Mastering Configuration Settings: A Comprehensive Guide to Setup, Best Practices, and Examples
Network configuration settings are the backbone of any Linux system, defining how it communicates with other devices, accesses the internet, and manages network resources. Whether you're setting up a static IP for a server, configuring DNS resolution, or troubleshooting connectivity issues, understanding Linux network configuration is essential for system administrators, DevOps engineers, and developers.
This guide dives deep into Linux network configuration settings: what they are, where they live, how to view and modify them, and best practices to ensure your systems remain connected, secure, and easy to maintain. We cover modern tools like ip, nmcli, netplan, and systemd-networkd, as well as legacy approaches still in use today.
Table of Contents#
- What Are Network Configuration Settings?
- Viewing Current Network Settings
- Network Configuration Methods
- Configuring with ip Commands
- Configuring with NetworkManager (nmcli)
- Configuring with Netplan (Ubuntu)
- Configuring with systemd-networkd
- Legacy Configuration: /etc/network/interfaces
- DNS Configuration Settings
- Routing Configuration
- Advanced Settings: Bonding, Bridges, and VLANs
- Best Practices for Network Configuration
- Troubleshooting Network Settings
- Conclusion
- References
What Are Network Configuration Settings?#
Network configuration settings control how a Linux system interacts with networks. These settings include:
- IP addresses: Unique identifiers for network interfaces (e.g.,
192.168.1.10/24) - Default gateway: The router that forwards traffic to other networks (e.g.,
192.168.1.1) - DNS servers: Servers that resolve domain names to IP addresses (e.g.,
8.8.8.8) - Interface states: Whether a network interface is up or down
- Routes: Rules that determine where network traffic is directed
- MTU (Maximum Transmission Unit): The largest packet size allowed on the interface
Why Network Configuration Matters#
- Connectivity: Proper settings ensure your system can reach other hosts and the internet.
- Security: Correct firewall rules and DNS settings protect against threats.
- Performance: Optimized MTU, routing, and bonding settings improve throughput.
- Reliability: Redundant configurations (bonding, multiple DNS servers) prevent downtime.
- Manageability: Consistent, documented settings simplify troubleshooting and scaling.
Viewing Current Network Settings#
Before making changes, always inspect your current configuration.
Using ip Commands#
The ip command (from the iproute2 package) is the modern standard for viewing and configuring network settings.
# List all network interfaces with IP addresses
ip addr show
ip a # Short form
# Show a specific interface
ip addr show eth0
# Display the routing table
ip route show
ip r # Short form
# Show link-layer information (MAC addresses, states)
ip link show
# Display interface statistics (packet counts, errors)
ip -s link show eth0Viewing DNS Settings#
# Show DNS resolver configuration
resolvectl status
# View the resolv.conf file
cat /etc/resolv.conf
# Query a specific DNS server
dig @8.8.8.8 example.com
nslookup example.comChecking Active Connections#
# Show listening TCP and UDP ports
ss -tuln
# Show established connections
ss -tun
# Display connection statistics
ss -sNetwork Configuration Methods#
Linux distributions use different tools for network configuration. The method you use depends on your distribution and environment.
| Tool | Primary Use | Distributions |
|---|---|---|
ip command | Temporary changes, troubleshooting | All Linux |
NetworkManager (nmcli, nmtui) | Desktops, laptops, RHEL/Fedora | RHEL, Fedora, CentOS, Ubuntu Desktop |
| Netplan | Server and desktop config | Ubuntu 17.10+, Debian 10+ |
| systemd-networkd | Servers, minimal installs | Arch, Ubuntu Server, container hosts |
/etc/network/interfaces | Legacy Debian/Ubuntu config | Older Debian/Ubuntu systems |
/etc/sysconfig/network-scripts/ | Legacy RHEL/CentOS config | RHEL 7 and older |
Configuring with ip Commands#
The ip command makes immediate changes that are lost on reboot. Use it for testing or temporary fixes.
Managing Interface State#
# Bring an interface up
sudo ip link set eth0 up
# Bring an interface down
sudo ip link set eth0 downAssigning IP Addresses#
# Add an IP address to an interface
sudo ip addr add 192.168.1.100/24 dev eth0
# Add a secondary IP address
sudo ip addr add 192.168.1.101/24 dev eth0
# Remove an IP address
sudo ip addr del 192.168.1.100/24 dev eth0
# Flush all addresses from an interface
sudo ip addr flush dev eth0Managing Routes#
# Add a default gateway
sudo ip route add default via 192.168.1.1
# Delete the default gateway
sudo ip route del default
# Add a static route to a specific network
sudo ip route add 10.0.0.0/8 via 192.168.1.254
# Show routes for a specific interface
ip route show dev eth0Changing the MAC Address#
sudo ip link set eth0 down
sudo ip link set eth0 address 00:11:22:33:44:55
sudo ip link set eth0 upConfiguring with NetworkManager (nmcli)#
NetworkManager is the default network management tool on RHEL, Fedora, CentOS, and Ubuntu Desktop. The nmcli command-line tool provides full control over connections.
Viewing Connections#
# List all connections
nmcli connection show
# Show active connections
nmcli connection show --active
# List network devices and their states
nmcli device status
# Show detailed info about a connection
nmcli connection show "Wired connection 1"Creating a Static IP Connection#
nmcli connection add \
con-name "static-eth0" \
type ethernet \
ifname eth0 \
ipv4.addresses "192.168.1.100/24" \
ipv4.gateway "192.168.1.1" \
ipv4.dns "8.8.8.8,8.8.4.4" \
ipv4.method manualCreating a DHCP Connection#
nmcli connection add \
con-name "dhcp-eth0" \
type ethernet \
ifname eth0 \
ipv4.method autoModifying Connections#
# Change the IP address
nmcli connection modify "static-eth0" ipv4.addresses "192.168.1.101/24"
# Add a DNS server
nmcli connection modify "static-eth0" +ipv4.dns "1.1.1.1"
# Remove a DNS server
nmcli connection modify "static-eth0" -ipv4.dns "8.8.4.4"
# Change the gateway
nmcli connection modify "static-eth0" ipv4.gateway "192.168.1.254"Activating and Deactivating Connections#
# Bring up a connection
nmcli connection up "static-eth0"
# Bring down a connection
nmcli connection down "static-eth0"
# Restart a connection
nmcli connection down "static-eth0" && nmcli connection up "static-eth0"Using nmtui (Text User Interface)#
For interactive configuration without memorizing commands:
nmtuiThis launches a menu-driven interface where you can edit connections, activate/deactivate them, and set the system hostname.
Configuring with Netplan (Ubuntu)#
Netplan is the default network configuration tool for Ubuntu 17.10 and later. It uses YAML files in /etc/netplan/ and generates configuration for either systemd-networkd or NetworkManager backends.
Configuration File Location#
ls /etc/netplan/
# Common files: 00-installer-config.yaml, 01-netcfg.yamlStatic IP Configuration#
# /etc/netplan/01-static.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search:
- example.com
mtu: 1500DHCP Configuration#
# /etc/netplan/01-dhcp.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
dhcp6: false
dhcp4-overrides:
use-dns: true
use-routes: true
route-metric: 100Applying Netplan Configuration#
# Validate the YAML syntax
sudo netplan generate
# Test the configuration (auto-reverts after 120 seconds if not confirmed)
sudo netplan try
# Apply permanently
sudo netplan apply
# Apply with debug output
sudo netplan --debug applyChoosing a Renderer#
- Use
renderer: networkdfor servers (lightweight, no GUI dependencies). - Use
renderer: NetworkManagerfor desktops (supports WiFi, VPNs).
# Check the current renderer
netplan get network.rendererConfiguring with systemd-networkd#
systemd-networkd is a system daemon that manages network configurations. It is the default on Arch Linux and suitable for servers and minimal installations on other distributions.
Configuration Files#
Configuration files are stored in three locations (processed in order):
/usr/lib/systemd/network/— system defaults/run/systemd/network/— runtime configuration/etc/systemd/network/— local administration (highest priority)
Files use three types:
.network— network configuration for matched interfaces.netdev— virtual network device definitions.link— link-layer configuration
Enabling systemd-networkd#
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
# Optional: enable systemd-resolved for DNS
sudo systemctl enable systemd-resolved
sudo systemctl start systemd-resolved
# Link resolv.conf to systemd-resolved
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.confStatic IP Configuration#
# /etc/systemd/network/10-static.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
[Route]
Destination=10.0.0.0/8
Gateway=192.168.1.254DHCP Configuration#
# /etc/systemd/network/20-dhcp.network
[Match]
Name=eth*
[Network]
DHCP=yes
IPv6AcceptRA=yes
[DHCPv4]
UseDNS=yes
UseRoutes=yes
RouteMetric=100Checking Status#
# View network device status
networkctl status
# View specific interface
networkctl status eth0
# Restart after configuration changes
sudo systemctl restart systemd-networkdLegacy Configuration: /etc/network/interfaces#
On older Debian and Ubuntu systems (pre-17.10), network interfaces are configured in /etc/network/interfaces.
Static IP#
# /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.100/24
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4DHCP#
auto eth0
iface eth0 inet dhcpApplying Changes#
# Restart networking service
sudo systemctl restart networking
# Or bring interfaces up/down individually
sudo ifdown eth0 && sudo ifup eth0Migrating from ifupdown to Netplan#
If you're upgrading from an older Ubuntu system:
- Backup the old config:
sudo cp /etc/network/interfaces /etc/network/interfaces.bak - Create a Netplan YAML file in
/etc/netplan/ - Disable the old service:
sudo systemctl mask networking.service - Apply Netplan:
sudo netplan apply
DNS Configuration Settings#
DNS settings determine how your system resolves domain names.
Using systemd-resolved#
On systems with systemd-resolved, DNS is managed centrally:
# View current DNS settings
resolvectl status
# Set DNS for a specific interface
sudo resolvectl dns eth0 8.8.8.8 8.8.4.4
# Set a DNS search domain
sudo resolvectl domain eth0 example.comTraditional /etc/resolv.conf#
# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
options timeout:2 attempts:3Note: On systems using systemd-resolved or NetworkManager, /etc/resolv.conf is often a symlink managed automatically. Edit the upstream configuration instead.
Per-Interface DNS with Netplan#
# /etc/netplan/01-dns.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
nameservers:
addresses:
- 1.1.1.1
- 1.0.0.1
search:
- internal.example.comPer-Interface DNS with systemd-networkd#
# /etc/systemd/network/10-static.network
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
DNS=1.1.1.1
DNS=1.0.0.1
Domains=internal.example.comRouting Configuration#
Routing determines the path network traffic takes to reach its destination.
Viewing Routes#
# Show the routing table
ip route show
# Show routes for a specific interface
ip route show dev eth0
# Show routes to a specific destination
ip route get 8.8.8.8Adding Static Routes#
# Add a route to a specific network via a gateway
sudo ip route add 10.0.0.0/8 via 192.168.1.254
# Add a route with a specific metric
sudo ip route add 10.0.0.0/8 via 192.168.1.254 metric 100Persistent Routes with Netplan#
# /etc/netplan/01-routes.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
- to: 10.0.0.0/8
via: 192.168.1.254
metric: 100Persistent Routes with systemd-networkd#
# /etc/systemd/network/10-static.network
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
[Route]
Destination=10.0.0.0/8
Gateway=192.168.1.254
Metric=100Advanced Settings: Bonding, Bridges, and VLANs#
Network Bonding#
Bonding combines multiple physical interfaces into a single logical interface for redundancy or increased throughput.
Common bonding modes:
| Mode | Name | Description |
|---|---|---|
| 0 | balance-rr | Round-robin load balancing |
| 1 | active-backup | Failover (one active, others standby) |
| 4 | 802.3ad | LACP (requires switch support) |
Netplan example (active-backup):
# /etc/netplan/01-bond.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
eth1:
dhcp4: false
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
parameters:
mode: active-backup
primary: eth0
mii-monitoring-interval: 100Verify bonding status:
cat /proc/net/bonding/bond0Network Bridges#
Bridges connect multiple network segments, commonly used for virtual machines and containers.
Netplan example:
# /etc/netplan/01-bridge.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
bridges:
br0:
interfaces:
- eth0
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
parameters:
stp: true
forward-delay: 4VLAN Configuration#
VLANs segment a physical network into isolated logical networks.
Netplan example:
# /etc/netplan/01-vlan.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
vlans:
vlan100:
id: 100
link: eth0
addresses:
- 10.100.0.10/24
routes:
- to: default
via: 10.100.0.1
vlan200:
id: 200
link: eth0
addresses:
- 10.200.0.10/24Best Practices for Network Configuration#
1. Use Persistent Configuration Tools#
Avoid relying solely on ip commands for production systems. Use Netplan, NetworkManager, or systemd-networkd for settings that survive reboots.
2. Test Before Applying Remotely#
When configuring a remote server, use netplan try instead of netplan apply. The try command automatically reverts changes after 120 seconds if you lose connectivity and cannot confirm.
sudo netplan try3. Backup Configuration Files#
Always back up existing configuration before making changes:
sudo cp /etc/netplan/01-network.yaml /etc/netplan/01-network.yaml.bak4. Use Version Control#
Store network configuration in Git for change tracking and rollback:
cd /etc/netplan/
sudo git init
sudo git add .
sudo git commit -m "Initial network configuration"5. Set Proper File Permissions#
Protect configuration files that contain sensitive information:
sudo chmod 600 /etc/netplan/*.yaml6. Use Consistent Naming#
Name configuration files with numeric prefixes to control processing order:
01-ethernet.yaml
02-wifi.yaml
03-vlans.yaml
7. Document Your Configuration#
Add comments to configuration files explaining the purpose of each setting:
# /etc/netplan/01-static.yaml
# Primary ethernet interface for web server
network:
version: 2
renderer: networkd
ethernets:
eth0:
# Static IP for DNS A record
addresses:
- 192.168.1.100/248. Avoid Storing Secrets in Plain Text#
For WiFi passwords or other secrets, use encrypted storage or proper secret management tools rather than plain-text YAML files.
9. Set Appropriate MTU Values#
Match MTU across the network path to avoid fragmentation:
ethernets:
eth0:
mtu: 1500 # Standard Ethernet
# mtu: 9000 # Jumbo frames (requires switch support)Troubleshooting Network Settings#
Systematic Diagnosis#
Follow this workflow when troubleshooting connectivity issues:
-
Is the interface up?
ip link show eth0 # Look for "state UP" -
Does the interface have an IP address?
ip addr show eth0 -
Can you reach the gateway?
ping -c 3 192.168.1.1 -
Can you reach an external IP (bypassing DNS)?
ping -c 3 8.8.8.8 -
Is DNS resolution working?
nslookup example.com dig example.com
Common Issues and Fixes#
Interface not coming up:
# Check if the network driver is loaded
lspci -k | grep -A 3 -i network
# Check kernel messages for errors
dmesg | grep eth0
# Verify the interface exists
ip link show eth0DHCP not assigning an IP:
# Force DHCP release and renewal
sudo dhclient -r eth0
sudo dhclient eth0
# Check DHCP client logs
journalctl -u dhcpcdDNS not resolving:
# Test with a specific DNS server
dig @8.8.8.8 example.com
# Check if resolv.conf is a symlink
ls -la /etc/resolv.conf
# Verify systemd-resolved is running
systemctl status systemd-resolvedCannot reach external networks:
# Verify a default route exists
ip route | grep default
# Check for firewall rules blocking traffic
sudo iptables -L -n -v
sudo nft list ruleset
# Trace the route to a destination
traceroute 8.8.8.8
mtr 8.8.8.8Duplicate IP address conflict:
# Check for conflicts using ARP
arping -D -I eth0 192.168.1.100Useful Diagnostic Commands#
# Monitor network traffic on an interface
sudo tcpdump -i eth0 -n
# View interface error statistics
ip -s link show eth0
# Check for listening services
ss -tuln
# View NetworkManager logs
journalctl -u NetworkManager -f
# View systemd-networkd logs
journalctl -u systemd-networkd -fConclusion#
Linux network configuration has evolved significantly from the days of editing /etc/network/interfaces by hand. Modern tools like ip, nmcli, netplan, and systemd-networkd provide powerful, flexible ways to manage network settings across different distributions and environments.
Key takeaways:
- Use
ipcommands for quick, temporary changes and troubleshooting. - Use NetworkManager (
nmcli/nmtui) on desktops and RHEL-based systems. - Use Netplan on Ubuntu for declarative YAML-based configuration.
- Use
systemd-networkdon servers and minimal installations. - Always test configuration changes safely, especially on remote systems.
- Back up and version-control your network configuration.
- Follow a systematic approach when troubleshooting connectivity issues.
By mastering these tools and following best practices, you can confidently manage Linux network configurations in any environment—from a single workstation to a fleet of servers.