![为什么通过接口名称 ping 不通,而通过接口地址 ping 通?](https://linux22.com/image/89926/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%80%9A%E8%BF%87%E6%8E%A5%E5%8F%A3%E5%90%8D%E7%A7%B0%20ping%20%E4%B8%8D%E9%80%9A%EF%BC%8C%E8%80%8C%E9%80%9A%E8%BF%87%E6%8E%A5%E5%8F%A3%E5%9C%B0%E5%9D%80%20ping%20%E9%80%9A%EF%BC%9F.png)
我使用 USB 以太网适配器,该适配器eth1
在目标中被识别。然后我设置一个IP以eth1
使用该命令
ifconfig eth1 YY.YY.YY.YY
当我使用
ping -I eth1 XX.XX.XX.XX
输出 :
mx6q:~# ping -I eth1 192.168.2.35
PING 192.168.2.35 (192.168.2.35): 56 data bytes
^C
--- 192.168.2.35 ping statistics --- 3 packets transmitted, 0 packets received, 100% packet loss
它不起作用,而当我使用时
ping -I YY.YY.YY.YY XX.XX.XX.XX
输出 :
mx6q:~# ping -I 192.168.2.99 192.168.2.35
PING 192.168.2.35 (192.168.2.35) from 192.168.2.99: 56 data bytes
64 bytes from 192.168.2.35: seq=0 ttl=64 time=0.765 ms
64 bytes from 192.168.2.35: seq=1 ttl=64 time=0.437 ms
^C
--- 192.168.2.35 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
它是在职的。
如何通过接口名称 ping 通?
IF配置
eth1 Link encap:Ethernet HWaddr 00:07:40:53:dd:1b
inet addr:192.168.2.99 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::207:40ff:fe53:dd1b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4754 (4.6 KiB) TX bytes:1376 (1.3 KiB)
答案1
确保您的计算机上存在接口名称。通过执行ifconfig
或ip addr show
或ip link show
命令进行检查。
您还可以使用ip route show
和traceroute -i
命令进行一些故障排除。
它的工作原理如下图所示:
[iahmad@ijaz-cms ~]$ ping -I enp0s25 www.google.com
PING www.google.com (172.217.18.100) from 137.138.52.207 enp0s25: 56(84) bytes of data.
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=1 ttl=54 time=4.88 ms
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=2 ttl=54 time=4.97 ms
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=3 ttl=54 time=5.01 ms
^C
--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 4.885/4.958/5.019/0.055 ms
[iahmad@ijaz-cms ~]$ ping -I 137.138.52.207 www.google.com
PING www.google.com (172.217.18.100) from 137.138.52.207 : 56(84) bytes of data.
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=1 ttl=54 time=4.98 ms
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=2 ttl=54 time=4.93 ms
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=3 ttl=54 time=4.96 ms
64 bytes from zrh04s05-in-f4.1e100.net (172.217.18.100): icmp_seq=4 ttl=54 time=4.98 ms
^C
--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 4.939/4.966/4.983/0.017 ms