6 Basic 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.

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
# 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

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

;                    IN      A

;; ANSWER SECTION:             106     IN      A

;; AUTHORITY SECTION:             33959   IN      NS             33959   IN      NS             33959   IN      NS             33959   IN      NS

;; ADDITIONAL SECTION:         206816  IN      A         206816  IN      A         206816  IN      A         206816  IN      A

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




Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button