Ubuntu Server: The Easy Way to Assign a Static IP
This lab shows how to use netplan set for quick, error-free NIC setup, ideal for sysadmins managing servers.

The Goal
To configure a static IP address on an Ubuntu server so that it remains reliably reachable by other systems—whether it's serving files, running applications, or hosting a database.
The Lab
This lab is also available on YouTube
In this setup:
- The server is called
server1
- It has two NICs:
eth0
(already using DHCP)eth1
(to be configured with a static IP)
- The desired IP configuration:
- IP Address:
10.0.10.10/24
- Gateway:
10.0.10.1
- Name Servers:
10.0.10.1
- IP Address:
- Configuration is managed using Ubuntu's
netplan
utility
The Why
Servers that provide persistent services—whether for internal users or other servers—must be reliably addressable. DHCP assigns addresses dynamically, which risks change. Static IPs eliminate that uncertainty and ensure service availability across reboots or network reassignments.
Using a VPN is a secure and simple way to protect your data.
The How
1. Identify the NICs
Run:
ip a
This lists all interfaces and shows which ones are active and which have IPs. In this case, eth0
uses DHCP; eth1
is unconfigured.
2. Review Netplan Files
Netplan stores network settings in YAML format under:
/etc/netplan/
Run:
ls /etc/netplan
View current config:
sudo cat /etc/netplan/<filename>.yaml
The file will show DHCP set to true for eth0
.
3. Set a Static IP Using Netplan’s CLI
Use netplan set
to apply settings without manually editing YAML files. This will create a new yaml file named eth1-net-config.yaml
sudo netplan set ethernets.eth1.addresses=["10.0.10.10/24"] --origin-hint eth1-net-config
Check changes:
netplan get
You'll see eth1
listed with the new static IP.
4. Add Gateway and DNS
sudo netplan set ethernets.eth1.gateway4="10.0.10.1" --origin-hint eth1-net-config
sudo netplan set ethernets.eth1.nameservers.addresses=["10.0.10.1"] --origin-hint eth1-net-config
Confirm configuration:
netplan get
5. Apply the Configuration
sudo netplan apply
Verify IPs:
ip a
eth1
will now show 10.0.10.10/24
as its assigned address.
The Results
eth1
is now statically configured.- Gateway and name servers are applied.
- The configuration is saved in a dedicated file (
eth1-net-config.yaml
). netplan get
confirms all parameters are correctly indented and valid.
The Conclusion
Using netplan set
and netplan get
simplifies interface management—especially on servers with multiple NICs. Configurations are modular, clean, and easy to maintain. Static IPs are essential for service stability, and this method avoids manual YAML edits altogether.
If you'd like to support my work, show your appreciation!
Comments ()