Hi everyone, this time I want to share how to set a static IP on Ubuntu Server 26.04 using netplan. A static IP is something you really need to set before the server is used for any service, whether that is SSH, a DHCP server, a DNS server, a web server, or a file server. If the server still gets its IP from DHCP, the address can change at any time and every client computer that connects to the server will lose its connection.
I did this hands on with the same server from my guide on how to install Ubuntu Server 26.04 LTS, and then tested it from a Windows PC acting as the client. Two things turned out to be different from most tutorials you find online. The netplan file on my server is not called 50-cloud-init.yaml, and the 26.04 installer had already turned off cloud-init network configuration automatically. I cover both of them in their own steps.
The steps below also work on Ubuntu Server 24.04 and 22.04 because they all use netplan. The only things you need to adjust are the file name and the interface name.
Preparation Before Setting a Static IP
Before changing anything, gather three pieces of information first: the name of your network interface, the gateway address, and the DNS used on your network. Also decide which IP you want to use as the static IP. Make sure that IP is not already used by another device, and ideally pick one outside your router’s DHCP range so there is no conflict.
On my network, the router sits at 192.168.1.1 and I chose 192.168.1.200 for the server. Before using it, I pinged 192.168.1.200 from another PC and got no reply, which means the IP was still free.
Check the interface name and current IP

Log in to the server, then run the following commands.
ip -4 a show
ip routeYou can see that the interface on my server is named enp0s3 with the IP 192.168.1.16 obtained from DHCP, marked by the words dynamic and proto dhcp. The line default via 192.168.1.1 shows the gateway in use. Write down your interface name and gateway because you will need both in the configuration file. The interface name can be different on every computer, for example ens18, ens33, or eth0.
Check the netplan configuration file

All netplan configuration is stored in the /etc/netplan folder. Look at the file name and then display its contents.
ls /etc/netplan/
sudo cat /etc/netplan/00-installer-config.yamlOn my server there is only one file, named 00-installer-config.yaml, which was created by the installer with the setting dhcp4: true. A lot of tutorials mention a file called 50-cloud-init.yaml, and that file is indeed used on servers built from a cloud image or on a VPS. Just use whatever file name exists on your own server.
Make sure cloud-init does not overwrite the configuration

On a cloud server or VPS, cloud-init can overwrite the netplan configuration every time the server boots, so the IP goes back to DHCP. Check first whether cloud-init network configuration has already been disabled.
ls /etc/cloud/cloud.cfg.d/ | grep network
sudo cat /etc/cloud/cloud.cfg.d/00-subiquity-disable-cloudinit-networking.cfgOn my fresh Ubuntu Server 26.04 install, the file 00-subiquity-disable-cloudinit-networking.cfg was already there with the content network: {config: disabled}. That means the installer has already turned it off and you do not need to create any file.
Note: If that file does not exist on your server, which usually happens on a VPS or a cloud image, create the file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing a single line network: {config: disabled}. This method follows the official cloud-init documentation.
How to Set a Static IP with Netplan
Back up the old configuration file
Before editing, keep a copy of the original file. I save it in my home folder, not in /etc/netplan, because netplan reads every file ending in .yaml inside that folder.
sudo cp /etc/netplan/00-installer-config.yaml ~/00-installer-config.yaml.bakEdit the netplan YAML file

Open the configuration file with nano.
sudo nano /etc/netplan/00-installer-config.yamlDelete the old content, then type the following configuration. Adjust the interface name, IP, gateway, and DNS to match your own network.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: false
dhcp6: false
addresses:
- 192.168.1.200/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 8.8.8.8]The addresses line holds the static IP along with its prefix, and /24 is the same as the subnet mask 255.255.255.0. The routes section with to: default and via is the new way of writing the gateway. The old gateway4 syntax has been marked as deprecated in the netplan documentation, so you should not use it anymore. Nameservers holds the DNS, and I use the router’s DNS with 8.8.8.8 as a backup. Save with Ctrl + O, press Enter, then exit with Ctrl + X.
Warning: YAML is very sensitive to indentation. Use spaces, not Tab, and make sure the number of spaces at each level is exactly the same as in the example. A single wrong space can make netplan reject the whole file.
Check the permission and validate the file

The netplan file should only be readable and writable by root. Check its permission, then validate the file contents with netplan generate.
sudo stat -c '%A %U:%G %n' /etc/netplan/00-installer-config.yaml
sudo netplan generateThe result -rw——- root:root means the permission is already 600. The netplan generate command prints nothing at all when the YAML is written correctly. If there is a mistake, netplan immediately points to the line that has the problem.
Applying the Static IP Configuration
Test it first with netplan try

