Essential Linux Network Commands: A Practical Guide
Network troubleshooting and configuration are crucial skills for Linux system administrators or DevOps Engineer. This guide covers essential network commands for AlmaLinux8/RHEL8 systems.
Note: Use
sudo
for commands requiring elevated privileges
1. IP Command
Modern replacement for ifconfig
. Manages network interfaces and routing.
1# Show network interfaces
2ip addr show
3
4# Enable/disable interface
5ip link set eth0 up
6ip link set eth0 down
7
8# Set IP address
9ip addr add 192.168.1.100/24 dev eth0
10
11# Show routing table
12ip route show
13
14# Add static route
15ip route add 10.0.0.0/24 via 192.168.1.1
2. Socket Statistics (ss)
Replaces netstat
, provides socket information.
1# Show TCP connections
2ss -ta
3
4# Show listening ports
5ss -ltpn
6
7# Display processes using port
8ss -ltpn | grep :80
9
10# Show UDP sockets
11ss -ua
4. Network Manager
Manages network connections and interfaces.
1# Check NetworkManager status
2systemctl status NetworkManager
3
4# View all devices
5nmcli device status
6
7# Show connection details
8nmcli connection show
9
10# View real-time logs
11journalctl -fu NetworkManager
12
13# Restart NetworkManager
14sudo systemctl restart NetworkManager
15
16# Connect specific interface
17nmcli device connect eth0
5. Ping
Tests network connectivity.
1# Basic ping
2ping google.com
3
4# Limit to 5 packets
5ping -c 5 192.168.1.1
6
7# Set interval (seconds)
8ping -i 0.5 8.8.8.8
9
10# Set packet size
11ping -s 1500 google.com
6. Traceroute
Identifies network path issues.
1# Basic trace
2traceroute google.com
3
4# Use TCP
5traceroute -T google.com
6
7# Specify port
8traceroute -p 443 google.com
7. Nmap
Network exploration and security scanning.
1# Scan host
2nmap 192.168.1.100
3
4# Scan network range
5nmap 192.168.1.0/24
6
7# Scan specific ports
8nmap -p 80,443 192.168.1.100
9
10# OS detection
11nmap -O 192.168.1.100
8. cURL
Tests web services and APIs.
1# GET request
2curl http://example.com
3
4# Download file
5curl -O http://example.com/file.zip
6
7# POST request
8curl -X POST -d "data=value" http://api.example.com
9
10# Show headers
11curl -I https://example.com
9. dig
DNS lookup utility.
1# Basic lookup
2dig example.com
3
4# Query MX records
5dig example.com MX
6
7# Use specific DNS server
8dig @8.8.8.8 example.com
9
10# Trace resolution
11dig +trace example.com
10. tcpdump
Network packet analyzer.
1# Capture interface packets
2tcpdump -i eth0
3
4# Capture specific port
5tcpdump -i eth0 port 80
6
7# Save to file
8tcpdump -w capture.pcap
9
10# Read from file
11tcpdump -r capture.pcap
11. iptables
Firewall management.
1# List rules
2iptables -L
3
4# Allow SSH
5iptables -A INPUT -p tcp --dport 22 -j ACCEPT
6
7# Block IP
8iptables -A INPUT -s 192.168.1.100 -j DROP
12. netcat (nc)
Network utility tool.
1# Listen on port
2nc -l 8080
3
4# Connect to port
5nc example.com 80
6
7# Port scanning
8nc -zv example.com 20-30
13. host
Simple DNS lookup.
1# Basic lookup
2host example.com
3
4# Reverse lookup
5host 8.8.8.8
6
7# Query MX records
8host -t MX example.com
Common Use Cases
Web Server Troubleshooting
1# Check if web server is listening
2ss -ltpn | grep :80
3
4# Test local web server
5curl -I http://localhost
6
7# Check server certificate
8openssl s_client -connect yourdomain.com:443
9
10# Monitor HTTP traffic
11tcpdump -i eth0 port 80 -A
12
13# Check error logs
14tail -f /var/log/httpd/error_log
Network Connectivity
1# Test DNS and internet connectivity
2ping -c 3 8.8.8.8
3ping -c 3 google.com
4
5# Check interface status and IP
6ip addr show
7nmcli device status
8
9# Verify routing
10ip route show
11traceroute problematic-server.com
12
13# Monitor interface traffic
14tcpdump -i eth0 -n
15
16# Check DNS resolution
17dig +trace yourdomain.com
Security Checks
1# Port scanning
2nmap -sS -p- 192.168.1.0/24
3
4# Check open connections
5ss -tapn
6
7# Monitor connections in real-time
8watch ss -tapn
9
10# Review firewall rules
11firewall-cmd --list-all
12iptables -L -n -v
13
14# Check SELinux status
15sestatus
16getenforce
Performance Analysis
1# Network interface statistics
2ip -s link show
3
4# Monitor bandwidth by process
5iftop -i eth0
6
7# Track network latency
8mtr google.com
9
10# Check network load
11netstat -s
12
13# Monitor network errors
14watch -n1 'netstat -i'
15
16# NetworkManager real-time logs
17journalctl -fu NetworkManager
Service Status
1# Check system services
2systemctl status NetworkManager
3systemctl status firewalld
4
5# View network services
6ss -tulpn
7
8# DNS resolution check
9cat /etc/resolv.conf
10dig google.com
11
12# Review network logs
13journalctl -u NetworkManager
Note: Many commands require root privileges. Use
sudo
as needed.