Setting a static IP Address on a headless Ubuntu Server post-installation is done via Netplan, which has been Ubuntu's default network management tool since Ubuntu 17.10.
Netplan uses YAML configuration files located in /etc/netplan/.
I have a Ubuntu server running, and I will connect to it via SSH.
Step 1: Identify Your Network Interface Name
Run the ip command to view available network interfaces:
ip link show
Look for your primary network interface (e.g., eth0, enp0s3, or enp3s0). Ignore lo (loopback).
Step 2: Locate or Create the Netplan Configuration File
Netplan configuration files are located in /etc/netplan/. List the directory to find your file name:
ls /etc/netplan/
You will typically see a file like 50-cloud-init.yaml, 01-netcfg.yaml, or 00-installer-config.yaml. Open it with nano:
sudo nano /etc/netplan/00-installer-config.yaml
(Replace 00-installer-config.yaml with your actual file name.)
Step 3: Edit the Netplan Configuration File
Important (YAML Syntax): YAML files are strictly indented with spaces, not tabs. Improper indentation will cause Netplan to fail.
Modify the file to set your static IP details. Here is a standard configuration:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: false
addresses:
- 192.168.1.180/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 1.0.0.1
Adjust the values to fit your local network.
Save and exit (Control + O, Enter, then Control + X (or Control + X, Y, then Enter) in nano editor.
Step 4: Test and Apply the Changes
Netplan provides a safe way to test configuration without locking yourself out of a headless server over SSH.
1. Try the Configuration Safely
sudo netplan try
netplan try checks for syntax errors and applies the changes temporarily.
Press Enter within 120 seconds to confirm the configuration. If you lose connection and don't press Enter, it will automatically roll back to the previous settings.
2. Alternatively, Apply Directly
If you are directly connected or confident in your settings:
sudo netplan apply
Finally, reboot the system:
sudo reboot
Step 5: Verify Your Connection
Check if the static IP has been applied:
ip addr show eth0
Verify external network access and DNS:
ping -c 3 1.1.1.1
ping -c 3 ubuntu.com
Once these checks are successful, your headless Ubuntu Server should be using the configured static IP address and have working external network access and DNS resolution.
With a static IP configured, you can reliably connect to your headless Ubuntu Server over SSH without having to determine its new DHCP-assigned address after every reboot.
