我有一个基于 Linux 的进程控制器,它偶尔会锁定到无法 ping 的程度(即我可以 ping 它,然后如果不对网络设置进行任何修改,它就不再可 ping 通)。
我很好奇,什么进程/系统负责实际响应 ping?看来这个过程正在崩溃。
当我做:
$ traceroute 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
我得到的输出只显示星星,即使 ping google.com (8.8.8.8) 似乎工作。
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=73.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=69.6 ms
Run Code Online (Sandbox Code Playgroud)
$ traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 …Run Code Online (Sandbox Code Playgroud) 有没有办法在ping不停止执行的情况下告诉显示其通常的终止统计信息?
例如,我想快速查看:
--- 8.8.8.8 ping statistics ---
2410 packets transmitted, 2274 received, +27 errors, 5% packet loss, time 2412839ms
rtt min/avg/max/mdev = 26.103/48.917/639.493/52.093 ms, pipe 3
Run Code Online (Sandbox Code Playgroud)
无需停止程序,从而丢失累积的数据。
我在虚拟机上使用 Debian 9 映像。没有安装 ping 命令。当我运行时:
sudo apt-get install ping
Run Code Online (Sandbox Code Playgroud)
它问我:
Package ping is a virtual package provided by:
iputils-ping 3:20161105-1
inetutils-ping 2:1.9.4-2+b1
You should explicitly select one to install.
Run Code Online (Sandbox Code Playgroud)
为什么有两个 ping 实用程序?它们之间有什么区别?是否有一些指南可以选择一个版本而不是另一个版本?这个选择有什么影响?所有脚本和程序都与这两个版本兼容吗?
列出目录时/usr/bin,您会看到 ping 显示为黄色-红色:
该文件没有特殊功能:
$ file /usr/bin/ping
/usr/bin/ping: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 2.6.32, BuildID[sha1]=2508ea2a85b70c68967b3e6345541430f5317d5f,
stripped
$ stat /usr/bin/ping
File: '/usr/bin/ping'
Size: 62096 Blocks: 136 IO Block: 4096 regular file
Device: 802h/2050d Inode: 4457229 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:ping_exec_t:s0
Access: 2016-11-01 10:02:57.332925719 +0100
Modify: 2016-06-22 14:01:14.000000000 +0200
Change: 2016-07-10 23:41:59.623796126 +0200
Birth: -
Run Code Online (Sandbox Code Playgroud)
根据终端中不同颜色的含义是什么?,在那里我们可以找到一个脚本来列出颜色解释,“yellow-on-red”的意思是“ca”:
“ca”是什么意思?也许这意味着这个文件是从别处硬链接的(/usr/bin/ping并且 …
执行以下命令禁用 ping 回复后:
# sysctl net.ipv4.icmp_echo_ignore_all=1
# sysctl -p
Run Code Online (Sandbox Code Playgroud)
我从 ping localhost 与 127.0.0.1 获得不同的结果
# ping -c 3 localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.029 ms
64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.035 ms
64 bytes from localhost (::1): icmp_seq=3 ttl=64 time=0.101 ms
--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2042ms
rtt min/avg/max/mdev = 0.047/0.072/0.101/0.022 ms
Run Code Online (Sandbox Code Playgroud)
Ping 127.0.0.1 失败:
ping -c 3 127.0.0.1 …Run Code Online (Sandbox Code Playgroud) 我在某个 Debian 机器上有一个 NIC 卡。机器已关闭,但我需要知道 NIC 卡是否打开,以便稍后(从另一台 Debian 机器)发送 wake-on-lan 魔术包将其唤醒。我有卡的MAC地址。有什么办法可以通过MAC ping 以太网卡,看看它是否打开?
我尝试创建一个 ARP 条目:
arp -s 192.168.2.2 00-0c-0d-ef-02-03
ping 192.168.2.2
Run Code Online (Sandbox Code Playgroud)
那没有用,因为 NIC 卡没有这个 IP 地址。所以 NIC 卡会收到 ping 请求,但不会回复它。有没有办法解决?
我正在使用 etherwake 包发送网络唤醒消息。
我可以 ping google.com几秒钟,当我按Ctrl+时C,底部会显示一个简短的摘要:
$ ping google.com
PING google.com (74.125.131.113) 56(84) bytes of data.
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=2 ttl=56 time=46.7 ms
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=3 ttl=56 time=45.0 ms
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=4 ttl=56 time=54.5 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3009ms
rtt min/avg/max/mdev = 44.965/48.719/54.524/4.163 ms
Run Code Online (Sandbox Code Playgroud)
但是,当我使用 执行相同的重定向输出到日志文件时tee,不会显示摘要:
$ ping google.com | tee log
PING google.com (74.125.131.113) 56(84) …Run Code Online (Sandbox Code Playgroud) 我知道可以运行 Bashfor循环的方法和ping多台服务器的方法,是否有我可以使用的 Linux CLI 工具,它允许我执行此操作而不必求助于将 Bash 脚本编写到ping服务器列表一次一个?
像这样的东西:
$ ping host1 host2 host3
Run Code Online (Sandbox Code Playgroud)
注意:我正在寻找 CentOS/Fedora,但如果它适用于其他发行版,那也很好。
ping ×10
linux ×3
networking ×3
icmp ×2
arp ×1
colors ×1
command-line ×1
debian ×1
gnu ×1
ls ×1
mac-address ×1
signals ×1
sysctl ×1
tee ×1
traceroute ×1
wake-on-lan ×1