Linux powers everything from embedded devices to enterprise servers, and at the heart of its versatility lies robust networking capabilities. Whether you’re a system administrator managing servers, a developer debugging application connectivity, or a hobbyist setting up a home lab, understanding Linux networking fundamentals is critical. This blog demystifies basic Linux networking, covering core concepts, configuration tools, troubleshooting workflows, and best practices. By the end, you’ll be equipped to configure network interfaces, diagnose common issues, and maintain reliable connectivity in Linux environments.
Table of Contents
- Fundamental Networking Concepts
- IP Addressing & Subnetting
- Default Gateway
- DNS (Domain Name System)
- Essential Networking Tools
ip(Replacements forifconfig)- NetworkManager:
nmcli&nmtui netplan(Modern Configuration)
- Configuring Network Interfaces
- Dynamic IP (DHCP)
- Static IP Assignment
- DNS and Hostname Configuration
/etc/resolv.confand DNS Servers- Hostname Management
/etc/hostsfor Local Resolution
- Troubleshooting Common Networking Issues
- Verifying Connectivity:
ping,traceroute,mtr - Inspecting Ports and Connections:
ss - Packet Capture:
tcpdump - Firewall Checks:
iptables/ufw
- Verifying Connectivity:
- Best Practices
- Conclusion
- References
Fundamental Networking Concepts
Before diving into configuration, let’s clarify key networking terms:
IP Addressing & Subnetting
An IP address (e.g., 192.168.1.10) uniquely identifies a device on a network. IPv4 (32-bit) is most common, but IPv6 (128-bit) is growing.
- Subnet Mask/CIDR: Defines the network portion of an IP. For example,
192.168.1.10/24(CIDR notation) means the first 24 bits are the network (192.168.1.0), and the last 8 bits are for hosts. The subnet mask here is255.255.255.0.
Default Gateway
A gateway is a router that connects your local network to external networks (e.g., the internet). Use ip route show to view the default gateway:
ip route show | grep default # Output: default via 192.168.1.1 dev eth0
DNS (Domain Name System)
DNS translates human-readable domain names (e.g., google.com) to IP addresses. Without DNS, you’d need to remember 8.8.8.8 instead of google.com.
Essential Networking Tools
Linux offers powerful tools to manage and monitor networks. Here are the most critical:
ip Command (iproute2 Suite)
The ip command replaces legacy tools like ifconfig and route. Key subcommands:
| Task | Command Example |
|---|---|
| Show interfaces | ip link show |
| Show IP addresses | ip addr show (or ip a) |
| Bring interface up/down | ip link set eth0 up / ip link set eth0 down |
| Add static route | ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0 |
NetworkManager: nmcli & nmtui
NetworkManager is a dynamic network management tool (default on most Linux desktops/servers).
-
nmcli(CLI): Manage connections, interfaces, and settings.
Example: List active connections:nmcli connection show --active # "Wired connection 1" might be the default -
nmtui(Text UI): Interactive menu for configuring networks (runnmtuiin terminal).
netplan (Modern Configuration)
Netplan (used in Ubuntu 18.04+, Debian 10+) uses YAML config files to define networks. Configs live in /etc/netplan/ (e.g., 01-netcfg.yaml).
Configuring Network Interfaces
Dynamic IP (DHCP)
Most home networks use DHCP to assign IPs automatically.
With nmcli:
nmcli connection modify "Wired connection 1" ipv4.method auto
nmcli connection up "Wired connection 1" # Apply changes
With netplan:
Edit /etc/netplan/01-netcfg.yaml:
network:
version: 2
renderer: NetworkManager # Use NetworkManager (or systemd-networkd)
ethernets:
eth0: # Replace with your interface name (check `ip link show`)
dhcp4: true # Enable IPv4 DHCP
dhcp6: true # Optional: Enable IPv6 DHCP
Apply with:
sudo netplan apply
Static IP Assignment
For servers, static IPs ensure consistent connectivity.
With nmcli:
nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \ # IP and subnet (CIDR)
ipv4.gateway 192.168.1.1 \ # Default gateway
ipv4.dns "8.8.8.8, 8.8.4.4" # DNS servers (Google DNS)
nmcli connection up "Wired connection 1"
With netplan:
Edit /etc/netplan/01-netcfg.yaml:
network:
version: 2
renderer: networkd # Use systemd-networkd (no GUI)
ethernets:
enp0s3: # Interface name (check `ip link show`)
addresses: [192.168.1.100/24] # Static IP/CIDR
gateway4: 192.168.1.1 # Default gateway (IPv4)
nameservers:
addresses: [8.8.8.8, 8.8.4.4] # DNS servers
Apply:
sudo netplan apply
DNS and Hostname Configuration
DNS Servers
DNS servers are defined in /etc/resolv.conf, but modern systems (using NetworkManager or systemd-resolved) may manage this file dynamically.
With nmcli:
Set DNS for a connection:
nmcli connection modify "Wired connection 1" ipv4.dns "8.8.8.8, 1.1.1.1"
nmcli connection up "Wired connection 1"
With netplan:
DNS is configured directly in the netplan YAML (see static IP example above).
Hostname Management
The hostname identifies your system on the network.
-
View/set hostname:
hostname # Show current hostname sudo hostnamectl set-hostname "server01" # Set new hostname (persistent) -
/etc/hostname: Stores the hostname (updated byhostnamectl).
/etc/hosts File
For local name resolution (bypassing DNS), edit /etc/hosts:
sudo nano /etc/hosts
Add entries like:
127.0.0.1 localhost
192.168.1.50 nas.local # Map "nas.local" to a local server
Troubleshooting Common Networking Issues
When connectivity fails, follow this workflow:
1. Verify Interface Status
Check if the interface is up and has an IP:
ip link show eth0 # "UP" should appear (e.g., `<BROADCAST,MULTICAST,UP,LOWER_UP>`)
ip addr show eth0 # Ensure an IP is assigned (e.g., `inet 192.168.1.100/24`)
2. Test Connectivity
ping: Check if a host is reachable (ICMP):
ping -c 4 192.168.1.1 # Ping gateway (4 packets)
ping -c 4 8.8.8.8 # Ping Google DNS (test internet)
traceroute: Trace path to a host (shows hops):
traceroute google.com # Identify where the connection fails
mtr: Combines ping and traceroute (real-time):
mtr google.com # Ctrl+C to exit; look for packet loss
3. Inspect Ports and Connections
Use ss (replaces netstat) to check open ports and active connections:
ss -tuln # Show listening TCP/UDP ports (t: TCP, u: UDP, l: listening, n: numeric)
ss -tulnp # Show process IDs (requires root: `sudo ss -tulnp`)
ss -t state established # Show established TCP connections
4. Capture Packets with tcpdump
Debug traffic with packet capture (e.g., port 80):
sudo tcpdump -i eth0 port 80 # Capture HTTP traffic on eth0
sudo tcpdump -w capture.pcap # Save to file (open with Wireshark later)
5. Check Firewall Rules
Linux firewalls (e.g., iptables, ufw) may block traffic.
ufw (Uncomplicated Firewall, user-friendly):
sudo ufw status # Show active rules (e.g., "Status: active, Allow 22/tcp")
sudo ufw allow 80/tcp # Allow HTTP (if needed)
iptables (advanced):
sudo iptables -L # List all rules (look for DROP/REJECT on critical ports)
Common Issues & Fixes
| Symptom | Likely Cause | Fix |
|---|---|---|
| No IP address | DHCP failure or misconfigured static | sudo dhclient eth0 (force DHCP) or check netplan/nmcli config |
| Can ping IP but not domain | DNS failure | Check /etc/resolv.conf or set DNS via nmcli/netplan |
| Connection refused | Firewall block or service not running | Check ss -tuln for listening port; allow via ufw |
Best Practices
- Use Modern Tools: Prefer
ipoverifconfig,nmcli/netplanover manual config files. - Backup Configs: Before editing, backup files (e.g.,
sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak). - Static IP for Servers: Avoid DHCP for critical services (e.g., databases, web servers).
- Secure with Firewalls: Default-deny incoming traffic; allow only necessary ports (e.g., 22 for SSH, 80/443 for web).
- Document Changes: Log network config modifications (e.g., IP assignments, DNS servers).
- Monitor Networks: Use tools like
iftop(bandwidth) ornloadto track usage.
Conclusion
Mastering basic Linux networking is foundational for system administration and development. By understanding IP addressing, using tools like ip, nmcli, and netplan, and following troubleshooting workflows, you can resolve most connectivity issues efficiently. Remember to prioritize security with firewalls and document changes to maintain reliable networks.
With these skills, you’ll be well-equipped to manage Linux networks in home labs, enterprise environments, or cloud instances.
References
- iproute2 Documentation
- NetworkManager Manual
- Netplan Guide (Ubuntu)
- Linux man pages:
man ip,man nmcli,man tcpdump - DigitalOcean: Linux Networking Basics