Do not jump straight to netplan apply, especially if you manage the server remotely. Use netplan try first.
sudo netplan tryNetplan applies the new configuration and then waits for confirmation. If you do not press Enter within 120 seconds, the configuration is automatically rolled back to the previous state. This feature saves you if it turns out you mistyped the IP or gateway and your SSH connection drops.
My experience: Before pressing Enter, I opened PowerShell on my Windows PC and pinged 192.168.1.200. Only once I got a reply was I sure the new configuration was working and safe to accept.

Press Enter, and the message Configuration accepted will appear, which means the new configuration has been saved permanently.
Apply it with netplan apply

Run netplan apply to make sure the configuration is really applied, then check the IP, route, and DNS again.
sudo netplan apply
ip -4 -br a show enp0s3
ip route
resolvectl dns enp0s3You can see that the IP has changed to 192.168.1.200/24, the gateway is now default via 192.168.1.1 proto static, and the DNS shows 192.168.1.1 and 8.8.8.8. The words dynamic and proto dhcp are gone.
Testing the Static IP
Testing should be done from two sides. From the server, to make sure it can reach the internet, and from a client PC, to make sure the server can be reached at its new IP. The client PC is another computer on the same network, and here I use a Windows PC connected to the same router as the server.
Test the internet connection from the server

Ping a public IP and a domain name.
ping -c 3 8.8.8.8
ping -c 3 ubuntu.comPinging 8.8.8.8 tests the gateway, while pinging ubuntu.com also tests DNS at the same time. If the ping to the IP works but the ping to the domain fails, the problem is in your nameservers setting.
Check the network status with netplan status

Netplan has a command that shows the full state of the network.
sudo netplan status enp0s3At the top it says Online state: online. Below that you can see the address 192.168.1.200/24, the DNS, and the route default via 192.168.1.1 labeled static.

To see the configuration netplan is currently reading, use netplan get.
sudo netplan get ethernets.enp0s3Test ping from the client PC

Now move to the client PC. On Windows, open PowerShell or Command Prompt, then ping the server IP.
ping 192.168.1.200If you see Reply from 192.168.1.200 with 0% loss, the server can now be reached from other computers using its new static IP.
Test SSH from the client PC

Still in PowerShell, try connecting to the server over SSH using the new IP. Replace the username with your own.
ssh mamangdigital@192.168.1.200After entering the password, I was logged in to the server and the command ip -4 -br a showed 192.168.1.200. From now on the server can simply be accessed through this IP, and the IP will not change even when the server or the router is restarted.
Common Problems and How to Fix Them
Permissions for /etc/netplan are too open

I deliberately changed the file permission to 644 to see this message. Netplan immediately showed WARNING Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others. This message does not take your network down, but you should still fix it because a netplan file can contain sensitive data such as a WiFi password.
sudo chmod 600 /etc/netplan/00-installer-config.yaml
After the permission was set back to 600, netplan generate ran again without any warning.
gateway4 has been deprecated
This message shows up if you are still using the gateway4: 192.168.1.1 syntax from an old tutorial. Replace it with a routes block containing to: default and via, like the example above. Do not use both at once, because the default route can only be defined once for each IP family.
Error in network definition
This is almost always caused by wrong YAML indentation or a missing colon. Netplan shows the line and column number where the problem is, so open the file again and check that line. Make sure there are no Tab characters, because YAML only accepts spaces.
IP goes back to DHCP after a reboot
The most common cause is cloud-init rewriting the netplan file during boot, usually on a VPS. Create the 99-disable-network-config.cfg file as shown in the preparation section. Another cause is that there is still another .yaml file in /etc/netplan that enables dhcp4. Netplan reads all .yaml files in order of their names, so delete or move any file you are not using.
SSH disconnects after changing the IP
This is normal because the old SSH session is still using the previous IP. Just reconnect SSH to the new IP. So you do not end up locked out of a remote server, get used to using netplan try, because the configuration is rolled back automatically if you are unable to press Enter.
At this point the Ubuntu 26.04 server is running on a static IP and can be reached from the client PC through both ping and SSH. The next step is securing remote access to this server, which I cover in the guide to configure an SSH server on Ubuntu 26.04 with SSH keys, from passwordless login to changing the SSH port. If you run into a different error while trying this, just write it in the comments along with the error message, and we can figure out the solution together.












