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
For detailed option tables and diagnostic workflows, review our dedicated command references: test ICMP reachability with ping, analyze network hops with traceroute, inspect modern kernel socket statistics with ss, and compare legacy network socket states with netstat.
To inspect or configure network hostnames, domain resolution identities, and system deployment metadata, consult our guides for traditional hostname and systemd hostnamectl.
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).
Knowledge Check
ss and netstat?Frequently Asked Questions
Continue Learning
Linux Commands Explained: Essential Commands with Examples for Beginners
Understand Linux command syntax, options and arguments through practical examples for navigation, files, permissions, processes, networking and text.
Linux · Beginner100 Essential Linux Commands Every Beginner Should Know
A quick-reference cheat sheet of 100 essential Linux commands every beginner should know, organized by category with syntax, examples, and practical use cases for system administration and cybersecurity.
Linux · BeginnerKali Linux in VirtualBox: Complete Setup Guide
Step-by-step guide to installing Kali Linux in VirtualBox including VM configuration, guest additions, networking modes, and post-installation setup.
Linux · BeginnerLinux Package Management: APT, DPKG, and Beyond
Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.
Related Security Tools
Nmap
Learn how to use Nmap, the free open-source network scanner: run your first port scan, discover live hosts, detect services and operating systems, and check for vulnerabilities with NSE scripts — a beginner tutorial for Kali Linux.
Sniffing & Spoofingtcpdump
tcpdump is a powerful, lightweight command-line packet analyzer that allows users to capture, parse, and filter TCP/IP and other packets transmitted or received over a network.
Information Gatheringdig
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s).
Information GatheringSMBClient
Learn how to use SMBClient on Kali Linux: install Samba's FTP-like SMB/CIFS client, list shares, connect as a guest or with credentials, browse folders, and upload or download files on Windows, Samba, or NAS devices. For authorized assessments, check ports 139/445 with Nmap before testing share permissions.