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.
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 (184.108.40.206) 56(84) bytes of data. 64 bytes from ord30s25-in-f206.1e100.net (220.127.116.11): icmp_seq=1 ttl=53 time=27.0 ms 64 bytes from ord30s25-in-f206.1e100.net (18.104.22.168): icmp_seq=2 ttl=53 time=27.0 ms 64 bytes from ord30s25-in-f206.1e100.net (22.214.171.124): icmp_seq=3 ttl=53 time=27.0 ms
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
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
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 126.96.36.199 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 188.8.131.52 184.108.40.206.in-addr.arpa domain name pointer example.com.
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
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: 220.127.116.11 Address: 18.104.22.168#53 Non-authoritative answer: Name: google.com Address: 22.214.171.124
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.