Static IP Configuration on Linux: Complete Guide for Netplan, NetworkManager, and ifupdown
Introduction
Configuring a static IP address on Linux servers is a fundamental skill for system administrators and DevOps engineers. Unlike dynamic IP addresses assigned by DHCP servers, static IP addresses remain constant, making them essential for servers, network infrastructure, and services that require predictable network addressing. Whether you're setting up a web server, database cluster, or network appliance, understanding how to configure static IP addresses across different Linux distributions is crucial for maintaining reliable and secure network connectivity.
This comprehensive guide covers static IP configuration across three major network management systems used in modern Linux distributions: Netplan (Ubuntu 18.04+), NetworkManager (RHEL, CentOS, Fedora), and the traditional ifupdown system (Debian). By mastering these configuration methods, you'll be equipped to handle network configuration on virtually any Linux distribution.
Why Use Static IP Addresses?
Static IP addresses offer several advantages for server environments:
- Predictability: Services always bind to the same IP address, simplifying DNS configuration and firewall rules
- Remote Access: Consistent IP addresses make SSH access and remote administration reliable
- Network Services: Essential for servers hosting DNS, email, web services, and databases
- Service Dependencies: Applications expecting specific IP addresses function correctly
- Monitoring and Logging: Simplified tracking and correlation of network activity
- Reduced DHCP Dependencies: Eliminates reliance on DHCP server availability
Prerequisites
Before configuring static IP addresses on your Linux system, ensure you have:
- Root or sudo access to the target Linux server
- Basic understanding of networking concepts (IP addresses, subnet masks, gateways)
- SSH access to the server (if configuring remotely)
- Backup of current network configuration files
- Valid IP address, subnet mask, gateway, and DNS server information
- Knowledge of your network interface name (eth0, ens33, enp0s3, etc.)
Checking Your Current Network Configuration
Before making changes, document your current network settings:
# View all network interfaces
ip addr show
# Display current routing table
ip route show
# Check DNS configuration
cat /etc/resolv.conf
# View current network connections
ss -tuln
Static IP Configuration with Netplan (Ubuntu 18.04+ and Derivatives)
Netplan is the default network configuration tool for Ubuntu 18.04 and later versions. It uses YAML configuration files to define network settings, which are then applied through underlying renderers like systemd-networkd or NetworkManager.
Understanding Netplan Architecture
Netplan acts as a network configuration abstraction layer, translating YAML files into configuration for backend renderers. This approach provides a consistent configuration experience across different Ubuntu versions and derivatives.
Step-by-Step Netplan Configuration
Step 1: Identify Network Interface
First, identify your network interface name:
ip link show
Common interface names include:
ens33,ens18- VMware and VirtualBoxenp0s3,enp0s8- Physical serverseth0,eth1- Older naming convention
Step 2: Backup Existing Configuration
Always create a backup before modifying network configuration:
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.backup
Step 3: Edit Netplan Configuration
Netplan configuration files are located in /etc/netplan/. Edit the main configuration file:
sudo nano /etc/netplan/00-installer-config.yaml
Replace the contents with your static IP configuration:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Configuration breakdown:
network.version: 2- Specifies Netplan version 2 syntaxrenderer: networkd- Uses systemd-networkd as the backend (alternative: NetworkManager)dhcp4: no- Disables DHCP for IPv4addresses- Static IP address with CIDR notation (/24 = 255.255.255.0)routes- Default gateway configurationnameservers- DNS server addresses
Step 4: Validate Configuration Syntax
Before applying changes, validate the YAML syntax:
sudo netplan --debug generate
If no errors appear, the syntax is correct.
Step 5: Apply Configuration
Apply the new network configuration:
sudo netplan apply
For testing purposes, you can try the configuration with automatic rollback:
sudo netplan try
This command waits for confirmation before permanently applying changes, reverting automatically after 120 seconds if not confirmed.
Advanced Netplan Configurations
Multiple IP Addresses
Configure multiple IP addresses on a single interface:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.100/24
- 192.168.1.101/24
- 192.168.1.102/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Static Routes
Add custom static routes:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
- to: 10.10.0.0/16
via: 192.168.1.254
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
Bond Interface Configuration
Configure network bonding for redundancy:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
ens34:
dhcp4: no
bonds:
bond0:
dhcp4: no
interfaces:
- ens33
- ens34
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
parameters:
mode: active-backup
primary: ens33
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Static IP Configuration with NetworkManager (RHEL, CentOS, Rocky Linux, Fedora)
NetworkManager is the default network configuration system for Red Hat-based distributions. It provides both command-line (nmcli) and text-based UI (nmtui) tools for network configuration.
Using nmcli (Command-Line Interface)
The nmcli tool offers powerful command-line network configuration capabilities.
Step 1: List Network Connections
View existing network connections:
nmcli connection show
Identify your connection name (e.g., "System eth0" or "Wired connection 1").
Step 2: Configure Static IP with nmcli
Configure static IP addressing:
# Set static IPv4 address
sudo nmcli connection modify "System eth0" ipv4.addresses 192.168.1.100/24
# Set gateway
sudo nmcli connection modify "System eth0" ipv4.gateway 192.168.1.1
# Set DNS servers
sudo nmcli connection modify "System eth0" ipv4.dns "8.8.8.8 8.8.4.4"
# Change from auto (DHCP) to manual
sudo nmcli connection modify "System eth0" ipv4.method manual
# Bring the connection down and up to apply changes
sudo nmcli connection down "System eth0"
sudo nmcli connection up "System eth0"
Step 3: Verify Configuration
Confirm the configuration:
nmcli connection show "System eth0"
ip addr show
Using nmtui (Text User Interface)
For those who prefer a text-based graphical interface:
sudo nmtui
Navigate through the interface:
- Select "Edit a connection"
- Choose your network interface
- Select "IPv4 CONFIGURATION" and change to "Manual"
- Add your IP address, gateway, and DNS servers
- Select "OK" and then "Activate a connection" to apply
Using Configuration Files Directly
NetworkManager stores connection profiles in /etc/NetworkManager/system-connections/ (RHEL 8+) or uses ifcfg files in /etc/sysconfig/network-scripts/ (RHEL 7).
For RHEL 7 and CentOS 7 (ifcfg files):
Edit the interface configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
Configure static IP:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
Restart networking:
sudo systemctl restart network
# Or for newer systems:
sudo nmcli connection reload
sudo nmcli connection up eth0
Static IP Configuration with ifupdown (Debian Traditional Method)
The traditional Debian networking system uses /etc/network/interfaces for configuration. While Debian 10+ often uses NetworkManager by default, many server installations still use ifupdown.
Step 1: Edit Interfaces Configuration
Edit the main network configuration file:
sudo nano /etc/network/interfaces
Step 2: Configure Static IP
Replace DHCP configuration with static settings:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
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
Alternative CIDR notation (Debian 10+):
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.4
Step 3: Configure DNS Resolution
Edit DNS configuration:
sudo nano /etc/resolv.conf
Add DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
To prevent DHCP from overwriting /etc/resolv.conf:
sudo chattr +i /etc/resolv.conf
Step 4: Restart Networking
Apply the configuration:
sudo systemctl restart networking
# Or
sudo ifdown eth0 && sudo ifup eth0
Advanced ifupdown Configurations
Multiple IP Addresses (IP Aliasing)
Configure additional IP addresses:
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
auto eth0:1
iface eth0:1 inet static
address 192.168.1.102
netmask 255.255.255.0
Static Routes
Add custom routing:
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
# Static route to 10.0.0.0/8 network
up ip route add 10.0.0.0/8 via 192.168.1.254
down ip route del 10.0.0.0/8 via 192.168.1.254
Verification and Testing
After configuring static IP addresses, thoroughly test your network configuration.
Basic Connectivity Tests
Verify IP Address Assignment
ip addr show
# Or older command
ifconfig
Look for your configured IP address on the correct interface.
Check Routing Table
ip route show
# Verify default gateway
ip route | grep default
Test Gateway Connectivity
ping -c 4 192.168.1.1
Test DNS Resolution
# Check DNS servers
cat /etc/resolv.conf
# Test DNS resolution
nslookup google.com
dig google.com
# Test with specific DNS server
nslookup google.com 8.8.8.8
Test Internet Connectivity
ping -c 4 8.8.8.8
ping -c 4 google.com
Advanced Network Testing
Check Network Interface Status
ip link show eth0
# Look for "state UP"
Test Network Performance
# Download speed test
wget -O /dev/null http://speedtest.tele2.net/100MB.zip
# MTU path discovery
ping -M do -s 1472 192.168.1.1
Verify Service Binding
# Check which services are listening
ss -tuln
netstat -tuln
# Check specific port
ss -tuln | grep :80
Troubleshooting Common Issues
Issue 1: Network Interface Not Coming Up
Symptoms: Interface shows "DOWN" state
Solutions:
# Check interface status
ip link show
# Bring interface up manually
sudo ip link set eth0 up
# For Netplan
sudo netplan apply
# For NetworkManager
sudo nmcli connection up "System eth0"
# For ifupdown
sudo ifup eth0
Issue 2: No Route to Gateway
Symptoms: Cannot ping gateway
Diagnosis:
ip route show
Solutions:
# Add default gateway manually
sudo ip route add default via 192.168.1.1
# Make permanent by updating configuration files
Issue 3: DNS Resolution Failure
Symptoms: Can ping IP addresses but not domain names
Diagnosis:
cat /etc/resolv.conf
nslookup google.com
Solutions:
# Update DNS servers in /etc/resolv.conf
sudo nano /etc/resolv.conf
# Add nameservers
nameserver 8.8.8.8
nameserver 1.1.1.1
# For systemd-resolved systems
sudo systemctl restart systemd-resolved
Issue 4: Configuration Not Persisting After Reboot
Symptoms: Static IP works until reboot
Solutions:
For Netplan:
# Verify configuration file
ls -la /etc/netplan/
sudo netplan apply
For NetworkManager:
# Ensure connection starts on boot
sudo nmcli connection modify "System eth0" connection.autoconnect yes
For ifupdown:
# Verify "auto" directive in /etc/network/interfaces
auto eth0
Issue 5: Conflicting IP Address
Symptoms: Network intermittently disconnects or shows duplicate IP warnings
Diagnosis:
# Check for IP conflicts
sudo arping -D -I eth0 192.168.1.100
Solutions:
- Verify no other device uses the same IP address
- Use a different IP address from the available pool
- Configure DHCP server to exclude static IP range
Issue 6: Netplan YAML Syntax Errors
Symptoms: "netplan apply" fails with syntax errors
Solutions:
# Validate YAML syntax
sudo netplan --debug generate
# Common issues:
# - Incorrect indentation (use spaces, not tabs)
# - Missing colons after keys
# - Incorrect array syntax
Proper indentation example:
network:
version: 2
ethernets:
ens33:
addresses:
- 192.168.1.100/24 # Note: 2 space indent for array items
Best Practices for Static IP Configuration
1. IP Address Planning and Documentation
- Maintain an IP address management (IPAM) spreadsheet or database
- Reserve IP ranges for static assignments (e.g., .100-.200)
- Use DHCP for dynamic assignments outside static range
- Document all static IP assignments with hostname, purpose, and assignment date
2. Network Configuration Backups
Always backup configuration before changes:
# Netplan backup
sudo cp /etc/netplan/*.yaml /root/netplan-backup/
# NetworkManager backup
sudo cp /etc/NetworkManager/system-connections/* /root/nm-backup/
sudo cp /etc/sysconfig/network-scripts/ifcfg-* /root/ifcfg-backup/
# ifupdown backup
sudo cp /etc/network/interfaces /etc/network/interfaces.backup
3. Use Configuration Management
For managing multiple servers, use configuration management tools:
- Ansible playbooks for network configuration
- Puppet or Chef recipes
- Salt states
- Version control for configuration files (Git)
4. DNS Best Practices
- Configure at least two DNS servers for redundancy
- Use reliable DNS providers (Google: 8.8.8.8, Cloudflare: 1.1.1.1)
- Consider internal DNS servers for corporate environments
- Set appropriate DNS search domains
5. Security Considerations
# Disable unused network interfaces
sudo ip link set eth1 down
# Configure firewall rules for static IP
sudo ufw allow from 192.168.1.0/24 to any port 22
# Restrict SSH to specific IPs in /etc/ssh/sshd_config
ListenAddress 192.168.1.100
6. Testing Procedures
Establish a testing checklist:
- Verify IP address assignment
- Test gateway connectivity
- Confirm DNS resolution
- Check Internet connectivity
- Verify service accessibility
- Test after server reboot
- Monitor for IP conflicts
7. Remote Configuration Safety
When configuring remotely via SSH:
# Use screen or tmux to prevent disconnection
screen
# For Netplan, use "netplan try" for automatic rollback
sudo netplan try
# Set up console/IPMI access before making changes
# Keep current SSH session open until verification
8. Monitoring and Alerts
Set up monitoring for network interface status:
# Create monitoring script
cat << 'EOF' | sudo tee /usr/local/bin/check_network.sh
#!/bin/bash
INTERFACE="eth0"
if ! ip link show $INTERFACE | grep -q "state UP"; then
echo "Network interface $INTERFACE is down!" | mail -s "Network Alert" [email protected]
fi
EOF
sudo chmod +x /usr/local/bin/check_network.sh
# Add to crontab
echo "*/5 * * * * /usr/local/bin/check_network.sh" | sudo crontab -
Performance Optimization
MTU Configuration
Optimize Maximum Transmission Unit for your network:
Netplan:
network:
version: 2
ethernets:
ens33:
mtu: 9000
addresses: [192.168.1.100/24]
NetworkManager:
sudo nmcli connection modify "System eth0" 802-3-ethernet.mtu 9000
ifupdown:
iface eth0 inet static
mtu 9000
Network Interface Queue Length
Increase transmit queue length for high-traffic servers:
sudo ip link set eth0 txqueuelen 10000
Make permanent by adding to network configuration or rc.local.
Security Considerations
1. Firewall Configuration
After setting static IP, configure firewall rules:
# UFW (Ubuntu)
sudo ufw allow from 192.168.1.0/24 to 192.168.1.100 port 22
sudo ufw enable
# firewalld (RHEL/CentOS)
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="22" protocol="tcp" accept'
sudo firewall-cmd --reload
2. Network Segmentation
Place servers in appropriate network segments:
- DMZ for public-facing servers
- Internal network for databases and application servers
- Management network for administrative access
3. Disable IPv6 if Not Used
If IPv6 is not required:
Netplan:
network:
version: 2
ethernets:
ens33:
dhcp6: no
accept-ra: no
Sysctl:
sudo nano /etc/sysctl.conf
# Add:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
sudo sysctl -p
4. MAC Address Filtering
For sensitive environments, consider MAC address filtering at the switch level and documentation:
# View MAC address
ip link show eth0 | grep link/ether
Conclusion
Configuring static IP addresses on Linux is a fundamental networking skill that every system administrator must master. Whether you're working with modern Ubuntu systems using Netplan, Red Hat-based distributions with NetworkManager, or traditional Debian systems with ifupdown, understanding the nuances of each approach ensures reliable network configuration across diverse environments.
Key takeaways from this guide:
- Netplan provides a modern, YAML-based configuration approach for Ubuntu and derivatives
- NetworkManager offers powerful CLI and TUI tools for Red Hat-based systems
- ifupdown remains relevant for traditional Debian server deployments
- Always backup configurations before making changes
- Thoroughly test after configuration changes, especially before rebooting
- Implement monitoring and documentation practices
- Consider security implications of static IP assignments
By following the best practices outlined in this guide, you'll maintain stable, secure, and well-documented network configurations that form the foundation of reliable server infrastructure. Remember to adapt these configurations to your specific network environment and always test changes in a non-production environment when possible.
For ongoing learning, explore advanced topics such as network bonding, VLANs, and software-defined networking to further enhance your Linux networking expertise.


