Ping

From LQWiki
Jump to: navigation, search

Ping is a network troubleshooting tool that sends ICMP echo requests that is used for testing connectivity between computers. It, of course, is named after sonar pings that a submarine uses to detect other ships. It is sometimes said to stand for Packet INternet Groper, but this is a backronym.

One difference between the MS-DOS/Windows version of this tool and the Linux version is that, by default, the DOS version quits after 4 pings, the Linux version keeps pinging indefinitely. (Stop it with Ctrl C, or run it with the -c 4 option to stop after 4 pings.)

Examples

ping www.google.com
  • Pings Google.
  • Note that ping can accept IP addresses or domain names.

Broadcast ping

Here is how you do a broadcast ping with SUSE, it should work same or similar with every distribution. Log in as root user to perform the following tasks.

  • Stop the firewall
rcSuSEfirewall2 stop
  • Allow for broadcast pings
echo "0" >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
  • Verify broadcast pings are allowed
sysctl net.ipv4.icmp_echo_ignore_broadcasts
net.ipv4.icmp_echo_ignore_broadcasts = 0
  • 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
# 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

If this does not work you can use the following command to search for IP addresses that respond:

for i in $(seq 1 1 5); do (ping -c 1 -w 1 192.168.0.$i >/dev/null && echo $i); done;

TroubleShooting

Problem: The DNS entry has changed (maybe it is a dynamic one from dyndns), but ping still tries to reach the old ip-address.

Reason: The IP address is cached.

Solution: Restart the name service cache daemon:

/etc/init.d/nscd restart

See also