Useful code snippets and commands for Linux.

Alternatives to the ping and traceroute commands on a Linux system.

There are many alternatives to the ping and traceroute commands on a Linux system. The mtr command is one of them. This command will trace the route the network packets are taking to the target IP address.

bash 06:42:02 Mon Jul 22 [[email protected] $ mtr

This code will ping a server and use tcp, udp, icmp, stream, and syn packets to do so. This is useful to see if a server is up, but they block icmp packets, this script will work regardless of this and still allow you to see if the server is up or not. Good if you are behind a proxy at a college or something like that. There is also a tcpping command for Linux that can work when you are behind a restrictive firewall. There is some information about this here:


use warnings;
use strict;

use Net::Ping;

# code source:
# More:

#$| = 1;
print "Please type a host to check: -:\n";
my $host = <>; #Reading input from STDIN.

if (length($host) < 3) {
    print "You did not type a host!\n";

my @proto = ("tcp", "udp", "icmp", "stream", "syn");

foreach my $pro ( @proto ) {
    print "#-Protocol $pro \n";
    my $p = Net::Ping->new($pro);
    # Specify source interface of pings
    print "$host is ";
    print "NOT " unless $p->ping($host, 2);
    print "reachable.\n";


This is a good alternative for tracing the route taken from one host to another.

[email protected] ~ % sudo tcptraceroute
[sudo] password for homer: 
traceroute to (, 30 hops max, 60 byte packets
 1  localhost ( <syn,ack>  0.031 ms  0.004 ms  0.005 ms

This is how to ping the TCP port of a remote host. This is using the netcat tool.

[email protected] ~ % nc -zvv 80
Connection to 80 port [tcp/http] succeeded!

The hping3 command on Linux Mint 15 is very useful for sending TCP packets to a remote host to test the configuration of the server.

Type this command to install this utility: sudo apt-get install hping3.

And this is the output you get when you are pinging the Yahoo website with hping3.

bash 09:32:38 Mon Jul 22 [[email protected] $ sudo hping3 -S -p 80
HPING (eth1 S set, 40 headers + 0 data bytes
len=46 ip= ttl=112 id=51335 sport=80 flags=SA seq=0 win=8192 rtt=208.4 ms
len=46 ip= ttl=110 id=53804 sport=80 flags=SA seq=1 win=8192 rtt=197.2 ms
len=46 ip= ttl=110 id=56362 sport=80 flags=SA seq=2 win=8192 rtt=211.5 ms
len=46 ip= ttl=110 id=58939 sport=80 flags=SA seq=3 win=8192 rtt=211.0 ms
len=46 ip= ttl=110 id=61474 sport=80 flags=SA seq=4 win=8192 rtt=197.5 ms
len=46 ip= ttl=112 id=64019 sport=80 flags=SA seq=5 win=8192 rtt=195.7 ms
len=46 ip= ttl=112 id=998 sport=80 flags=SA seq=6 win=8192 rtt=194.8 ms
len=46 ip= ttl=112 id=3556 sport=80 flags=SA seq=7 win=8192 rtt=210.2 ms
len=46 ip= ttl=112 id=6243 sport=80 flags=SA seq=8 win=8192 rtt=210.6 ms
len=46 ip= ttl=110 id=8839 sport=80 flags=SA seq=9 win=8192 rtt=197.2 ms
--- hping statistic ---
10 packets transmitted, 10 packets received, 0% packet loss
round-trip min/avg/max = 194.8/203.4/211.5 ms
Ralph using a computer.
Ralph using a computer.

No comments have been made. Use this form to start the conversation :)

Leave a Reply