Install ping on linux

Docker — Ubuntu — bash: ping: command not found

Do I need to install that? Seems a pretty basic command to be missing. I tried whereis ping which doesn’t report anything.

It’s entirely appropriate for a Docker image to be minimal. In most cases, a container will never do anything but run a single application — why install anything that application doesn’t need?

8 Answers 8

Docker images are pretty minimal, but you can install ping in your official ubuntu docker image via:

apt-get update -y apt-get install -y iputils-ping 

Chances are you don’t need ping on your image, and just want to use it for testing purposes. Above example will help you out.

But if you need ping to exist on your image, you can create a Dockerfile or commit the container you ran the above commands into a new image.

docker commit -m "Installed iputils-ping" --author "Your Name " ContainerNameOrId yourrepository/imagename:tag 
FROM ubuntu RUN apt-get update && apt-get install -y iputils-ping CMD bash 

Please note there are best practices on creating docker images, like clearing apt cache files afterwards and etc.

apt-get fails with Temporary failure resolving ‘security.ubuntu.com’ obviously because networking is not present.

I’d got into the habit of using apt install and ended up with «package not found», but as the answer says, apt-get works just fine.

If you need to install on a container running you need to execute with root privileges, so execute docker exec -u 0 -it /bin/bash . Where -u 0 is user root.

This is the Docker Hub page for Ubuntu and this is how it is created. It only has (somewhat) bare minimum packages installed, thus if you need anything extra you need to install it yourself.

apt-get update && apt-get install -y iputils-ping 

However usually you’d create a «Dockerfile» and build it:

mkdir ubuntu_with_ping cat >ubuntu_with_ping/Dockerfile  

