Linux Networking Basics: Commands and Configuration
Essential Linux networking commands and configuration for IP addressing, routing, DNS, firewall rules, and network troubleshooting.
Linux Networking Overview
Linux networking is powerful and flexible. Every Linux system can function as a client, server, router, firewall, or bridge. Understanding Linux networking commands is essential for system administration and cybersecurity.
Prerequisites
Basic Linux command line skills. Understanding of IP addresses and ports.
Network Interface Configuration
ip addr show # View IP addresses (modern)
ip link show # View interfaces
ip route show # View routing table
ifconfig # Legacy alternative
iwconfig # Wireless interfaces
Configuring IP Addresses
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
sudo ip addr del 192.168.1.100/24 dev eth0
DNS Configuration
cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 1.1.1.1
nslookup google.com
dig google.com
host google.com
Network Diagnostics
ping -c 4 google.com # Test connectivity
traceroute google.com # Trace network path
traceroute -I google.com # Use ICMP instead of UDP
ss -tulpn # Listening ports (modern)
netstat -tulpn # Listening ports (legacy)
nc -zv 192.168.1.1 22 80 443 # Test TCP ports
curl -I https://example.com # HTTP request
Packet Capture
sudo tcpdump -i eth0 # All traffic
sudo tcpdump -i eth0 port 80 # HTTP traffic
sudo tcpdump -i eth0 host 192.168.1.100 # Specific host
sudo tcpdump -i eth0 -w capture.pcap # Save to file
tcpdump -r capture.pcap # Read capture file
sudo tcpdump -c 100 -i eth0 # Limit to 100 packets
Firewall Management
iptables
sudo iptables -L -n -v # View rules
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -j DROP # Default deny
sudo iptables-save > /etc/iptables/rules.v4
ufw (Simple Firewall)
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status verbose
Persistent Network Configuration
Netplan (Modern)
# /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
sudo netplan apply
Real-World Examples
Find public IP: curl -s ifconfig.me
Check service on port: sudo lsof -i :80
Test throughput: iperf3 -c server-ip
Monitor bandwidth: nload or iftop
Common Mistakes
Using ifconfig on modern systems (use ip). Forgetting sudo for packet capture. Having multiple default gateways. Opening too many firewall ports.
Best Practices
Use iproute2 suite (ip,ss) over legacy tools. Document network changes. Use persistent config (Netplan). Default deny firewall rules. Monitor traffic for anomalies.
Related Tools
nmap — Network discovery. tcpdump — Packet capture. Wireshark — Graphical analysis. iperf3 — Bandwidth testing. nload — Bandwidth monitoring.
Related Articles
Summary
Linux networking commands provide control over interfaces, routing, DNS, firewalls, and traffic analysis. Key commands: ip (interfaces), ss (sockets), ping (connectivity), tcpdump (packet capture), iptables/ufw (firewall).