我在运行 arch linux 的树莓派上的路由表有一个奇怪的问题。
greg@pi etc]$ uname -a
Linux pi 3.6.11-2-ARCH+ #1 PREEMPT Mon Dec 31 23:00:25 UTC 2012 armv6l GNU/Linux
我有一个静态 IP 地址的 pi 设置。使用 netcfg 和 net-auto-wired 服务。
我还使用 nmbd 服务作为 samba 的一部分,以允许我通过其主机名 ping 设备奇怪的是,我分配给设备的静态 ip 不是我在通过主机名通信时收到回复的 ip。
查看路由表似乎暗示了问题:
[greg@pi ~]$ ip route show
default via 192.168.1.1 dev eth0
default via 192.168.1.1 dev eth0 metric 204
192.168.0.0/24 via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.20 metric 204
[greg@pi ~]$
我的界面设置:
[greg@pi ~]$ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ba27:ebff:fec9:1caf prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:c9:1c:af txqueuelen 1000 (Ethernet)
RX packets 1127 bytes 93818 (91.6 KiB)
RX errors 0 dropped 3 overruns 0 frame 0
TX packets 684 bytes 76203 (74.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifb0: flags=130<BROADCAST,NOARP> mtu 1500
ether e2:bb:30:e7:d0:8a txqueuelen 32 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifb1: flags=130<BROADCAST,NOARP> mtu 1500
ether 8a:e3:26:d4:38:b8 txqueuelen 32 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 20 bytes 1890 (1.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20 bytes 1890 (1.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
从网络上的另一台电脑上,我验证了两个 IP 都指向同一个接口(它们具有相同的物理地址)。
通信工作示例:
[2013-01-22 00:37.47] ~
[GKuhn.GKUHN-L01] ? ping pi
Pinging pi [192.168.1.20] with 32 bytes of data:
Reply from 192.168.1.20: bytes=32 time=36ms TTL=64
Reply from 192.168.1.20: bytes=32 time=7ms TTL=64
Reply from 192.168.1.20: bytes=32 time=3ms TTL=64
Reply from 192.168.1.20: bytes=32 time=2ms TTL=64
Ping statistics for 192.168.1.20:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 36ms, Average = 12ms
[2013-01-22 00:37.54] ~
[GKuhn.GKUHN-L01] ? ping 192.168.1.3
Pinging 192.168.1.3 with 32 bytes of data:
Reply from 192.168.1.3: bytes=32 time=2ms TTL=64
Reply from 192.168.1.3: bytes=32 time=2ms TTL=64
Reply from 192.168.1.3: bytes=32 time=2ms TTL=64
Reply from 192.168.1.3: bytes=32 time=26ms TTL=64
Ping statistics for 192.168.1.3:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 26ms, Average = 8ms
现在正如我所说,这个设置仍然有效。但我很困惑,想知道a)这实际上是如何工作的b)如何解决它
PS 查看我的日志(以下来自“everything.log”)我看到更多对 dhcpcd 的引用
Jan 1 01:00:09 pi dhcpcd[108]: eth0: rebinding lease of 192.168.1.20
Jan 1 01:00:10 pi dhcpcd[108]: eth0: acknowledged 192.168.1.20 from 192.168.1.1
Jan 1 01:00:10 pi dhcpcd[108]: eth0: checking for 192.168.1.20
Jan 1 01:00:14 pi dhcpcd[108]: eth0: leased 192.168.1.20 for 3600 seconds
但是我没有此过程的自定义配置。任何关于我应该在哪里调试的建议将不胜感激。
更多细节:覆盆子连接到 edimax wifi usb 加密狗,所以我在设置它时也考虑到了这个接口。我一直使用拱形无线设置页面作为指南。
我安装了 wireless_tools、dhcpcd(如果还没有的话,我不记得了)和 netcfg。我还安装了 net-auto-wired 和 net-auto-wireless,希望连接能够根据插入的连接正常工作。
下面是相关的配置文件:
[greg@pi multi-user.target.wants]$ pwd
/etc/systemd/system/multi-user.target.wants
[greg@pi multi-user.target.wants]$ ls
cronie.service openntpd.service sshdgenkeys.service
dhcpcd@eth0.service remote-fs.target syslog-ng.service
net-auto-wired.service smbd.service
nmbd.service sshd.service
[greg@pi multi-user.target.wants]$
dhcpcd@eth0.service:
[greg@pi multi-user.target.wants]$ cat dhcpcd\@eth0.service
[Unit]
Description=dhcpcd on %I
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=forking
PIDFile=/run/dhcpcd-%I.pid
ExecStart=/usr/sbin/dhcpcd -q -w %I
ExecStop=/usr/sbin/dhcpcd -x %I
[Install]
Alias=multi-user.target.wants/dhcpcd@eth0.service
网络自动连线服务:
[greg@pi multi-user.target.wants]$ cat net-auto-wired.service
[Unit]
Description=Provides automatic netcfg wired connection
[Service]
EnvironmentFile=/etc/conf.d/netcfg
ExecStart=/usr/bin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -fIns
ExecStop=/usr/bin/netcfg iface-down $WIRED_INTERFACE
[Install]
WantedBy=multi-user.target
[greg@pi multi-user.target.wants]$
[greg@pi network.d]$ pwd
/etc/network.d
[greg@pi network.d]$ ls
ethernet-static examples interfaces wlan0-xxx
[greg@pi network.d]$ cat wlan0-xxx
CONNECTION='wireless'
DESCRIPTION='Automatically generated profile by wifi-menu'
INTERFACE='wlan0'
SECURITY='wpa'
ESSID=xxx
IP='dhcp'
KEY=xxx
[greg@pi network.d]$ cat ethernet-static
CONNECTION='ethernet'
DESCRIPTION='A basic static ethernet connection using iproute'
INTERFACE='eth0'
IP='static'
ADDR='192.168.1.3'
ROUTES=('192.168.0.0/24 via 192.168.1.1')
GATEWAY='192.168.1.1'
DNS=('192.168.1.1')
## For IPv6 autoconfiguration
#IP6=stateless
## For IPv6 static address configuration
#IP6='static'
#ADDR6=('1234:5678:9abc:def::1/64' '1234:3456::123/96')
#ROUTES6=('abcd::1234')
#GATEWAY6='1234:0:123::abcd'
[greg@pi network.d]$
[greg@pi log]$ cat /etc/dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Inform the DHCP server of our hostname for DDNS.
hostname
# To share the DHCP lease across OSX and Windows a ClientID is needed.
# Enabling this may get a different lease than the kernel DHCP client.
# Some upstream DHCP servers may also require a ClientID, such as FRITZ!Box.
#clientid
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname
noipv4ll
#static dns lookup address
#nohook resolv.conf
[greg@pi log]$
如果有什么我遗漏的,请告诉我,我会发布的。
systemctl 报告的服务摘要:
[greg@pi ~]$ systemctl > services
[greg@pi ~]$ cat services
UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys...t_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point
sys-devi...y-ttyAMA0.device loaded active plugged /sys/devices/dev:f1/tty/ttyAMA0
sys-devi...-net-eth0.device loaded active plugged ec00
sys-devi...mmcblk0p1.device loaded active plugged /sys/devices/platform/mmc_host/mmc0/mmc0:e624/block/mmcblk0/mmcblk0p1
sys-devi...mmcblk0p2.device loaded active plugged /sys/devices/platform/mmc_host/mmc0/mmc0:e624/block/mmcblk0/mmcblk0p2
sys-devi...k-mmcblk0.device loaded active plugged /sys/devices/platform/mmc_host/mmc0/mmc0:e624/block/mmcblk0
sys-devi...-net-ifb0.device loaded active plugged /sys/devices/virtual/net/ifb0
sys-devi...-net-ifb1.device loaded active plugged /sys/devices/virtual/net/ifb1
sys-devi...ttyprintk.device loaded active plugged /sys/devices/virtual/tty/ttyprintk
sys-module-configfs.device loaded active plugged /sys/module/configfs
sys-subs...ices-eth0.device loaded active plugged ec00
sys-subs...ices-ifb0.device loaded active plugged /sys/subsystem/net/devices/ifb0
sys-subs...ices-ifb1.device loaded active plugged /sys/subsystem/net/devices/ifb1
-.mount loaded active mounted /
boot.mount loaded active mounted /boot
dev-mqueue.mount loaded active mounted POSIX Message Queue File System
proc-sys...infmt_misc.mount loaded active mounted Arbitrary Executable File Formats File System
sys-kernel-config.mount loaded active mounted Configuration File System
sys-kernel-debug.mount loaded active mounted Debug File System
tmp.mount loaded active mounted Temporary Directory
systemd-...ord-console.path loaded active waiting Dispatch Password Requests to Console Directory Watch
systemd-...ssword-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch
crond.service loaded failed failed LEGACY unit for "crond" rc script
cronie.service loaded active running Periodic Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
dhcpcd@eth0.service loaded active running dhcpcd on eth0
getty@tty1.service loaded active running Getty on tty1
hwclock.service loaded active exited LEGACY unit for "hwclock" rc script
net-auto-wired.service loaded active running Provides automatic netcfg wired connection
network.service loaded active exited LEGACY unit for "network" rc script
nmbd.service loaded active running Samba NetBIOS name server
openntpd.service loaded active running OpenNTP Daemon
rc-local.service loaded active exited /etc/rc.local Compatibility
smbd.service loaded active running Samba SMB/CIFS server
sshd.service loaded active running OpenSSH Daemon
syslog-ng.service loaded active running System Logger Daemon
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-...es-setup.service loaded active exited Recreate Volatile Files and Directories
systemd-...-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-...sessions.service loaded active exited Permit User Sessions
systemd-...le-setup.service loaded active exited Setup Virtual Console
dbus.socket loaded active running D-Bus System Message Bus Socket
syslog.socket loaded active running Syslog Socket
systemd-initctl.socket loaded active listening /dev/initctl Compatibility Named Pipe
systemd-journald.socket loaded active running Journal Socket
systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket
systemd-...d-control.socket loaded active listening udev Control Socket
systemd-udevd-kernel.socket loaded active running udev Kernel Socket
arch-daemons.target loaded active active Arch Daemons
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User
network.target loaded active active Network
remote-fs.target loaded active active Remote File Systems
sockets.target loaded active active Sockets
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
syslog.target loaded active active Syslog
systemd-...iles-clean.timer loaded active waiting Daily Cleanup of Temporary Directories
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
67 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[greg@pi ~]$
有趣的是,我尝试禁用 dhcpcd 服务,正如 Martin 在下面的评论中建议的那样,在确认它被禁用并重新启动后,我没有看到任何变化,ping 覆盆子显示来自 192.168.1.3 的响应不同但ip route show
产生了相同的结果。然后我尝试禁用net-auto-wired
服务。我重新启动了覆盆子,然后我认为我无法访问设备(通过 ssh 无头),因为我没有重新启用 dhcpcd 服务。有趣的是我没有,我的 IP 地址现在是 192.168.1.20。
dhcpcd 服务目前没有运行:
[greg@pi log]$ systemctl | grep -i dhcp
[greg@pi log]$
因此,这告诉我必须有其他一些我还不知道的 dhcp 机制。
查看 systemctl 并寻找 eth0:
[greg@pi log]$ systemctl -a --full | grep -i eth
sys-devices-platform-bcm2708_usb-usb1-1\x2d1-1\x2d1.1-1\x2d1.1:1.0-net-eth0.device loaded active plugged ec00
sys-subsystem-net-devices-eth0.device loaded active plugged ec00
LOAD = Reflects whether the unit definition was properly loaded.
[greg@pi log]$
我还不确定上述 2 项服务是什么,但它们可能与问题有关吗?