How to Set up a Static IP address on Ubuntu 26.04
A static IP address is a network address that stays the same every time your Ubuntu 26.04 machine connects. Your router normally assigns a new address each time, which can change where other devices find your computer.
Laptops rarely need a fixed address. A home server, file share, or database does, because other devices need to reach it at the same address every time. On Ubuntu 26.04, you set a static address with Netplan, the tool Ubuntu uses to manage networking.
These steps work on Ubuntu Server and any Ubuntu install that uses Netplan. If you run the desktop edition and prefer menus, skip to the graphical route in the last main section.
Open the Netplan file in /etc/netplan/ (for example, sudo nano /etc/netplan/50-cloud-init.yaml), set dhcp4 to false, and add your address, such as 192.168.1.50/24, with your router as the default route. Then run sudo netplan apply. The address stays fixed across reboots, so other devices can reach the machine at the same place every time.
Gather your network details first
Collect these numbers before you edit any file. Guessed values are the most common reason a static setup breaks the connection.
- Find your current address and interface name. Open a terminal and run
ip -br addr. Find the interface that holds your current address. Its name usually looks likeens18,enp3s0, oreth0. Write down the interface name and the address, including the number after the slash. That number is the prefix, explained in the tip below., such as192.168.1.45/24.💡TipThe/24at the end is a subnet mask in CIDR notation (a shorthand that shows how much of the address identifies the network).Most home networks use
/24. - Find your gateway. The gateway is your router, the device that sends your traffic to the internet. Run
ip route | grep default. The address afterviais your gateway, such as192.168.1.1. - Pick an address outside the router’s DHCP pool. DHCP (the system that hands out addresses automatically) reserves a range of addresses for itself. Log in to your router’s admin page and check that range. Choose an unused address outside it, like
192.168.1.50.Warning: If another device already uses your chosen address, you get an address conflict. Both devices may drop off the network, and the cause is hard to trace. Check first by running
ping 192.168.1.50from another computer. No reply means the address is probably free.
Write the Netplan configuration
Netplan reads YAML files (a text format that depends on indentation) from /etc/netplan/. One wrong space stops the whole file from loading. Editing files in this folder requires administrator privileges, so use sudo (a command that runs another command with administrator rights).
- Open the existing Netplan file. List the folder contents with
ls /etc/netplan/. You likely see a file such as50-cloud-init.yamlor00-installer-config.yaml. Open it withsudo nano /etc/netplan/50-cloud-init.yaml, using the filename you see.💡TipBack up the file before you edit it so you can restore it if something goes wrong:sudo cp /etc/netplan/50-cloud-init.yaml ~/netplan-backup.yaml. - Replace the contents with your static settings. Netplan tabs are not accepted. Indent with spaces only, and keep each level exactly two spaces deeper than the one above it. The example below uses the values from the previous section. Swap in your own interface name, address, gateway, and DNS servers.Code
network:
version: 2
ethernets:
ens18:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:This configuration turns off DHCP for the interface and assigns the fixed address. It sends outside traffic through your router and sets the DNS servers. (the services that turn names like example.com into addresses). Your router works as a first DNS server. Add a public one as a backup in case the router stops answering.
- Save the file and restrict its permissions. The steps below use nano, a text editor that runs in the terminal, and its save and exit keys. In nano, press
Ctrl+O, thenEnterto save, andCtrl+Xto exit. Then runsudo chmod 600 /etc/netplan/50-cloud-init.yaml(this requires administrator privileges).Tip: Netplan warns you when every user on the system can read the file. Setting it to 600 removes the warning and keeps the file private.
Stop cloud-init from overwriting your changes
Many Ubuntu installs use cloud-init (a tool that configures the system on first boot). On those systems, cloud-init can regenerate the network settings and switch DHCP back on. This step prevents that. It requires administrator privileges. It does no harm if cloud-init is not installed.
- Tell cloud-init to leave networking alone. Create a new file with
sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg. Add this single line:CSSnetwork: {config: disabled} - Save and close the file.
Test the configuration before you commit
A mistake in the file can cut off your connection, and you may not be able to reconnect over the network. Test the changes before you make them permanent.
- Check the syntax. Run
sudo netplan generate. No output means the file is valid. An error message usually names the line number. Indentation is the most common cause. - Apply the settings with a safety net. Run
sudo netplan try(this requires administrator privileges). Netplan applies the new configuration and waits for your confirmation. Before you run this step, make sure you have a local console or a session you can afford to lose. If you connect over SSH (a tool for logging in to a computer remotely) and the new address is wrong, you may need physical access to fix it. PressEnterto keep the settings. If you don't confirm within about two minutes, or your connection drops, Netplan rolls back to the previous settings automatically. - Make it permanent. After the test passes, run
sudo netplan apply(this requires administrator privileges). This applies the configuration and keeps it through reboots.
Verify the new address works
Confirm that the settings took effect, both on the machine and from the rest of your network.
- Check the address on the machine. Run
ip -br addr show ens18, replacing the interface name with yours. Your fixed address appears, and the old address that DHCP (automatic address assignment) gave the machine is gone. - Check the route and internet access. Run
ip routeto confirm that traffic leaves through your gateway (the default route, the path used for any address outside your network). Runping -c 4 1.1.1.1to test internet connectivity, thenping -c 4 ubuntu.comto test DNS.Tip: If the IP test works but the name test fails, the problem is DNS. Your static address is fine. Check the
nameserversblock in your YAML file. - Connect from another computer. On your Windows PC, open PowerShell and run
ping 192.168.1.50, using your address. Replies confirm that other devices can reach the server at its new address.
Set a static IP on Ubuntu Desktop instead
Ubuntu Desktop uses NetworkManager (the service that manages network connections on desktop systems). You set a fixed address through the interface and skip the YAML file.
- Open the network settings. Click the system menu in the top-right corner, then the gear icon next to your connection. Alternatively, open Settings and choose Network.
- Edit the connection. Click the gear icon beside your active wired or Wi-Fi connection. Go to the IPv4 tab and change IPv4 Method from Automatic (DHCP) to Manual.
- Enter your values. Under Addresses, enter your chosen IP, the netmask (for example,
255.255.255.0for a /24 network), and the gateway. Under DNS, enter your DNS servers separated by commas. Click Apply. Save your work before you click Apply. Turning the connection off drops any remote session, so keep this in mind before you start. Then turn the connection off and on again.
Troubleshoot common problems
These checks fix most failures.
- Read the Netplan error. Run
sudo netplan --debug applyto see the full output. Most failures come from bad indentation, a missing/before the prefix length, or the wrong interface name. - Check the interface name. If the YAML refers to an interface that doesn't exist, the network never comes up. Run
ip linkand match the name exactly. Names are case-sensitive. - Restore your backup if you lose access. From the console, run
sudo cp ~/netplan-backup.yaml /etc/netplan/50-cloud-init.yaml, thensudo netplan apply.
What to do next
Write down your address, gateway, DNS settings, and the Netplan file location. You need them if a router reset or a new network card changes your setup. Also add a matching reservation in your router's DHCP table so the router never hands that address to another device. [192.168.1.1, 1.1.1.1]
How do I configure a static IP address on Ubuntu?
Set a static IP on Ubuntu in Netplan, the tool that manages its network settings. Run ip -br addr in a terminal to find your interface name and current address. Then edit the YAML file in /etc/netplan to add the address, gateway, and DNS servers. Apply it with sudo netplan try, which reverts itself if the connection drops.
How long does it take to set a static IP on Linux?
Setting a static IP on Linux usually takes 5 to 15 minutes if you already know your address, gateway, and DNS servers. Most of that time goes to finding those numbers. Editing the Netplan file takes a minute, and the change applies in seconds. If you have to look up the settings or fix a mistake, allow 30 minutes.
How do I configure a static IP via SSH?
Connect over SSH (a remote login method), then run the same Netplan steps on the remote Ubuntu machine. Warning: if you change the address of the machine you're connected to, your SSH session drops and you may lose access. Run sudo netplan try so the change rolls back automatically if you lose connection. Reconnect using the new address.
How do I configure static IP with netplan?
Open the Netplan file in /etc/netplan with sudo. Under your interface name, set dhcp4: no, then add addresses: with your IP and prefix, such as 192.168.1.45/24. Add a default route to your gateway and list your DNS servers under nameservers. Save, then run sudo netplan try to test the change.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!