Network Configuration and Troubleshooting Commands in Linux

Spread the love

 

Network Configuration and Troubleshooting Commands in Linux

Network configuration and troubleshooting are the essential part of  Linux administration. In this tutorial, we are going to review one of the most frequently used network configuration and troubleshooting commands in Linux.

1. PING

The ping command is used to check if the remote server is reachable or not. Whether it is Local Area Network (LAN) or Wide Area Network (WAN). If the packets are received, the destination device sends packets back:

ping using the IP address

$ ping 192.168.1.5
PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.
64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=0.131 ms
64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=0.126 ms
64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=0.109 ms

ping using DNS name

$ ping google.com
PING google.com (216.58.192.206) 56(84) bytes of data.
64 bytes from ord30s25-in-f206.1e100.net (216.58.192.206): icmp_seq=1 ttl=53 time=27.0 ms
64 bytes from ord30s25-in-f206.1e100.net (216.58.192.206): icmp_seq=2 ttl=53 time=27.0 ms
64 bytes from ord30s25-in-f206.1e100.net (216.58.192.206): icmp_seq=3 ttl=53 time=27.0 ms

2. NETSTAT

Netstat (network statistics) is a command line utility that can be used to list out all the network (socket) connections on a system. It lists out all the tcp, udp socket connections and the unix socket connections.

List out all connections

$ netstat -a

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 example.com:domain      *:*                     LISTEN     
tcp        0      0 localhost.localdoma:953 *:*                     LISTEN     
tcp        0      0 localhost.localdom:6082 *:*                     LISTEN
tcp6       0      0 [::]:6081               [::]:*                  LISTEN
udp6       0      0 localhost:38578         localhost:49250         ESTABLISHED

List out only listening connections

$ netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6081          0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:6081                :::*                    LISTEN

3. HOSTNAME

Hostname is used to display the system’s DNS name, and to display or set its hostname or NIS (Network Information Services) domain name.

$ hostname
rosehosting.com

To set a new hostname for the server use:

$ sudo hostname new-hostname.com
$ hostname
new-hostname.com

4. HOST

Host command is used to find out the IP address for a domain. It can also be used to find the domain name for an IP address.

To return the IP address for a domain name type the following command:

$ host google.com
google.com has address 172.217.0.46
google.com has IPv6 address 2607:f8b0:4005:802::200e
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.

To return the domain name for a IP address type the following command:

$ host 206.196.115.39
39.115.196.206.in-addr.arpa domain name pointer example.com.

5. DIG

Dig (domain information groper) is a tool that is used for querying DNS servers for various DNS records, making it very useful for troubleshooting DNS problems.

$ 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

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             106     IN      A       216.58.216.78

;; AUTHORITY SECTION:
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.

;; ADDITIONAL SECTION:
ns3.google.com.         206816  IN      A       216.239.36.10
ns4.google.com.         206816  IN      A       216.239.38.10
ns2.google.com.         206816  IN      A       216.239.34.10
ns1.google.com.         206816  IN      A       216.239.32.10

;; Query time: 0 msec
;; SERVER: 209.135.140.42#53(209.135.140.42)
;; WHEN: Sun Mar  5 18:37:21 2017
;; MSG SIZE  rcvd: 180

6. NSLOOKUP

To check for a specific record you need to specify the nslookup command, the record type — for example, A, MX, or TXT — and the host name you want to check. The following example shows how to check  A record  (IP Address) for google.com:

$ nslookup google.com
Server:         173.230.155.5
Address:        173.230.155.5#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.0.46

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.

Be the first to write a comment.

Your feedback