6 Basic Network Commands in Linux

network commands in linux

This Linux tutorial covers some basic network commands which can be useful when troubleshooting networking problems with other servers both within the network and across the Internet, obtaining more information about other servers.

1. The ping command sends ICMP echo requests to the server you specify on the command line, and is used to quickly test network connectivity to another server. If the packets are received, the destination device sends packets back:

# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.141 ms
64 bytes from icmp_seq=2 ttl=64 time=0.136 ms
64 bytes from icmp_seq=3 ttl=64 time=0.109 ms

Please note, ping is not a reliable way to test network connectivity because many servers block ICMP echo packets by default, so if some server is not responding to pings, it doesn’t always mean it is down or unavailable.
2.  Netstat (Network Statistic) command display network connections to and from the server, routing tables, networking interface statistics, masquerade connections etc. The netstat command has been replaced with ss. The command-line parameters are almost identical.

netstat -tunlp | less

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0        *                   LISTEN      15501/sshd
tcp        0      0        *                   LISTEN      29709/httpd

-t   List all tcp ports;
-u   List all udp ports;
-n   Show numerical addresses instead of trying to determine symbolic host;
-l   Show only listening sockets;
-p   Show the PID and name of the program to which each socket belongs.
3. Traceroute is a network troubleshooting command which will show the route of a packet to the destination server (the number of hops) and response time to get to the destination server.

# traceroute
traceroute to (, 30 hops max, 60 byte packets
1 (  0.471 ms  0.401 ms  0.402 ms

4. The hostname command shows the host name of the server, and it is also used to set (or change) the server hostname:

# hostname

To set a new hostname for the server use:

#sudo hostname new-hostname.com
# hostname

5. The route command is a network utility used to display or modify the routing table.

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface    *         U     0      0        0 eth0
link-local     *           U     1002   0        0 eth0
default          UG    0      0        0 eth0

To add a new route use:

# route add -net netmask dev eth0

To delete a route use:

# route del -net netmask dev eth0

To delete the default gateway and add a new gateway as the default use:

# route delete default gw eth0
# route add default gw eth0

6. Dig (domain information groper) is a useful tool for network troubleshooting, primarily used to query DNS related information like A Record, CNAME, NS, MX Records etc.

# dig google.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.4 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25916
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 4

;google.com.                    IN      A

google.com.             106     IN      A

google.com.             33959   IN      NS      ns4.google.com.
google.com.             33959   IN      NS      ns3.google.com.
google.com.             33959   IN      NS      ns2.google.com.
google.com.             33959   IN      NS      ns1.google.com.

ns3.google.com.         206816  IN      A
ns4.google.com.         206816  IN      A
ns2.google.com.         206816  IN      A
ns1.google.com.         206816  IN      A

;; Query time: 0 msec
;; WHEN: Sun Mar  5 18:37:21 2017
;; MSG SIZE  rcvd: 180

Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to troubleshoot any networking problems for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Install Odoo on a Debian 8 VPS with Nginx as a reverse proxy
How to install ActiveMQ on CentOS
How to Install Ruby on Rails with Nginx and Passenger
  • BasketCase


    Author Reply

    The netstat and route command were both obsoleted by the iproute2 package more than a decade ago. Use the ss and ip route commands respectively instead.

  • Fred


    Author Reply

    You might want to mention the ip and ss commands for newer distributions that don’t come with nestat/ifconfig/etc.. installed by default.

    • admin


      Author Reply

      Yes, iproute2 replaced the net-tools package. Socket statistics, or ss is the equivalent for netstat. Also, the options used with the ss command are very similar to netstat.

  • Rutvik Mehra

    Excellent article about basic network commands in linux…thank you for share this awesome post….Will you please keep it updated every time.I’ll make a note of this article for sure. Keep it up!