我正在尝试使用ping带有命令的指定接口
ping -I re3 192.168.1.1
Run Code Online (Sandbox Code Playgroud)
我知道re3存在于ifconfig
re3: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=8209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE>
ether e8:de:27:01:7f:e7
inet6 fe80::eade:27ff:fe01:7fe7%re3 prefixlen 64 scopeid 0x4
inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法 ping 它的网关:
$/root: ping -I re3 192.168.1.1
ping: invalid multicast interface: `re3'
Run Code Online (Sandbox Code Playgroud)
那是什么意思?
更新
$arp 192.168.1.1
? (192.168.1.1) at (incomplete) on re3 expired [ethernet]
Run Code Online (Sandbox Code Playgroud)
对freebsd系统没有太多经验,据我所知,ping尝试:
ping -S 192.168.1.2 192.168.1.1
Run Code Online (Sandbox Code Playgroud)
至于arp
在 FreeBSD 和 macos 上,该-I标志的行为与人们对 Linux 的期望不同。如果你仔细检查手册页,你会看到:
Run Code Online (Sandbox Code Playgroud)-I iface Source multicast packets with the given interface **address**.
[强调我的]
So the -I flag actually expects an address, not an interface. You can confirm with something like:
$ ping -I 192.168.1.2 192.168.1.1
Run Code Online (Sandbox Code Playgroud)
But unless your target IP address is a multicast address this will still fail.
To get the behaviour we all know and expect from traceroute and Linux, use the -S flag instead and specify the IP address of the interface you want to use:
$ ping -S 192.168.1.2 192.168.1.1
PING 192.168.1.1 (192.168.1.1) from 192.168.1.20: 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=64 time=5.956 ms
Run Code Online (Sandbox Code Playgroud)