树莓派只启用一个无线网卡为何有两个局域网 IP?

2017-01-22 22:33:03 +08:00
 lenovo
pi@raspberrypi:~ $ sudo ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:91:46:91
          inet6 addr: fe80::ca34:11e2:7331:b87d/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1086 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1086 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:83408 (81.4 KiB)  TX bytes:83408 (81.4 KiB)

wlan0     Link encap:Ethernet  HWaddr b4:ee:b4:87:3a:d1
          inet addr:192.168.0.121  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::b6ee:b4ff:fe87:3ad1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:241947 errors:0 dropped:35834 overruns:0 frame:0
          TX packets:225100 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:185653893 (177.0 MiB)  TX bytes:195708830 (186.6 MiB)

pi@raspberrypi:~ $ hostname -I
192.168.0.121 192.168.0.111

网络配置如下:

pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.0.121
        netmask 255.255.255.0
        gateway 192.168.0.1
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

这个 192.168.0.111 是从哪里来的?

4285 次点击
所在节点    Linux
8 条回复
mazyi
2017-01-22 23:39:28 +08:00
去看看 hostname -i 的指令说明。
mingl0280
2017-01-23 10:02:03 +08:00
你 manual 又没配置内容,自动 dhcp 咯……
正确做法是 down 掉 eth0
holyzhou
2017-01-23 10:31:13 +08:00
再用 ip a 看眼当前网络状况,接着用 root 用户 journalctl |grep "IP" 看看 ip 地址是什么时候怎么分配的。
lenovo
2017-01-23 11:21:09 +08:00
r#3 @holyzhou @mingl0280
看起来还是 wlan0 分配的 IP ,不知怎么停用这一个?

pi@raspberrypi:~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether b8:27:eb:91:46:91 brd ff:ff:ff:ff:ff:ff
inet6 fe80::ca34:11e2:7331:b87d/64 scope link tentative
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b4:ee:b4:87:3a:d1 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.121/24 brd 192.168.0.255 scope global wlan0
valid_lft forever preferred_lft forever
inet 192.168.0.111/24 brd 192.168.0.255 scope global secondary wlan0
valid_lft forever preferred_lft forever
inet6 fe80::b6ee:b4ff:fe87:3ad1/64 scope link
valid_lft forever preferred_lft forever
lenovo
2017-01-23 11:23:03 +08:00
r#3 @holyzhou
pi@raspberrypi:~ $ sudo journalctl |grep "IP"
Jan 22 13:33:21 raspberrypi kernel: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
Jan 22 13:33:21 raspberrypi kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000)
Jan 22 13:33:21 raspberrypi kernel: SMP: Total of 4 processors activated (153.60 BogoMIPS).
Jan 22 13:33:26 raspberrypi kernel: IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Jan 22 13:33:27 raspberrypi kernel: IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Jan 22 13:33:27 raspberrypi kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: Joining mDNS multicast group on interface wlan0.IPv6 with address fe80::b6ee:b4ff:fe87:3ad1.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: New relevant interface wlan0.IPv6 for mDNS.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.0.121.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: New relevant interface wlan0.IPv4 for mDNS.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::ca34:11e2:7331:b87d.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: New relevant interface eth0.IPv6 for mDNS.
Jan 22 13:33:28 raspberrypi avahi-daemon[493]: Registering new address record for 192.168.0.121 on wlan0.IPv4.
Jan 22 13:33:29 raspberrypi dhcpcd[514]: wlan0: soliciting an IPv6 router
Jan 22 13:33:35 raspberrypi avahi-daemon[493]: Registering new address record for 192.168.0.111 on wlan0.IPv4.
Jan 22 13:33:41 raspberrypi dhcpcd[514]: wlan0: no IPv6 Routers available
lenovo
2017-01-23 11:41:50 +08:00
解决了,静态 IP 要在 /etc/dhcpcd.conf 中配置,不要在 /etc/network/interfaces 中配置
holyzhou
2017-01-23 11:57:00 +08:00
虽然解决了 ,但是我印象中,静态地址就是在 interfaces 里面定义的,而且 dhcpcd 也应该是配置 dhcp 相关的内容吧,你再想想你有没有在图形界面中配置过 ip 地址之类的信息,这也可能导致你 wlan 获得两个 ip 地址。
lenovo
2017-01-23 12:12:48 +08:00
r#7 @holyzhou 我没显示器,都是 ssh 进去配置的
/etc/network/interfaces 最上面有几行提示,之前没注意

pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/336331

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX