Ping

From Linuxintro

Ping allows you to see if a computer is reachable via the network and to measure the network latency. You stop it with CTRL_C.

Example:

# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.19 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.417 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.382 ms

In this example we have a latency of below 1 milisecond and 192.168.0.1 is up

Broadcast ping

A broadcast ping can be described as a request "Anybody who hears this, please respond back". The problem is that you can configure computers to ignore these requests.

To tell your computer to answer on broadcast pings, open a console and issue:

echo "0" >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

To verify if your computer is set to answer on broadcast pings, issue:

sysctl net.ipv4.icmp_echo_ignore_broadcasts

In this case, the response

net.ipv4.icmp_echo_ignore_broadcasts = 0

means it is set to answer broadcast pings.

To perform a broadcast ping,

  • Find out the broadcast address of the network where you want to broadcast
ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:1C:F0:BB:06:C8
          inet addr:192.168.0.5  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:f0ff:febb:6c8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:315742 errors:0 dropped:0 overruns:0 frame:0
          TX packets:297176 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:195071533 (186.0 Mb)  TX bytes:41401952 (39.4 Mb)
          Interrupt:21 Base address:0x4000
  • ping the broadcast IP
# ping -b 192.168.0.255
WARNING: pinging broadcast address
PING 192.168.0.255 (192.168.0.255) 56(84) bytes of data.
64 bytes from 192.168.0.5: icmp_seq=1 ttl=64 time=0.039 ms 

Broadcast ping does not work?

try nmap like this:

nmap 192.168.0.0/24

It will show you which IP addresses are active in the 192.168.0.* network.

MTU

The maximum transfer unit determines how big network packets can be. It can be set on the computer and on the network switch. The biggest packets that will be able to travers the internet are 1500 bytes in size. Jumbo-Frames are typically 9000 bytes of size. A good explanation can be found at http://www.dslreports.com/faq/695. Note that

ping -s 65000 192.168.0.1

is not sufficient to say if packets of 65000 bytes are possible. Better use

ping -M do -s 65000 192.168.0.1

Ping does not work

If you change a host's IP in /etc/hosts and this change is not reflected instantly by ping, restart the name service cache daemon:

/etc/init.d/nscd restart

and check /etc/nsswitch.conf

See also