DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Debugging Core Dump Files on Linux - A Detailed Guide
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Your Network, Your Rules: Take Charge With Own DNS

Trending

  • A Guide to Container Runtimes
  • Unlocking AI Coding Assistants Part 3: Generating Diagrams, Open API Specs, And Test Data
  • Building Scalable and Resilient Data Pipelines With Apache Airflow
  • Google Cloud Document AI Basics
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Top 10 Essential Linux Commands

Top 10 Essential Linux Commands

This article provides 10 commands that are vital for troubleshooting network issues on Linux systems with real-world examples.

By 
Prashanth Ravula user avatar
Prashanth Ravula
DZone Core CORE ·
Apr. 30, 24 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
14.0K Views

Join the DZone community and get the full member experience.

Join For Free

As a Linux administrator or even if you are a newbie who just started using Linux, having a good understanding of useful commands in troubleshooting network issues is paramount. 

We'll explore the top 10 essential Linux commands for diagnosing and resolving common network problems. Each command will be accompanied by real-world examples to illustrate its usage and effectiveness.

1. ping

Example: ping google.com

Shell
 
test@ubuntu-server ~ % ping google.com -c 5

PING google.com (142.250.189.206): 56 data bytes

64 bytes from 142.250.189.206: icmp_seq=0 ttl=58 time=14.610 ms

64 bytes from 142.250.189.206: icmp_seq=1 ttl=58 time=18.005 ms

64 bytes from 142.250.189.206: icmp_seq=2 ttl=58 time=19.402 ms

64 bytes from 142.250.189.206: icmp_seq=3 ttl=58 time=22.450 ms

64 bytes from 142.250.189.206: icmp_seq=4 ttl=58 time=15.870 ms

--- google.com ping statistics ---

5 packets transmitted, 5 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 14.610/18.067/22.450/2.749 ms

test@ubuntu-server ~ %


Explanation

ping uses ICMP protocol, where ICMP stands for internet control message protocol and ICMP is a network layer protocol used by network devices to communicate. ping helps in testing the reachability of the host and it will also help in finding the latency between the source and destination.

2. traceroute

Example: traceroute google.com

Shell
 
test@ubuntu-server ~ % traceroute google.com
traceroute to google.com (142.250.189.238), 64 hops max, 52 byte packets
 1  10.0.0.1 (10.0.0.1)  6.482 ms  3.309 ms  3.685 ms
 2  96.120.90.197 (96.120.90.197)  13.094 ms  10.617 ms  11.351 ms
 3  po-301-1221-rur01.fremont.ca.sfba.comcast.net (68.86.248.153)  12.627 ms  11.240 ms  12.020 ms
 4  ae-236-rar01.santaclara.ca.sfba.comcast.net (162.151.87.245)  18.902 ms  44.432 ms  18.269 ms
 5  be-299-ar01.santaclara.ca.sfba.comcast.net (68.86.143.93)  14.826 ms  13.161 ms  12.814 ms
 6  69.241.75.42 (69.241.75.42)  12.236 ms  12.302 ms
    69.241.75.46 (69.241.75.46)  15.215 ms
 7  * * *
 8  142.251.65.166 (142.251.65.166)  21.878 ms  14.087 ms
    209.85.243.112 (209.85.243.112)  14.252 ms
 9  nuq04s39-in-f14.1e100.net (142.250.189.238)  13.666 ms
    192.178.87.152 (192.178.87.152)  12.657 ms  13.170 ms
test@ubuntu-server ~ %


Explanation

Traceroute shows the route packets take to reach a destination host. It displays the IP addresses of routers along the path and calculates the round-trip time (RTT) for each hop. Traceroute helps identify network congestion or routing issues.

3. netstat

Example: netstat -tulpn

Shell
 
test@ubuntu-server ~ % netstat -tuln 
Active LOCAL (UNIX) domain sockets
Address          Type   Recv-Q Send-Q            Inode             Conn             Refs          Nextref Addr
aaf06ba76e4d0469 stream      0      0                0 aaf06ba76e4d03a1                0                0 /var/run/mDNSResponder
aaf06ba76e4d03a1 stream      0      0                0 aaf06ba76e4d0469                0                0
aaf06ba76e4cd4c1 stream      0      0                0 aaf06ba76e4ccdb9                0                0 /var/run/mDNSResponder
aaf06ba76e4cace9 stream      0      0                0 aaf06ba76e4c9e11                0                0 /var/run/mDNSResponder
aaf06ba76e4d0b71 stream      0      0                0 aaf06ba76e4d0aa9                0                0 /var/run/mDNSResponder
test@ubuntu-server ~ % 


Explanation

Netstat displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It's useful for troubleshooting network connectivity, identifying open ports, and monitoring network performance.

4. ifconfig/ip

Example: ifconfig or ifconfig <interface name>

Shell
 
test@ubuntu-server ~ % ifconfig en0 
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=6460<TSO4,TSO6,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
	ether 10:9f:41:ad:91:60
	inet 10.0.0.24 netmask 0xffffff00 broadcast 10.0.0.255
	inet6 fe80::870:c909:df17:7ed1%en0 prefixlen 64 secured scopeid 0xc 
	inet6 2601:641:300:e710:14ef:e605:4c8d:7e09 prefixlen 64 autoconf secured 
	inet6 2601:641:300:e710:d5ec:a0a0:cdbb:79a7 prefixlen 64 autoconf temporary 
	inet6 2601:641:300:e710::6cfc prefixlen 64 dynamic 
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect
	status: active
