When setting up a Linux server – especially for web hosting, file sharing, or remote access via SSH – it’s often necessary to assign a static IP address. This ensures your server doesn’t get a new IP every time it reboots.
If you’re running Ubuntu 18.04 or later, you’re likely using Netplan for network configuration. This guide will walk you through assigning a static IP using Netplan step-by-step.
๐งฐ What You’ll Need
- A running Ubuntu server
sudoprivileges- Basic knowledge of your network settings (IP, subnet, gateway, DNS)
โ๏ธ Step 1: Locate and Edit the Netplan Config File
Netplan’s config files are usually found in the /etc/netplan/ directory. Run the following to list the files:
ls /etc/netplan/
You’ll likely see something like:
01-netcfg.yaml
Now open that file with your favorite text editor (here we use nano):
sudo nano /etc/netplan/01-netcfg.yaml
๐งพ Step 2: Configure Your Static IP
Replace the contents with something like this:
network:
version: 2
ethernets:
ens33:
addresses:
- 192.168.1.183/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 192.168.1.1
routes:
- to: default
via: 192.168.1.1
๐ Note: Replace
ens33with your actual network interface name. You can check that with:ip link show
๐พ Step 3: Apply the Configuration
Save and exit (Ctrl + O, Enter, Ctrl + X in nano), then apply the new settings:
sudo netplan apply
Optional but recommended:
sudo netplan try
This gives you 120 seconds to confirm the new config works. If not, it’ll revert automatically.
โ Step 4: Verify Your IP Settings
Check your network interface with:
ip addr show
And check your routing table with:
ip route show
You should see:
- Your new IP address (
192.168.1.183) - A default route via
192.168.1.1
๐ Conclusion
And that’s it! You’ve successfully configured a static IP address on Ubuntu using Netplan. This setup is persistent across reboots and works great for servers that need a reliable network identity.
If you found this helpful, consider bookmarking this post or sharing it with others who manage Linux servers! โ๏ธ
