¿Ping 命令未找到? 在 Ubuntu 上安裝 Ping

大多數 Linux 系統上通常已經安裝了 ping 命令。

但在極少數情況下,例如當您安裝了 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 身份運行此命令來更新本地包緩存(如果您不是 root 用戶,請使用 sudo):

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
Comando ping ejecutándose en Ubuntu

如果您在 Docker 容器中使用它,您就會知道您對容器所做的更改是臨時的。 您必須使用 Dockerfile 對映像和後續容器進行永久更改。

我希望這個在 Ubuntu 上安裝 ping 命令的快速提示對您有所幫助。 如果還有什麼問題或者建議,歡迎在評論區告訴我。

相關文章