test@ubuntu-server ~ %


Explanation

ifconfig and ip commands are used to view and configure network parameters. They provide information about the IP address, subnet mask, MAC address, and network status of each interface.

5. tcpdump

Example:tcpdump -i en0 tcp port 80

Shell
 
test@ubuntu-server ~ % tcpdump -i en0 tcp port 80
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on en0, link-type EN10MB (Ethernet), snapshot length 524288 bytes

0 packets captured
55 packets received by filter
0 packets dropped by kernel
test@ubuntu-server ~ %


Explanation

Tcpdump is a packet analyzer that captures and displays network traffic in real-time. It's invaluable for troubleshooting network issues, analyzing packet contents, and identifying abnormal network behavior. Use tcpdump to inspect packets on specific interfaces or ports.

6. nslookup/dig

Example: nslookup google.com or dig 

Shell
 
test@ubuntu-server ~ % nslookup google.com
Server:		2001:558:feed::1
Address:	2001:558:feed::1#53

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

test@ubuntu-server ~ % 

test@ubuntu-server ~ % dig google.com

; <<>> DiG 9.10.6 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46600
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		164	IN	A	142.250.189.206

;; Query time: 20 msec
;; SERVER: 2001:558:feed::1#53(2001:558:feed::1)
;; WHEN: Mon Apr 15 22:55:35 PDT 2024
;; MSG SIZE  rcvd: 55

test@ubuntu-server ~ % 


Explanation

nslookup and dig are DNS lookup tools used to query DNS servers for domain name resolution. They provide information about the IP address associated with a domain name and help diagnose DNS-related problems such as incorrect DNS configuration or server unavailability.

7. iptables/firewalld

Example: iptables -L or firewall-cmd --list-all

Shell
 
test@ubuntu-server ~# iptables -L
Chain INPUT (policy ACCEPT)
target   prot opt source  destination

Chain FORWARD (policy DROP)
target   prot opt source  destination

Chain OUTPUT (policy ACCEPT)
target   prot opt source  destination
test@ubuntu-server ~# 


Explanation

iptables and firewalld are firewall management tools used to configure packet filtering and network address translation (NAT) rules. They control incoming and outgoing traffic and protect the system from unauthorized access. Use them to diagnose firewall-related issues and ensure proper traffic flow.

8. ss

Example: ss -tulpn

Shell
 
test@ubuntu-server ~#
Netid  State Recv-Q  Send-Q        Local Address:Port     Peer Address:Port
udp	   UNCONN 0        0                *:161                   *:*	
udp	   UNCONN 0        0                *:161                   *:*	
test@ubuntu-server ~#


Explanation

ss is a utility to investigate sockets. It displays information about TCP, UDP, and UNIX domain sockets, including listening and established connections, connection state, and process IDs. ss is useful for troubleshooting socket-related problems and monitoring network activity.

9. arp

Example: arp -a

Shell
 
test@ubuntu-server ~ % arp -a
? (10.0.0.1) at 80:da:c2:95:aa:f7 on en0 ifscope [ethernet]
? (10.0.0.57) at 1c:4d:66:bb:49:a on en0 ifscope [ethernet]
? (10.0.0.83) at 3a:4a:df:fe:66:58 on en0 ifscope [ethernet]
? (10.0.0.117) at 70:2a:d5:5a:cc:14 on en0 ifscope [ethernet]
? (10.0.0.127) at fe:e2:1c:4d:b3:f7 on en0 ifscope [ethernet]
? (10.0.0.132) at bc:d0:74:9a:51:85 on en0 ifscope [ethernet]
? (10.0.0.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
mdns.mcast.net (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
? (239.255.255.250) at 1:0:5e:7f:ff:fa on en0 ifscope permanent [ethernet]
test@ubuntu-server ~ %


Explanation

arp (Address Resolution Protocol) displays and modifies the IP-to-MAC address translation tables used by the kernel. It resolves IP addresses to MAC addresses and vice versa. arp is helpful for troubleshooting issues related to network device discovery and address resolution.

10. mtr

Example: mtr 

Shell
 
test.ubuntu.com (0.0.0.0)                       Tue Apr 16 14:46:40 2024
Keys: Help Display mode Restart statistics    Order of fields  quit Packets  Ping

Host                                               Loss% Snt Last Avg Best Wrst StDev
1. 10.0.0.10 								       0.0% 143  0.8 9.4  0.7  58.6 15.2
2. 10.0.2.10									   0.0% 143  0.8 9.4  0.7  58.6 15.2
3. 192.168.0.233 								   0.0% 143  0.8 9.4  0.7  58.6 15.2
4. 142.251.225.178								   0.0% 143  0.8 9.4  0.7  58.6 15.2
5. 142.251.225.177								   0.0% 143  0.8 9.4  0.7  58.6 15.2


Explanation

mtr (My traceroute) combines the functionality of ping and traceroute into a single diagnostic tool. It continuously probes network paths between the host and a destination, displaying detailed statistics about packet loss, latency, and route changes. Mtr is ideal for diagnosing intermittent network problems and monitoring network performance over time.

Mastering these commands comes in handy for troubleshooting network issues on Linux hosts.

Address Resolution Protocol Domain Name System Linux (operating system)

Opinions expressed by DZone contributors are their own.

Related

  • Debugging Core Dump Files on Linux - A Detailed Guide
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Your Network, Your Rules: Take Charge With Own DNS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!