Linux networking configuration involves multiple approaches and configuration files across different distributions. Understanding these files and systems is crucial for managing network interfaces, DNS resolution, hostnames, and network services. This comprehensive guide covers traditional configuration files, modern network managers, and distribution-specific approaches.
Network Configuration Systems Comparison
| Configuration System | Distributions | Primary Files | Management Tools | Use Case |
|---|---|---|---|---|
| Traditional Files | Debian, older systems | /etc/network/interfaces /etc/resolv.conf |
ifup, ifdown, ip | Simple static configurations |
| NetworkManager | Most modern distros | Keyfile, ifcfg-rh | nmcli, nmtui, GUI | Desktop, dynamic networks |
| systemd-networkd | Recent systemd distros | /etc/systemd/network/ | networkctl, systemctl | Server, minimal systems |
| netplan | Ubuntu 18.04+ | /etc/netplan/ | netplan apply | Cloud, Ubuntu servers |
• Check current system:
ps aux | grep -E '(NetworkManager|systemd-networkd)'• View interfaces:
ip addr show or ifconfig• Test connectivity:
ping -c 3 8.8.8.8 and ping -c 3 google.com• Check DNS:
nslookup google.com or dig google.com• Always backup config files before making changes
• Test network changes in non-production environments first
Network Configuration Workflow
Complete Network Configuration Process
Essential Network Configuration Files
| Configuration File | Purpose | Distributions | Syntax | Restart Command |
|---|---|---|---|---|
| /etc/hostname | System hostname | All Linux | Plain text | hostnamectl set-hostname |
| /etc/hosts | Local hostname resolution | All Linux | IP hostname aliases | Immediate |
| /etc/resolv.conf | DNS servers | All Linux | nameserver, search | Immediate |
| /etc/nsswitch.conf | Name service switch | All Linux | Service order | Immediate |
| /etc/network/interfaces | Network interfaces (Debian) | Debian/Ubuntu | iface, auto, allow-* | systemctl restart networking |
| /etc/sysconfig/network-scripts/ | Network interfaces (Red Hat) | RHEL/CentOS | KEY=VALUE pairs | systemctl restart network |
Traditional Network Configuration
Configure network interfaces using /etc/network/interfaces.
Common Configurations:
# Static IP configuration
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
# DHCP configuration
auto eth0
iface eth0 inet dhcp
# Bridge configuration
auto br0
iface br0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
bridge_ports eth0
Configure network interfaces using ifcfg files.
Common Configurations:
# Static IP - /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
TYPE=Ethernet
# DHCP - /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
# Bridge - /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
ONBOOT=yes
Configure hostname resolution and DNS settings.
Configuration Files:
# /etc/hostname
server1.example.com
# /etc/hosts
127.0.0.1 localhost localhost.localdomain
192.168.1.100 server1.example.com server1
192.168.1.101 server2.example.com server2
# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com local
Modern Network Managers
| Network Manager | Configuration Files | Management Tools | Best For | Example Distributions |
|---|---|---|---|---|
| NetworkManager | /etc/NetworkManager/ ~/.config/NetworkManager/ |
nmcli, nmtui, GUI | Desktops, laptops | Ubuntu, Fedora, RHEL |
| systemd-networkd | /etc/systemd/network/ | networkctl, systemctl | Servers, minimal systems | Ubuntu Server, CoreOS |
| netplan | /etc/netplan/*.yaml | netplan apply | Ubuntu servers, cloud | Ubuntu 18.04+ |
| Traditional | /etc/network/interfaces /etc/sysconfig/network-scripts/ |
ifup, ifdown, ip | Simple setups | Debian, CentOS 7 |
NetworkManager Configuration
Manage NetworkManager from command line.
Common Commands:
nmcli connection show- List connectionsnmcli device status- Show device statusnmcli connection up "connection-name"- Activate connectionnmcli connection down "connection-name"- Deactivate connection
Configuration Examples:
# Add static IP connection
nmcli connection add type ethernet con-name "static-eth0" \
ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1
# Modify existing connection
nmcli connection modify "static-eth0" ipv4.dns "8.8.8.8,8.8.4.4"
# Add WiFi connection
nmcli device wifi connect "SSID" password "password"
Configuration files for NetworkManager.
Key Files:
NetworkManager.conf- Main configurationsystem-connections/- Connection profilesconf.d/- Additional configuration
Connection File Example:
# /etc/NetworkManager/system-connections/static-eth0.nmconnection
[connection]
id=static-eth0
type=ethernet
interface-name=eth0
[ipv4]
method=manual
addresses=192.168.1.100/24
gateway=192.168.1.1
dns=8.8.8.8;8.8.4.4;
[ipv6]
method=auto
Text-based user interface for NetworkManager.
Features:
- Interactive text interface
- No X server required
- Easy connection management
- Systemd service integration
Usage:
# Start nmtui
sudo nmtui
# Available options:
# - Edit a connection
# - Activate a connection
# - Set system hostname
# - Quit
systemd-networkd Configuration
Configure networks with systemd-networkd.
Example Configurations:
# /etc/systemd/network/10-eth0.network
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4
Domains=example.com
# DHCP configuration
[Match]
Name=eth0
[Network]
DHCP=yes
Configure network device properties.
Link File Examples:
# /etc/systemd/network/10-eth0.link
[Match]
MACAddress=00:11:22:33:44:55
[Link]
Name=eth0
MTUBytes=1500
WakeOnLan=magic
# Rename interface by MAC
[Match]
MACAddress=aa:bb:cc:dd:ee:ff
[Link]
Name=lan0
Configure advanced network features.
Advanced Configurations:
# Bridge - /etc/systemd/network/20-br0.netdev
[NetDev]
Name=br0
Kind=bridge
# VLAN - /etc/systemd/network/30-vlan100.netdev
[NetDev]
Name=vlan100
Kind=vlan
[VLAN]
Id=100
# Bridge network configuration
[Match]
Name=br0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
Netplan Configuration (Ubuntu)
Configure networks using Netplan YAML files.
Example Configurations:
# /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
routes:
- to: 10.0.0.0/8
via: 192.168.1.254
# DHCP configuration
network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: true
dhcp6: false
Manage and apply Netplan configurations.
Common Commands:
netplan generate- Generate configurationnetplan apply- Apply configurationnetplan try- Apply with rollbacknetplan info- Show debug information
Usage:
# Apply network configuration
sudo netplan apply
# Test configuration with rollback
sudo netplan try
# Press ENTER to accept, Ctrl+C to revert
# Generate configuration files
sudo netplan generate
Configure bridges, bonds, and VLANs with Netplan.
Advanced Configurations:
# Bridge configuration
network:
version: 2
renderer: networkd
bridges:
br0:
interfaces: [eth0]
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
# Bond configuration
network:
version: 2
bonds:
bond0:
interfaces: [eth0, eth1]
parameters:
mode: 802.3ad
lacp-rate: fast
# VLAN configuration
network:
version: 2
vlans:
vlan100:
id: 100
link: eth0
addresses: [192.168.100.100/24]
Practical Network Configuration Examples
Real-World Network Configuration Scenarios
# 1. Basic Static IP Configuration
# Debian/Ubuntu - /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
dns-search example.com
# Red Hat/CentOS - /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DOMAIN=example.com
# 2. NetworkManager - Static IP
sudo nmcli connection add type ethernet con-name "static-eth0" \
ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1
sudo nmcli connection modify "static-eth0" ipv4.dns "8.8.8.8,8.8.4.4"
sudo nmcli connection modify "static-eth0" ipv4.dns-search "example.com"
sudo nmcli connection up "static-eth0"
# 3. systemd-networkd - Static IP
# /etc/systemd/network/10-eth0.network
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4
Domains=example.com
# Enable and start
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
# 4. Netplan - Static IP (Ubuntu)
# /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
search: [example.com]
sudo netplan apply
# 5. Multiple IP Addresses on Single Interface
# Debian/Ubuntu - /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
auto eth0:0
iface eth0:0 inet static
address 192.168.1.101
netmask 255.255.255.0
# NetworkManager
sudo nmcli connection modify "static-eth0" +ipv4.addresses "192.168.1.101/24"
# systemd-networkd
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Address=192.168.1.101/24
Gateway=192.168.1.1
# 6. Bridge Configuration Examples
# Debian/Ubuntu Bridge
auto br0
iface br0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# NetworkManager Bridge
sudo nmcli connection add type bridge con-name br0 ifname br0
sudo nmcli connection modify br0 ipv4.addresses 192.168.1.100/24
sudo nmcli connection modify br0 ipv4.gateway 192.168.1.1
sudo nmcli connection modify br0 ipv4.method manual
sudo nmcli connection add type ethernet con-name br0-slave ifname eth0 master br0
# 7. Bonding Configuration
# NetworkManager Bond
sudo nmcli connection add type bond con-name bond0 ifname bond0 \
bond.options "mode=active-backup,miimon=100"
sudo nmcli connection add type ethernet con-name bond0-slave1 ifname eth0 master bond0
sudo nmcli connection add type ethernet con-name bond0-slave2 ifname eth1 master bond0
sudo nmcli connection modify bond0 ipv4.addresses 192.168.1.100/24
sudo nmcli connection modify bond0 ipv4.gateway 192.168.1.1
sudo nmcli connection modify bond0 ipv4.method manual
# 8. VLAN Configuration
# NetworkManager VLAN
sudo nmcli connection add type vlan con-name vlan100 ifname vlan100 \
dev eth0 id 100
sudo nmcli connection modify vlan100 ipv4.addresses 192.168.100.100/24
sudo nmcli connection modify vlan100 ipv4.method manual
# 9. Wireless Configuration
# NetworkManager WiFi
sudo nmcli device wifi list
sudo nmcli device wifi connect "MySSID" password "mypassword"
# Persistent WiFi configuration
sudo nmcli connection add type wifi con-name "MyWiFi" \
ifname wlan0 ssid "MySSID"
sudo nmcli connection modify "MyWiFi" wifi-sec.key-mgmt wpa-psk
sudo nmcli connection modify "MyWiFi" wifi-sec.psk "mypassword"
# 10. DNS Configuration Scenarios
# Static DNS in /etc/resolv.conf (not recommended - use below methods)
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com local
# NetworkManager DNS
sudo nmcli connection modify "static-eth0" ipv4.dns "8.8.8.8,8.8.4.4"
sudo nmcli connection modify "static-eth0" ipv4.dns-search "example.com,local"
# systemd-resolved configuration
# /etc/systemd/resolved.conf
[Resolve]
DNS=8.8.8.8 8.8.4.4
Domains=example.com
FallbackDNS=1.1.1.1 1.0.0.1
# 11. Hostname Configuration
# Temporary hostname
sudo hostname new-hostname
# Permanent hostname
echo "new-hostname" | sudo tee /etc/hostname
sudo hostnamectl set-hostname new-hostname
# Update /etc/hosts
127.0.0.1 localhost localhost.localdomain
192.168.1.100 new-hostname.example.com new-hostname
# 12. Routing Configuration
# Add static route
sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0
# Persistent routes - Debian/Ubuntu
# /etc/network/interfaces
up ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0
# Persistent routes - Red Hat/CentOS
# /etc/sysconfig/network-scripts/route-eth0
10.0.0.0/8 via 192.168.1.254 dev eth0
# 13. Network Troubleshooting Commands
# Check interface status
ip addr show
ip link show
# Check routing table
ip route show
route -n
# Check DNS resolution
nslookup google.com
dig google.com
# Check network connectivity
ping -c 4 8.8.8.8
ping -c 4 google.com
# Check listening ports
ss -tuln
netstat -tuln
# Check network statistics
ip -s link
netstat -i
# 14. Network Service Management
# Traditional Debian/Ubuntu
sudo systemctl restart networking
# Traditional Red Hat/CentOS
sudo systemctl restart network
# NetworkManager
sudo systemctl restart NetworkManager
# systemd-networkd
sudo systemctl restart systemd-networkd
# 15. Security Hardening
# Disable unused network services
sudo systemctl disable bluetooth
sudo systemctl stop bluetooth
# Configure firewall
sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
# Or use iptables directly
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -j DROP
Common Use Cases
Server Environments
- Static IP Configuration: Reliable network configuration for servers
- Multiple Interfaces: Separate management and data networks
- Bonding: Network redundancy and increased bandwidth
- VLANs: Network segmentation for security
Cloud & Virtualization
- Bridged Networking: Virtual machines with direct network access
- NAT Configuration: Isolated virtual networks
- Cloud-init: Automated network configuration in cloud environments
- Container Networking: Network namespaces and virtual interfaces
Development & Testing
- Multiple IPs: Testing different network configurations
- Network Isolation: Creating test environments
- DNS Configuration: Local development domains
- Proxy Settings: Development behind corporate firewalls
Advanced Network Configuration
Network Security
Secure network configuration and hardening.
Security Measures:
- Configure firewalls (iptables, ufw, firewalld)
- Use SSH key authentication
- Disable unused network services
- Implement VPN for remote access
Example:
# Basic ufw configuration
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw enable
Network Monitoring
Monitor network performance and troubleshoot issues.
Monitoring Tools:
iftop- Bandwidth monitoringnethogs- Process bandwidth usagetcpdump- Packet capturenetstat- Network statistics
Usage:
# Monitor bandwidth by interface
sudo iftop -i eth0
# Monitor bandwidth by process
sudo nethogs eth0
# Capture packets
sudo tcpdump -i eth0 -w capture.pcap
Performance Tuning
Optimize network performance for specific use cases.
Tuning Parameters:
- TCP buffer sizes
- Interface MTU settings
- Interrupt coalescing
- Queue disciplines
Examples:
# Increase TCP buffer sizes
echo 'net.core.rmem_max = 16777216' >> /etc/sysctl.conf
echo 'net.core.wmem_max = 16777216' >> /etc/sysctl.conf
sysctl -p
• Always backup network configuration files before making changes
• Test network changes in non-production environments first
• Be cautious when changing network configurations remotely - you may lose connectivity
• Understand the difference between temporary and permanent network changes
• Keep network configuration files in version control for reproducibility
• Document network configurations for troubleshooting and recovery
• Consider using configuration management tools for complex environments
• Regularly review and update network security configurations
• Use
ip addr show instead of deprecated ifconfig• Use
ss instead of netstat for better performance• Test both IP and hostname connectivity to diagnose DNS issues
• Use
mtr instead of traceroute for continuous route monitoring• Configure network bonding for redundancy in server environments
• Use VLANs to segment network traffic for security
• Implement network monitoring and alerting for production systems
• Use configuration management (Ansible, Puppet) for consistent network configurations
Key Takeaways
Mastering Linux network configuration is essential for system administrators, DevOps engineers, and network professionals. Understanding the different configuration systems - from traditional files to modern managers like NetworkManager, systemd-networkd, and Netplan - allows you to work effectively across various Linux distributions and environments. Remember that network configuration involves not just IP addresses and DNS, but also routing, security, performance tuning, and troubleshooting. Whether you're managing a single server or an entire data center, these skills ensure reliable, secure, and performant network connectivity.
Next Step: Explore advanced networking topics like network namespaces, software-defined networking (SDN), container networking, and network automation with tools like Ansible and Terraform.