Sunday, January 3, 2016

HowTo: Speedup ping and traceroute Command Responses under Linux / Unix

http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-speedup-ping-traceroute-command-probs

The following question was asked in the Unix networking exam:

     How do you speed up ping and traceroute command responses under Unix or Linux operating systems?
How can I speed up my ping or traceroute commands on a Linux?

The ping command line utility act as a computer network tool. It used to test whether a particular host is reachable across an IP network. The traceroute command also act as a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network.

Speedup ping command

The syntax is:
 
ping -n -W VALUE -i VALUE host
 
Where,
  1. -n : Disable DNS lookup to speed up queries.
  2. -W NUMBER : Time to wait for a response, in seconds. The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.
  3. -i SECONDS : Wait interval seconds between sending each packet. The default is to wait for one second between each packet normally, or not to wait in flood mode. Only super-user may set interval to values less 0.2 seconds.
The default command will produce output as follows:
$ ping -c 5 www.cyberciti.biz
Sample outputs:
PING www.cyberciti.biz (75.126.153.206) 56(84) bytes of data.
64 bytes from www.cyberciti.biz (75.126.153.206): icmp_req=1 ttl=55 time=293 ms
64 bytes from www.cyberciti.biz (75.126.153.206): icmp_req=2 ttl=55 time=295 ms
64 bytes from www.cyberciti.biz (75.126.153.206): icmp_req=3 ttl=55 time=293 ms
64 bytes from www.cyberciti.biz (75.126.153.206): icmp_req=4 ttl=55 time=294 ms
64 bytes from www.cyberciti.biz (75.126.153.206): icmp_req=5 ttl=55 time=294 ms
--- www.cyberciti.biz ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 293.571/294.170/295.158/0.869 ms
Now optimize the ping command:
$ ping -c 5 -n -i 0.2 -W1 www.cyberciti.biz
Sample outputs:
PING www.cyberciti.biz (75.126.153.206) 56(84) bytes of data.
64 bytes from 75.126.153.206: icmp_req=1 ttl=55 time=293 ms
64 bytes from 75.126.153.206: icmp_req=2 ttl=55 time=294 ms
64 bytes from 75.126.153.206: icmp_req=3 ttl=55 time=293 ms
64 bytes from 75.126.153.206: icmp_req=4 ttl=55 time=293 ms
64 bytes from 75.126.153.206: icmp_req=5 ttl=55 time=294 ms
--- www.cyberciti.biz ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 810ms
rtt min/avg/max/mdev = 293.279/293.955/294.522/0.799 ms, pipe 2
Here is another output showing the difference between two command line options:
Fig.01: Unix and Linux speedup ping command
Fig.01: Unix and Linux speedup ping command

Speedup traceroute command

The syntax is:
 
traceroute -n -w SECONDS -q NUMBER host
 
Where,
  1. -n : Disable DNS lookup to speed up queries.
  2. -w seconds : Set the time (in seconds) to wait for a response to a probe (default 5.0 sec).
  3. -q NUMBER : Sets the number of probe packets per hop. The default is 3.
The following example will wailt 3 seconds (instead of 5), only send out 1 query to each hop (ineader of 3):
$ traceroute -n -w 3 -q 1 www.cyberciti.biz
The -N option specifies the number of probe packets sent out simultaneously. Sending several probes concurrently can speed up traceroute considerably. The default value is 16:
$ traceroute -n -w 3 -q 1 -N 32 www.cyberciti.biz
Please Note that some routers and hosts can use ICMP rate throttling. In such a situation specifying too large number can lead to loss of some responses. You can also limit the maximum number of hops to 16 before giving up (instead of default 30) using the -m option:
$ traceroute -n -w 3 -q 1 -N 32 -m 16 www.cyberciti.biz
Sample outputs:
Fig.02: Unix and Linux speedup traceroute command
Fig.02: Unix and Linux speedup traceroute command
References:

No comments:

Post a Comment