6 essential network commands in Linux

This Linux tutorial covers some basic network commands that can be useful in troubleshooting network problems with other servers both on the network and over the Internet, get more information about other servers. 1. Command ping sends echo ICMP requests to the server, which you specify on the command line, and is used to quickly check the network connection to another server. If packets are accepted, the destination device sends the 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 that ping is not a reliable way to check network connectivity, as many servers block ICMP echo packets by default, so if a server does not respond to pings, this does not mean that it is or is not available. 2. Team netstat (Network Statistics) displays network connections to and from the server, routing tables, network interface statistics, masked connections, etc.

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 of all UDP ports;
  • -n Display numeric addresses instead of trying to determine a symbolic host;
  • -l Show only sockets;
  • -p Show the PID and name of the program that owns each socket.

3. Traceroute is a network troubleshooting command that will show the route of the packet to the destination server (number of flights) and the 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. Team hostname shows the hostname of the server, and it is also used to set (or change) the name of the proxy server:

# hostname

To set a new hostname for the server to use:

#sudo hostname new-hostname.ru
# hostname

5. Team route 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                                                                                
default         gw.msk.ispsyste         UG    100    0        0 eth0                                                                           U     100    0        0 eth0

To add a new route in use:

# route add -net netmask dev eth0

To remove a route usage:

# route del -net netmask dev eth0

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

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

6. dig (Groper Domain Information) is a useful tool for network troubleshooting, primarily used to query DNS information related like CNAME, NS, MX Records, etc.

# dig google.com

; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.2 <<>> google.com                                                                                                     
;; global options: +cmd                                                                                                                                      
;; Got answer:                                                                                                                                               
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5123                                                                                                     
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1                                                                                         
;; OPT PSEUDOSECTION:                                                                                                                                        
; EDNS: version: 0, flags:; udp: 4096                                                                                                                        
;; QUESTION SECTION:                                                                                                                                         
;google.com.                    IN      A                                                                                                                    
;; ANSWER SECTION:                                                                                                                                           
google.com.             94      IN      A                                                                                              
google.com.             94      IN      A                                                                                              
google.com.             94      IN      A                                                                                              
google.com.             94      IN      A                                                                                              
google.com.             94      IN      A                                                                                              
google.com.             94      IN      A                                                                                              
;; Query time: 0 msec                                                                                                                                        
;; SERVER:                                                                                                                   
;; WHEN: Mon Mar 06 21:22:06 MSK 2017                                                                                                                        
;; MSG SIZE  rcvd: 135