通常,ping 命令已经安装在大多数 Linux 系统上。
但在一些极少数情况下,例如当您安装了 Ubuntu 最小安装或在 Docker 容器中运行 Ubuntu 时,缺少 ping 命令。 如果您尝试使用它,您将看到 ping not found 错误。
[email protected]:/# ping itsfoss.com
bash: ping: command not found
这还不是最糟糕的事情。 您尝试安装 ping 然后它抱怨它是 找不到包裹 平。
[email protected]:/# apt install ping
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ping
现在它变得混乱了。 你不能在 Ubuntu 中使用 ping 吗? Ubuntu中没有ping命令吗? 这不可能是对的,不是吗?
在 Ubuntu 上安装 ping
这里的问题是 ping 命令本身不是一个包。 它是一部分 iputils 包. 这是当您尝试安装名为 ping 的软件包时,找不到它。
作为 iputils 一部分的实际 ping 包称为 iputils-ping。 这是您必须为 ping 安装的软件包。
首先,通过以 root 身份运行此命令来更新本地包缓存(使用 sudo 如果你不是root):
apt update
现在,使用以下命令安装 iputils-ping 软件包:
apt install iputils-ping
现在,您可以使用 ping 命令。
[email protected]:/# ping itsfoss.com
PING itsfoss.com (104.26.10.68) 56(84) bytes of data.
64 bytes from 104.26.10.68 (104.26.10.68): icmp_seq=1 ttl=56 time=25.1 ms
64 bytes from 104.26.10.68 (104.26.10.68): icmp_seq=2 ttl=56 time=49.6 ms
64 bytes from 104.26.10.68 (104.26.10.68): icmp_seq=3 ttl=56 time=34.8 ms
64 bytes from 104.26.10.68 (104.26.10.68): icmp_seq=4 ttl=56 time=38.9 ms
^C
--- itsfoss.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 25.125/37.095/49.590/8.773 ms

如果您在 Docker 容器中使用它,您就会知道您在容器中所做的更改是临时的。 您应该使用 Dockerfile 对映像和后续容器进行永久更改。
我希望你发现这个快速提示有助于在 Ubuntu 上安装 ping 命令。 如果您仍有问题或建议,请在评论部分告诉我。