Contents...
Networking is an important part of Linux and it provides lots of tool and command to diagnose any networking issue.As Linux admin you may need to fix lots of connection related issue. To Troubleshoot network related issue you can use the telnet, netstat and other networking commands to find problem and solve that. You can troubleshoot most of the networking problem with the combination of find and grep command.
In this tutorial I am going to explain networking basic commands in Linux, this enables you to quickly troubleshoot connections related issue. You can troubleshoot whether another server/system connected or not, whether another host responding or not.Using these tools you can save lots of time.
hostname
Hostname command used to display the system’s DNS name or Network Information Services (NIC) domain name.
hostname :- Without any options it displays the system’s hostname.
# hostname www.looklinux.com
hostname -d :- With -d options it displays the the domain name the system belongs to.
# hostname -d looklinux.com
hostname -f :- With -f Options it displays the fully qualified host and domain name.
# hostname -f www.looklinux.com
hostname -i :- With -i Options it displays the IP address of the current System.
# hostname -i 192.168.0.6
ping
Using ping command we can check the system connectivity. It is also used for finding information as to the speed of the connection. It sends the packets of information to the user-defined source. If the packets are received then destination device sends packets back.
#ping www.looklinux.com PING looklinux.com (104.27.129.39) 56(84) bytes of data. 64 bytes from 104.27.129.39: icmp_seq=1 ttl=60 time=0.891 ms 64 bytes from 104.27.129.39: icmp_seq=2 ttl=60 time=0.874 ms 64 bytes from 104.27.129.39: icmp_seq=3 ttl=60 time=0.859 ms 64 bytes from 104.27.129.39: icmp_seq=4 ttl=60 time=0.843 ms 64 bytes from 104.27.129.39: icmp_seq=5 ttl=60 time=1.08 ms 64 bytes from 104.27.129.39: icmp_seq=6 ttl=60 time=0.877 ms 64 bytes from 104.27.129.39: icmp_seq=7 ttl=60 time=0.902 ms 64 bytes from 104.27.129.39: icmp_seq=8 ttl=60 time=0.836 ms Use ctrl+C to stop the test.
ifconfig
ifconfig stands for “interface configuration“. It is used to view network configuration. It display the current network adaptor configuration and it is handy to check if you are getting transmit (TX) or receive (RX) errors.
# ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:47337835 errors:0 dropped:0 overruns:0 frame:0 TX packets:47337835 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:40687802843 (37.8 GiB) TX bytes:40687802843 (37.8 GiB) venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:192.168.0.6 P-t-P:127.0.0.1 Bcast:0.0.0.0 Mask:255.255.255.255 UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1 RX packets:1985937445 errors:0 dropped:0 overruns:0 frame:0 TX packets:1570725174 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1946633262751 (1.7 TiB) TX bytes:750330107530 (698.7 GiB)
netstat
netstat stands for “network statistics“.This command show various network related information like Network connections,interface statistics, masquerade connections, routing tables, and multicast memberships etc.
netstat -nap | grep port :- It shows process id of applications which is using that port.
# netstat -nap | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9463/httpd tcp 0 0 10.12.145.172:80 10.12.145.174:56934 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:62042 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:56931 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:56886 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:62026 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:57157 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:56793 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:57037 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:56862 TIME_WAIT - tcp 0 0 10.12.145.172:80 10.12.145.174:61998 TIME_WAIT -
netstat -a or netstat -all :- Displays all connections with tcp and udp.
# netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:ssh *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *:http *:* LISTEN tcp 0 0 *:mit-ml-dev *:* LISTEN tcp 0 0 *:52756 *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:35712 *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *:81 *:* LISTEN udp 0 0 *:bootpc *:* udp 0 0 *:sunrpc *:* udp 0 0 ip-172-31-28-36.ec2.inte:ntp *:* udp 0 0 localhost:ntp *:* udp 0 0 *:ntp *:* udp 0 0 fe80::c53:e9ff:dhcpv6-client *:* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 8007 @/com/ubuntu/upstart unix 11 [ ] DGRAM 9350 /dev/log unix 2 [ ACC ] SEQPACKET LISTENING 8269 @/org/kernel/udev/udevd unix 2 [ ACC ] STREAM LISTENING 9805 /var/run/rpcbind.sock unix 2 [ ACC ] STREAM LISTENING 9979 /var/run/dbus/system_bus_socket unix 2 [ ] DGRAM 10094 unix 2 [ ] DGRAM 10482 unix 2 [ ] DGRAM 213971 unix 3 [ ] STREAM CONNECTED 9982 unix 3 [ ] STREAM CONNECTED 9983 unix 2 [ ] DGRAM 10460 unix 3 [ ] STREAM CONNECTED 9988 /var/run/dbus/system_bus_socket unix 2 [ ] DGRAM 9881 unix 2 [ ] DGRAM 10378 unix 2 [ ] DGRAM 10642 unix 3 [ ] STREAM CONNECTED 2052855 unix 3 [ ] STREAM CONNECTED 9987 unix 3 [ ] STREAM CONNECTED 2052854 unix 3 [ ] STREAM CONNECTED 2374500 unix 2 [ ] DGRAM 15186 unix 2 [ ] DGRAM 2374557 unix 3 [ ] STREAM CONNECTED 2052856 unix 3 [ ] STREAM CONNECTED 2374499 unix 2 [ ] DGRAM 2374496 unix 3 [ ] STREAM CONNECTED 2052853 unix 3 [ ] DGRAM 8277 unix 3 [ ] DGRAM 8278
netstat -t or netstat –tcp :- It will display only TCP connections.
# netstat -t Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 304 ip-172-31-28-36.ec2.int:ssh 45.64.11.90:53664 ESTABLISHED tcp 0 0 ip-172-31-28-36.ec2.i:39430 ip-172-31-28-36.ec2.inte:81 TIME_WAIT tcp 0 0 ip-172-31-28-36.ec2.i:47118 ip-172-31-17-62.ec2.i:mysql TIME_WAIT tcp 0 0 ip-172-31-28-36.ec2.in:http 108.162.219.105:documentum TIME_WAIT tcp 0 0 ip-172-31-28-36.ec2.in:http 172.68.78.33:31057 ESTABLISHED
netstat -u or netstat –udp :- Shows only UDP connections.
netstat -g :- It will display all multicast network subscribed by this host.
nslookup
nslookup is a useful tool for troubleshooting DNS problems, such as hostname resolution. It displays the host name and IP address of the DNS server that is configured for the local system. If you know the IP address of system you can find hostname using nslookup. You can also find all the IP address for a given domain name using nslookup command.
# nslookup www.looklinux.com Server: 10.0.80.11 Address: 10.0.80.11#53 Non-authoritative answer: www.looklinux.com canonical name = looklinux.com. Name: looklinux.com Address: 104.27.129.39 Name: looklinux.com Address: 104.27.128.39
traceroute
Traceroute also know as tracepath or tracert. It is a network tool used to determine the path packets take from one IP address to another. Traceroute allows us to find out the precisely how a data transmission travelled from your computer to another. It is handy utility to view the number of hops and response time to get to a remote system or websites routes.
# traceroute www.looklinux.com traceroute to www.looklinux.com (104.27.128.39), 30 hops max, 60 byte packets 1 31.01.1632.ip4.static.sl-reverse.com (50.22.1.49) 1.015 ms * * 2 ae0.dar01.dal05.networklayer.com (173.192.118.130) 0.770 ms 0.776 ms 0.771 ms 3 * * * 4 141.101.74.253 (141.101.74.253) 0.873 ms * * 5 104.27.128.39 (104.27.128.39) 0.800 ms 0.798 ms 0.816 ms
finger
Finger is a program we can use it to find the information about computer users. It displays the login name, full name, real name, terminal name and possibly other details abut the user you are fingering.
#finger [email protected] [looklinux.com] Login name: sagar In real life: Sagar Kumar Directory: /home/mentor/d/sagar Shell: /bin/bash Last login Tue Jul 17 15:21 on ttyQ7 from expert.looklinux.com Unread mail since Wed Feb 18 13:00:54 2017
telnet
Telnet is a network protocol used to access remote computers.Using telnet an administrator or user can access someone else’s computer remotely.Normally it is used to check the network connections live or not. You can also check the ports of remote server if telnet is not blocked on that system.
# telnet www.looklinux.com 80 Trying 104.27.129.39... Connected to www.looklinux.com. Escape character is '^]'.
I hope this article will help to understand Basic Networking Commands in Linux. If you have any queries and problem please comment in comment section.
Thanks:)
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment