🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

Essential Linux Networking Commands: Complete Reference Guide 2026

Essential Linux Networking Commands: Complete Reference Guide 2026

Networking is the circulatory system of modern IT infrastructure. Every service, application, and user interaction depends on network connectivity. When something goes wrong β€” a website is unreachable, DNS resolution fails, latency spikes, or packets are being dropped β€” you need to diagnose the problem quickly and accurately from the command line.

This comprehensive reference covers the essential Linux networking commands that every system administrator, DevOps engineer, and network troubleshooter needs to know in 2026. From basic connectivity testing to advanced packet analysis, these commands form the toolkit for diagnosing and resolving any network issue you will encounter.

Linux networking commands and network infrastructure

Network Interface Configuration

Understanding and configuring network interfaces is the foundation of Linux networking. These commands show you what interfaces exist, how they are configured, and let you make changes.

ip β€” The Modern Network Swiss Army Knife

The ip command has replaced the older ifconfig command on all modern Linux distributions. It provides comprehensive control over network interfaces, addresses, routes, and tunnels.

  • ip addr show (or ip a) β€” Display all network interfaces and their IP addresses. This is the first command you run when troubleshooting: it shows interface names, IPv4/IPv6 addresses, MAC addresses, and interface state (UP/DOWN)
  • ip addr show eth0 β€” Show details for a specific interface
  • ip link show β€” Display interface link-layer information (MAC addresses, MTU, state)
  • ip link set eth0 up β€” Bring an interface up
  • ip link set eth0 down β€” Take an interface down
  • ip addr add 192.168.1.100/24 dev eth0 β€” Add an IP address to an interface
  • ip addr del 192.168.1.100/24 dev eth0 β€” Remove an IP address from an interface

Understanding ip addr Output

FieldMeaningExample
stateInterface operational stateUP, DOWN, UNKNOWN
mtuMaximum Transmission Unit (packet size)1500 (standard Ethernet)
inetIPv4 address with subnet mask192.168.1.100/24
inet6IPv6 addressfe80::1/64
link/etherMAC (hardware) address00:11:22:33:44:55
scopeAddress scopeglobal, link, host

Routing and Gateway Commands

Routing determines how packets travel from your server to their destination. Misconfigured routing is one of the most common causes of connectivity issues.

  • ip route show (or ip r) β€” Display the routing table. Shows the default gateway, directly connected networks, and any static routes
  • ip route get 8.8.8.8 β€” Show which route a specific destination would use. Extremely useful for debugging routing decisions
  • ip route add 10.0.0.0/8 via 192.168.1.1 β€” Add a static route
  • ip route del 10.0.0.0/8 β€” Remove a static route
  • ip route add default via 192.168.1.1 β€” Set the default gateway
  • traceroute destination (or tracepath) β€” Trace the path packets take to a destination, showing every router (hop) along the way. Essential for identifying where in the network a problem occurs
  • mtr destination β€” Combines traceroute and ping into a single real-time diagnostic tool. Shows packet loss and latency at each hop. This is the most powerful route diagnostic tool available

Connectivity Testing

These commands answer the most basic networking question: "Can I reach this destination?"

ping β€” The Universal Connectivity Test

  • ping 8.8.8.8 β€” Test basic IP connectivity to Google's DNS. If this works, your internet connection is functional
  • ping -c 5 192.168.1.1 β€” Send exactly 5 ping packets (useful in scripts)
  • ping -i 0.2 hostname β€” Ping every 0.2 seconds instead of the default 1 second (requires root)
  • ping -s 1400 hostname β€” Send larger packets to test MTU issues
  • ping6 ::1 β€” Ping using IPv6

Interpreting Ping Output

MetricGood ValueConcerning ValueMeaning
Latency (ms)< 50ms (local)> 200msRound-trip time for each packet
Packet loss0%> 1%Percentage of packets that did not return
Jitter< 5ms variance> 30ms varianceVariation in latency between packets
TTL64 or 128Very low valuesTime To Live β€” decrements at each hop

curl and wget β€” HTTP Connectivity

  • curl -I https://example.com β€” Fetch only HTTP headers (check if a web server responds)
  • curl -o /dev/null -s -w "%{http_code}" https://example.com β€” Get only the HTTP status code (useful in scripts)
  • curl -v https://example.com β€” Verbose mode showing TLS handshake, headers, and response
  • wget --spider https://example.com β€” Check if a URL is reachable without downloading
Network diagnostic tools and packet analysis

DNS Diagnostics

DNS (Domain Name System) translates domain names to IP addresses. DNS failures are the cause of an enormous percentage of "the internet is broken" reports. These commands help you diagnose DNS issues quickly.

  • dig example.com β€” Query DNS records with detailed output including TTL, record type, and response time. The most comprehensive DNS diagnostic tool
  • dig +short example.com β€” Show only the answer (just the IP address)
  • dig example.com MX β€” Query specific record types (MX for mail, AAAA for IPv6, TXT for SPF/DKIM)
  • dig @8.8.8.8 example.com β€” Query a specific DNS server (bypass your system resolver)
  • dig +trace example.com β€” Trace the full DNS resolution path from root servers to authoritative nameservers
  • nslookup example.com β€” Simpler DNS query tool (available on most systems including Windows)
  • host example.com β€” Quick DNS lookup with clean output
  • resolvectl status β€” Show systemd-resolved configuration (modern systems)

Common DNS Record Types

TypePurposeExample Query
AIPv4 addressdig example.com A
AAAAIPv6 addressdig example.com AAAA
MXMail serverdig example.com MX
CNAMEAlias to another domaindig www.example.com CNAME
TXTText records (SPF, DKIM, verification)dig example.com TXT
NSNameserversdig example.com NS
SOAStart of Authoritydig example.com SOA
PTRReverse DNS (IP to hostname)dig -x 8.8.8.8

Port and Connection Analysis

Understanding which ports are open, which services are listening, and who is connected is essential for both troubleshooting and security.

ss β€” Socket Statistics (Modern)

The ss command has replaced netstat on modern systems. It is faster and provides more detailed information.

  • ss -tuln β€” Show all listening TCP and UDP ports with numeric addresses. This is the "what is my server exposing?" command
  • ss -tunp β€” Show established connections with process names (requires root for -p)
  • ss -s β€” Display socket statistics summary (total connections by state)
  • ss state established β€” Show only established connections
  • ss -tuln sport = :80 β€” Filter for a specific port
  • ss -o state time-wait β€” Show TIME_WAIT connections (useful for diagnosing connection exhaustion)

netstat β€” Legacy but Still Useful

  • netstat -tuln β€” Equivalent to ss -tuln (available on older systems)
  • netstat -rn β€” Display routing table (equivalent to ip route show)
  • netstat -s β€” Protocol statistics (TCP retransmissions, errors, etc.)

Testing Port Connectivity

  • nc -zv hostname 443 β€” Test if a specific port is open (netcat)
  • nc -zv hostname 80-100 β€” Scan a range of ports
  • telnet hostname 25 β€” Connect to a specific port (useful for testing SMTP, HTTP manually)
  • nmap -sT hostname β€” Comprehensive port scan (more powerful than nc, must install separately)
  • nmap -sV hostname β€” Detect service versions on open ports

Firewall Management

Firewalls control which traffic is allowed in and out of your server. Misconfigured firewalls are one of the top causes of "my service is running but nobody can connect."

FirewallD (RHEL/AlmaLinux/Rocky/Fedora)

  • firewall-cmd --state β€” Check if firewall is running
  • firewall-cmd --list-all β€” Show all rules for the default zone
  • firewall-cmd --permanent --add-port=8080/tcp β€” Open a port permanently
  • firewall-cmd --permanent --add-service=https β€” Allow a service by name
  • firewall-cmd --reload β€” Apply permanent changes

UFW (Ubuntu/Debian)

  • ufw status verbose β€” Show all firewall rules
  • ufw allow 443/tcp β€” Allow incoming TCP on port 443
  • ufw deny from 10.0.0.0/8 β€” Block an IP range
  • ufw enable / ufw disable β€” Toggle the firewall

iptables (Low-Level)

  • iptables -L -n -v β€” List all rules with packet/byte counters
  • iptables -A INPUT -p tcp --dport 80 -j ACCEPT β€” Add an allow rule
  • iptables -A INPUT -s 10.0.0.0/8 -j DROP β€” Block an IP range

Bandwidth and Traffic Monitoring

Monitoring network bandwidth helps identify bottlenecks, unusual traffic patterns, and potential security issues.

  • iftop β€” Real-time bandwidth monitoring per connection (like top for network). Shows which connections are consuming the most bandwidth
  • nethogs β€” Group bandwidth usage by process (shows which application is using the network)
  • vnstat β€” Long-term traffic monitoring with hourly, daily, and monthly statistics
  • iperf3 -s (server) / iperf3 -c server-ip (client) β€” Measure network throughput between two hosts. Essential for validating bandwidth capacity
  • tc qdisc show β€” Show traffic control and queuing disciplines (advanced QoS)

Packet Capture and Analysis

When higher-level tools cannot identify the problem, packet capture lets you see exactly what is happening on the wire.

  • tcpdump -i eth0 β€” Capture all packets on an interface
  • tcpdump -i eth0 port 80 β€” Capture only HTTP traffic
  • tcpdump -i eth0 host 192.168.1.100 β€” Capture traffic to/from a specific host
  • tcpdump -i eth0 -w capture.pcap β€” Save capture to a file for later analysis (open in Wireshark)
  • tcpdump -i eth0 -c 100 β€” Capture exactly 100 packets then stop
  • tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0' β€” Capture only SYN packets (new connections)

Network Troubleshooting Workflow

When diagnosing network issues, follow this systematic approach:

  1. Check local interface: ip addr show β€” Is the interface up? Does it have an IP?
  2. Test local connectivity: ping gateway-ip β€” Can you reach your default gateway?
  3. Test internet connectivity: ping 8.8.8.8 β€” Can you reach the internet by IP?
  4. Test DNS resolution: dig example.com β€” Is DNS working?
  5. Check routing: ip route get destination-ip β€” Is traffic going the right way?
  6. Check firewall: firewall-cmd --list-all or iptables -L -n β€” Is the firewall blocking traffic?
  7. Check services: ss -tuln β€” Is the service actually listening?
  8. Trace the path: mtr destination β€” Where in the network is the problem?
  9. Capture packets: tcpdump β€” What is actually happening on the wire?

Quick Reference Table

TaskCommand
Show IP addressesip addr show
Show routing tableip route show
Test connectivityping hostname
DNS lookupdig hostname
Trace routemtr hostname
Show listening portsss -tuln
Test port opennc -zv host port
Firewall rulesfirewall-cmd --list-all
Capture packetstcpdump -i eth0
Bandwidth monitoringiftop

Frequently Asked Questions

What is the difference between ip and ifconfig?

ip is the modern replacement for ifconfig. The ifconfig command is deprecated on most modern Linux distributions and may not be installed by default. Always use ip addr instead of ifconfig, ip route instead of route, and ss instead of netstat.

How do I find which process is using a specific port?

Run ss -tulnp | grep :PORT (replace PORT with the port number). The -p flag shows the process name and PID. You may need root/sudo to see process information for services running as other users.

How do I check if a remote port is open?

Use nc -zv hostname port for a quick test. For more thorough scanning, use nmap hostname. If nc reports "Connection refused," the port is closed but the host is reachable. If it times out, either the port is filtered by a firewall or the host is unreachable.

What does "Connection refused" mean vs "Connection timed out"?

"Connection refused" means the host received your connection request but no service is listening on that port β€” the host is reachable but the service is not running. "Connection timed out" means the host never responded β€” either it is down, unreachable, or a firewall is silently dropping packets.

How do I find my public IP address from the command line?

Run curl -s ifconfig.me or curl -s icanhazip.com. These services return your public-facing IP address. For finding your local/private IP, use ip addr show and look for inet addresses on your primary interface.

Related Resources

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.