Please use Google to find tutorials and browse existing Dockerfiles to see how they usually do things 🙂 For example image size should be minimized by running apt-get clean && rm -rf /var/lib/apt/lists/* after apt-get install commands.

echo -e actually defies the POSIX sh standard, which doesn't allow it to do anything but print -e on its output. (Even with some versions of bash, that's the default behavior). Use printf instead: printf '%s\n' "FROM ubuntu" "RUN apt-get update && apt-get install -y iputils-ping" "CMD bash" , and see the APPLICATION USAGE section of the above-linked standards document.

Even bash won't support echo -e the way you expect it to (but instead will have a standards-compliant behavior) when in POSIX mode compiled with --enable-xpg-echo-default , or with appropriate environment variables or other runtime configuration.

(POSIX allows echo to behave in an implementation-defined way when given -n as a first argument, or when any backslash literals are present -- but even then, it's implementation-defined, not standard-guaranteed, so behavior is dependent on the individual shell in use).

Thanks for comments and improvements, the "copy-and-paste" friendly example was more of an after thought.

Alternatively you can use a Docker image which already has ping installed, e.g. busybox:

docker run --rm busybox ping SERVER_NAME -c 2 

It's a solution, but creating an image just to execute ping seems overkill for me. I'd rather apt-get iputils-ping on the image which needs it.

Generally people pull the official image of Ubuntu/CentOS but they don't realize that these images are minimal and doesn't have any thing on the top of that.

For Ubuntu, this image is built from official rootfs tarballs provided by Canonical. Given that it is a minimal install of Ubuntu, this image only includes the C, C.UTF-8, and POSIX locales by default.

One can install net-tools (includes ifconfig, netstat), ip-utils(includes ping) andy other likes curl etc on container and can create image from container or can write Dockerfile that will install these tool while creating image.

Below is Dockerfile example, while creating image from this it will include these tools:

FROM vkitpro/ubuntu16.04 RUN apt-get update -y \ && apt-get upgrade -y \ && apt-get install iputils-ping -y \ && apt-get install net-tools -y \ CMD bash 

or launch container from base image and install these utilities on container and then commit to image. docker commit -m "any descriptive message" container_id image_name:lattest

That image will have all thing installed.

Источник

How to Install and Use Ping Command in Linux

PING is undoubtedly a millennial word. It’s rooted in quotidian life and henceforth has become a concept to be unveiled. Many of us might be known of the fact that the word ‘ping‘ is not actually a word but an acronym. PING stands for Packet Internet Groper. The meaning
says it all.

Pinging is a notion to observe the connectivity between two systems, to check whether the remote system is online. Technically, the word ping lies in the domain of network communication. It deals with the notion of transferring and accepting the packets from source to destination system.

It is used to check the connectivity of systems by sending packets. Let’s say system A wishes to connect to system B. In this case, the A sends packets to B i.e A pings to B. System A can ping to B by either using its IP address or its hostname.

Pinging in Linux

Pinging in Linux is apparently an easy job to do until you have the command which performs this action for you. In Linux distribution, the pinging is done using the command “ping” followed by the IP address or hostname.

$ ping [option] [IP address / hostname]

To check the IP address of your Linux system, use the following command.

Check Linux IP Address

Next, try to ping the server using the IP address as shown.

Ping Linux System

What Does a Packet Contain?

So far we know pinging purports to send packets. But what are these packets? These packets comprise the information along with a header. The header is the guiding light for this packet.

A packet header contains the source IP address and the destination IP address. It resembles the way you send postcards containing your address and your friend’s address. Once the packet reaches its destined location it responses back and that’s what we call “The systems are pinging“.

The ping command actually sends an echo request to the remote system. It uses ICMP (Internet Control Message Protocol) for the same. Whenever the two systems ping it is followed by some detailed specifications ranging from who is sending packets and at what time it reaches the destination.

Ping Domain Name

The explanation of the above ping command.

  • icmp_seq – It is the number given to every request sent by the source.
  • ttl – Time To Live is the number of network nodes taken by the packet.
  • time – It represents the milliseconds taken by the packet to reach and come back again to the source.

How to Install Ping Command in Linux

By default, most Linux systems already have the ping command. Here, we consider the scenario that it does not, so we encounter this error on trying to ping with google.

$ ping www.google.com bash: /usr/sbin/ping: No such file or directory 

To install the ping command in Linux, use your system’s package manager as shown.

$ sudo apt install iputils-ping [On Debian, Ubuntu and Mint] $ sudo yum install iputils [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a net-misc/iputils [On Gentoo Linux] $ sudo pacman -S iputils [On Arch Linux] $ sudo zypper install iputils [On OpenSUSE]

Once the software has been installed you can successfully ping to any server. The process can be stopped using Ctrl+C .

Ping Google Domain

In extension, the ping command offers some specific options that can also be tried and tested. To see additional command-line options:

Ping Command Help

This article was an overview of how to install and explore the ‘ping‘ command in the Linux servers. It also gave an insight into the real essence of pinging. In addition, it appends to the knowledge bucket of Linux.

Ping command is accompanied by varied options which can further be used to control, count, stop the packets transfer. Examine these commands and keep pinging. Do let us know how you find this article. Any views, suggestions are welcomed.

Источник

Ping command in Ubuntu 22.04

In Linux-based systems such as Ubuntu 22.04, ping is a basic utility that is used to evaluate if a specific network is available or not and whether a host can be accessed or not. Moreover, you can also determine whether a server is up and running. You can also troubleshoot connectivity issues by testing your internet connection.

Based on your Ubuntu 22.04 server/desktop installation, the ping command might not be present in your system by default. Therefore, if you wish to install the ping command on your system then follow the provided guide below.

How to install Ping command in Ubuntu 22.04

The procedure of installing the ping command on Ubuntu 22.04 is very easy and the below-given step-by-step procedure demonstrates how to do that.

Step 1: Update System

It is considered to be a good practice to update and upgrade your system when you are about to install something on it. For this purpose, firstly, press “CTRL+ALT+T” to open up Ubuntu 22.04 terminal and then execute the following command:

As you can see, our Ubuntu 22.04 system has been updated successfully.

Step 2: Install ping in Ubuntu 22.04

The “iputils-ping” package contains the ping command, therefore, you need to have this package installed on your system:

Step 3: Verify ping installation

In the next step, we will verify the successful installation of the ping command:

Now to see if the ping command is working properly we will the remote host “linuxhint.com”:

Above-given output signifies that we have successfully pinged the mentioned remote host.

Conclusion

To install ping command on your system, first of all, update system repositories using this command “$ sudo apt update && sudo apt upgrade”, then install the “iputils-ping” package that comprises the ping command with the “$ sudo apt install iputils-ping” command. Lastly, verify this installation by running this command “$ which ping”. This write-up demonstrated the procedure to install and use ping command in Ubuntu 22.04.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.

Источник

Ping Command Not Found? Install Ping on Ubuntu

If you are running Ubuntu in a Docker container, ping command will be missing. You can install ping on Ubuntu with this simple trick.

Usually, the ping command is already installed on most Linux systems.

But in some rare cases like when you have Ubuntu minimal install or you are running Ubuntu in a Docker container, the ping command is missing. If you try to use it, you will see the ping not found error.

[email protected]:/# ping itsfoss.com bash: ping: command not found

That's not the worst thing. You try to install ping and then it complains that it is unable to locate package ping.

[email protected]:/# apt install ping Reading package lists. Done Building dependency tree Reading state information. Done E: Unable to locate package ping

Ping command not found in Ubuntu when running in Docker

Now it gets confusing. Can you not use ping in Ubuntu? Is there no ping command in Ubuntu? That cannot be right, isn't it?

Installing ping on Ubuntu

The problem here is that ping command is not a package itself. It is part of iputils package. This is when you try to install a package named ping, it cannot be found.

The actual ping package as part of iputils is called iputils-ping. This is the package you have to install for ping.

First, update the local package cache by running this command as root (use sudo if you are not root):

Now, install the iputils-ping package with this command:

Installing ping command on Ubuntu

[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 

ping command running in Ubuntu

If you are using this in a Docker container, you know that changes you made in the container are temporary. You should use Dockerfile to make permanent changes to the image and the subsequent containers.

I hope you find this quick tip helpful in installing ping command on Ubuntu. If you still have questions or suggestions, please let me know in the comment section.

Источник

Читайте также:  Find and print linux
Оцените статью
Adblock
detector