Introduction
This cheat sheet provides a comprehensive list of essential Linux network commands with examples. It is designed to help system administrators and network engineers efficiently manage and troubleshoot networks on various Linux distributions.
Basic Network Commands
1. Check Network Interfaces
List all network interfaces:
ip link show
2. Display Network Configuration
Show IP address and network details:
ip addr
3. Check Network Connectivity
Ping a remote server:
ping -c 4 example.com
4. Check Routing Table
View the system's routing table:
ip route
Advanced Network Commands
1. Test DNS Resolution
Use nslookup or dig for DNS resolution:
dig example.com
2. Monitor Network Traffic
Use iftop or nload to monitor traffic:
sudo iftop
3. Trace Network Route
Trace the path to a remote server:
traceroute example.com
4. Test Port Connectivity
Use telnet or nc to test port connectivity:
nc -zv example.com 80
Useful Network Tools
1. tcpdump
Capture network packets:
sudo tcpdump -i eth0
2. netstat
Display network connections:
netstat -tuln
3. ss
Show detailed socket statistics:
ss -tuln
4. curl and wget
Test HTTP/HTTPS connections:
curl -I http://example.com
Troubleshooting Tips
- Verify network interface status with
ip link. - Test DNS resolution using
digornslookup. - Check connectivity with
pingandtraceroute. - Analyze network traffic using
tcpdump.
Examples
1. Configure a Static IP
sudo ip addr add 192.168.1.100/24 dev eth0
2. Add a Default Gateway
sudo ip route add default via 192.168.1.1
3. Flush DNS Cache
Flush the DNS cache on Ubuntu:
sudo systemd-resolve --flush-caches
Conclusion
This cheat sheet provides an overview of essential Linux network commands. Regular use of these commands will help you master network management and troubleshooting on Linux systems.