Introduction
Netplan is the default network configuration tool for Ubuntu Server 18.04 and newer. It uses YAML configuration files to manage network interfaces, replacing the older /etc/network/interfaces method.
Static IP addresses are essential for servers to ensure they’re always reachable at the same address, which is critical for services like web servers, databases, and SSH access.
What you’ll learn:
- Check current network configuration
- Configure static IP with Netplan
- Handle cloud-init network configuration
- Test and apply Netplan changes safely
- Troubleshoot common networking issues
When to use static IPs:
- Servers (web, database, file servers)
- Infrastructure services (DNS, DHCP)
- Remote access (SSH, RDP)
- Docker hosts
- Any service that needs a consistent IP
Prerequisites
- Ubuntu Server (18.04 LTS or newer)
- sudo/root access
- Network information:
- Desired static IP address (e.g.,
192.168.1.110) - Subnet mask / CIDR notation (e.g.,
/24for 255.255.255.0) - Gateway IP (usually your router, e.g.,
192.168.1.1) - DNS servers (e.g.,
8.8.8.8, 8.8.4.4)
- Desired static IP address (e.g.,
- Physical or console access recommended (in case network connection is lost)
Part 1: Check Current Network Configuration
Step 1: Find Your Network Interface Name
ip a
Example output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether bc:24:11:2e:7f:90 brd ff:ff:ff:ff:ff:ff
altname enp0s18
inet 192.168.1.81/24 brd 192.168.1.255 scope global dynamic ens18
Key information:
- Interface name:
ens18(yours may be different:eth0,enp0s3, etc.) - Current IP:
192.168.1.81 - Subnet:
/24(255.255.255.0)
Step 2: Check Current Gateway
ip route show
Example output:
default via 192.168.1.1 dev ens18 proto dhcp src 192.168.1.81 metric 100
192.168.1.0/24 dev ens18 proto kernel scope link src 192.168.1.81
Key information:
- Gateway:
192.168.1.1(theviaaddress on the default route)
Step 3: Check Current DNS Servers
resolvectl status
Or:
cat /etc/resolv.conf
Example output:
nameserver 192.168.1.1
nameserver 8.8.8.8
Part 2: Locate Netplan Configuration Files
Check for Existing Netplan Files
ls -la /etc/netplan/
Common configurations:
Cloud-init setup (Proxmox VMs, cloud providers):
/etc/netplan/50-cloud-init.yaml
Standard setup (manual installations):
/etc/netplan/00-installer-config.yaml
/etc/netplan/01-netcfg.yaml
Determine Configuration Type
If you see 50-cloud-init.yaml:
- Your system uses cloud-init for network configuration
- Follow Method A: Cloud-Init Configuration below
If you see 00-installer-config.yaml or similar:
- Standard Netplan configuration
- Follow Method B: Standard Netplan Configuration below
Part 3: Configure Static IP
Method A: Cloud-Init Configuration (Proxmox VMs)
Cloud-init configurations require special handling to prevent cloud-init from overwriting your changes.
Step 1: Backup Existing Configuration
sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.backup
Step 2: View Current Configuration
cat /etc/netplan/50-cloud-init.yaml
Example current content:
network:
version: 2
ethernets:
ens18:
dhcp4: true
Step 3: Edit Cloud-Init Configuration
sudo nano /etc/netplan/50-cloud-init.yaml
Replace with static IP configuration:
network:
version: 2
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.1.110/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Customize these values:
ens18: Your actual interface name (fromip a)192.168.1.110/24: Your desired IP and subnet192.168.1.1: Your gateway IP8.8.8.8, 8.8.4.4: Your DNS servers (Google DNS shown here)
Save and exit (Ctrl+X, Y, Enter in nano).
Step 4: Prevent Cloud-Init from Overwriting
Create a cloud-init configuration to disable network management:
sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Add this content:
network: {config: disabled}
Save and exit.
This tells cloud-init to not manage network configuration.
Method B: Standard Netplan Configuration
Step 1: Backup Existing Configuration
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.backup
(Adjust filename to match your actual config file)
Step 2: Edit Netplan Configuration
sudo nano /etc/netplan/00-installer-config.yaml
Replace with static IP configuration:
network:
version: 2
renderer: networkd
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.1.110/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Save and exit.
Part 4: Test and Apply Configuration
Step 1: Validate Netplan Syntax
Before applying, check for YAML syntax errors:
sudo netplan generate
If successful, no output is shown.
If there are errors:
Error in network definition: invalid YAML at /etc/netplan/50-cloud-init.yaml line 5 column 6
Fix syntax errors (usually indentation issues in YAML) and run netplan generate again.
Step 2: Test Configuration (Recommended)
sudo netplan try
What this does:
- Applies the configuration temporarily
- Waits 120 seconds for confirmation
- Automatically reverts if you don’t confirm
Expected output:
Warning: Stopping systemd-networkd.service, but it can still be activated by:
systemd-networkd.socket
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 120 seconds
Test the connection:
Open a new SSH session to the new IP address:
If the new IP works, press Enter in the original terminal to accept changes
If it doesn’t work, wait 120 seconds for automatic revert, or press Ctrl+C to cancel immediately
Step 3: Apply Configuration Permanently
If netplan try worked, or if you’re confident in your configuration:
sudo netplan apply
Expected output:
(No output means success)
Part 5: Verify Configuration
Check IP Address
ip a show ens18
Expected output:
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 192.168.1.110/24 brd 192.168.1.255 scope global ens18
Verify the IP address matches your configuration.
Check Gateway
ip route show
Expected output:
default via 192.168.1.1 dev ens18 proto static
192.168.1.0/24 dev ens18 proto kernel scope link src 192.168.1.110
Check DNS
resolvectl status
Expected output:
Link 2 (ens18)
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8
8.8.4.4
Test Internet Connectivity
ping -c 4 8.8.8.8
Test DNS resolution:
ping -c 4 google.com
Both should work.
Troubleshooting
No Network After Applying Configuration
Cause: Syntax error or wrong configuration values
Solution:
Via console (Proxmox GUI, physical access, or KVM):
# Restore backup sudo cp /etc/netplan/50-cloud-init.yaml.backup /etc/netplan/50-cloud-init.yaml # Apply original configuration sudo netplan applyCheck syntax:
sudo netplan generateFix errors and try again
DNS Not Working
Cause: DNS servers not configured or unreachable
Solution:
# Test if DNS servers are reachable
ping -c 2 8.8.8.8
# If not, use your router as DNS
sudo nano /etc/netplan/50-cloud-init.yaml
# Change nameservers to:
nameservers:
addresses:
- 192.168.1.1 # Your router
Apply changes:
sudo netplan apply
Cannot Reach Gateway
Cause: Wrong gateway IP or subnet mismatch
Solution:
- Verify gateway IP (should be your router’s IP)
- Verify subnet matches your network (usually
/24) - Example: If your IP is
192.168.1.110/24, gateway should be192.168.1.1(or another IP in192.168.1.0/24range)
Changes Don’t Apply / Cloud-Init Overwrites
Cause: Cloud-init managing network configuration
Solution:
Disable cloud-init network management:
sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Add:
network: {config: disabled}
Reboot:
sudo reboot
netplan try Times Out
Cause: Lost network connectivity during test
Solution:
Wait 120 seconds for automatic revert, or use console access to restore backup configuration.
Advanced Configuration Examples
Multiple IP Addresses
network:
version: 2
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.1.110/24 # Primary IP
- 192.168.1.111/24 # Secondary IP
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
IPv6 Configuration
network:
version: 2
ethernets:
ens18:
dhcp4: no
dhcp6: no
addresses:
- 192.168.1.110/24
- 2001:db8::10/64
routes:
- to: default
via: 192.168.1.1
- to: default
via: 2001:db8::1
nameservers:
addresses:
- 8.8.8.8
- 2001:4860:4860::8888 # Google IPv6 DNS
Custom DNS Search Domain
network:
version: 2
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.1.110/24
routes:
- to: default
via: 192.168.1.1
nameservers:
search: [local.lan, home.local]
addresses: [192.168.1.1, 8.8.8.8]
Best Practices
- Always backup configuration files before editing
- Use
netplan tryto test changes safely - Document your IP scheme (spreadsheet of assigned IPs)
- Use DHCP reservations instead of static IPs when possible (configure on router)
- Keep DNS consistent across all servers
- Test after every change:
- IP connectivity
- Gateway reachability
- DNS resolution
- Internet access
Next Steps
Now that you have a static IP configured:
- Update SSH config on your local machine with the new IP
- Update firewall rules if using UFW
- Configure services (web server, database) to use the static IP
- Set up reverse DNS if needed (PTR records)
- Document the IP assignment in your network inventory
Related Guides
- How to Create a VM in Proxmox
- How to Set Up SSH on Ubuntu Server
- How to Install Docker on Ubuntu Server
Last updated: November 2025