Network configuration in Linux involves setting up and managing network interfaces, IP addresses, routing tables, and DNS settings. It’s fundamental for system connectivity, server administration, and troubleshooting network issues.
Key Concepts
- Network Interface: Physical or virtual network connection (eth0, wlan0, lo)
- IP Address: Unique identifier for network communication
- Subnet Mask: Defines network and host portions of IP
- Gateway: Router that connects to other networks
- DNS: Domain Name System for hostname resolution
- DHCP: Dynamic Host Configuration Protocol for automatic IP assignment
Command Syntax
ip [OPTIONS] OBJECT COMMAND
- Modern replacement for older net-tools commands
- Objects: link, addr, route, neigh
- More consistent and feature-rich interface
Common Options
ip addr show - Display all network interfaces
ip route show - Show routing table
ip link set - Configure interface properties
-4 - IPv4 only
-6 - IPv6 only
Practical Examples
Example 1: View network interfaces
|
|
Shows all interfaces with IP addresses and status
Example 2: Configure static IP
|
|
Assigns static IP to ethernet interface
Example 3: Add default gateway
|
|
Sets default route through gateway
Example 4: View routing table
|
|
Displays current routing configuration
Example 5: Configure DNS
|
|
Shows DNS server configuration
Use Cases
- Setting up servers with static IP addresses
- Configuring network interfaces after installation
- Troubleshooting connectivity issues
- Managing multiple network interfaces
- Setting up routing between networks
- Configuring wireless connections
Related Commands
ping - Test network connectivity
netstat - Display network connections (deprecated)
ss - Modern socket statistics tool
nmcli - NetworkManager command-line tool
systemctl - Manage network services
dhclient - DHCP client for automatic configuration
Tips & Troubleshooting
- Use
ip addrinstead of deprecatedifconfig - Check interface status with
ip link show - Verify routing with
ip route get <destination> - Test DNS resolution with
nslookupordig - NetworkManager may override manual configurations
- Restart networking:
sudo systemctl restart networking - Persistent config files:
/etc/network/interfaces(Debian) or/etc/netplan/(Ubuntu 18+) - Use
nmtuifor text-based network configuration GUI - Check firewall rules if connectivity fails despite correct config