How to Set Up a Static IP on Ubuntu 24.04
A static IP address on Ubuntu 24.04 gives your computer a permanent network address that never changes. Normally your router hands out addresses through DHCP, and the address can change after a reboot or when a lease expires. That causes trouble when you run a home server, share files, or connect to network printers, because other devices need to find the machine at the same address every time.
Ubuntu 24.04 handles network settings through a tool called Netplan. Netplan reads plain text YAML configuration files stored in the /etc/netplan/ folder and uses them to set your network details. Nothing needs to be installed. You only edit a text file in the terminal.
You set up a static IP on Ubuntu 24.04 by disabling the default Netplan configuration, creating a new YAML file with your IP details, and then applying the changes. Use `sudo mv` to disable the old config, `sudo nano` to create the new one, and `sudo netplan apply` to activate it.
Setup static IP
To set up a static IP, you edit the Netplan configuration in your terminal and replace DHCP with four values of your choosing: the IP address, the subnet mask, the gateway and the DNS servers. Your computer then keeps the exact same address every time it connects to your router.
Before you start, collect these details:
- The address you want to use. It must be on the same network as your router and outside the router’s DHCP range, so the router never gives it to another device. Check the router’s admin page for that range.
- The subnet mask. Most home networks use 255.255.255.0, which is written as /24 in the configuration.
- The gateway, which is almost always your router’s address.
- One or more DNS server addresses. Your router’s address works, or you can use a public DNS service.
You also need an account with sudo rights. Open a terminal with Ctrl+Alt+T on a desktop install, or sign in at the console on a server. If you are connected over SSH, read the warning near the end first, because changing the address drops your session.
Ubuntu also ships with a default network configuration YAML file for your device. It holds automatically generated settings, which are usually DHCP, so the address it gives you is not persistent. The file name depends on how Ubuntu was installed (server installer, cloud image or desktop), so list the contents of the Netplan folder to see what yours is called.
You need to disable this default config before your static IP will take effect. If you leave it in place, it can conflict with your new file and keep the interface on DHCP. Do not delete it. Rename it, so you can restore it if something goes wrong.
- Run the command below to rename and disable the default config file. Netplan only reads files that end in .yaml, so the renamed file is ignored but stays on disk as your backup.
Enter your password if sudo asks for it. The command prints nothing when it works. If you get a "No such file or directory" message, the file name in your command doesn't match what is in the folder, so check the exact name again.
sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
- Run the command below to create a new network configuration file. It opens the new file in a text editor, and the file is empty. Give it a name that ends in .yaml.
sudo nano /etc/netplan/01-netcfg.yaml
- Enter the following network configuration details to use a static IP address for your device. Replace the example values with your own address, gateway and DNS servers.
YAML is strict about indentation. Use spaces only, never tabs, and keep the same number of spaces for items at the same level. A wrong indent is the most common reason a Netplan file fails to apply.
network:
ethernets:
ens33:
dhcp4: false
addresses: [192.168.156.130/24]
routes:
- to: default
via: 192.168.156.2
metric: 100
nameservers:
addresses: [192.168.156.2,192.168.156.3]
search: [srv1.example.com,svr1.geek.net]
dhcp6: false
version: 2
- Save the file and exit the editor.
You should be back at the terminal prompt. Nothing has changed on the network yet, because Netplan only reads the file when you apply it.
Descriptions:
Here is what each setting in the file does:
- ens33: ==> interface name. (Yours might be different than mine.) Run the ip address show command to see the real name on your machine, such as enp0s3 or eth0. Use that name in the file.
- addresses: ==> IP address and network mask, written together. The number after the slash is the mask length, so /24 means 255.255.255.0.
- routes: ==> default gateway, which is normally your router
- [metric] : set priority (specify it if multiple NICs available). This matters on machines with more than one network card, such as a wired and a Wi-Fi connection.
- lower value is higher priority
- nameservers: ==> DNS server addresses. List more than one so name lookups still work if the first server is down.
- search: ==> DNS search base. It is the domain name added to short host names. You can leave it out on a home network that has no local domain.
Next, adjust the permissions to protect the file and apply your settings. Recent Netplan versions warn you if the configuration file can be read by other users, since network files can hold sensitive details. Restricting access removes the warning. The apply command then loads the file and switches the interface to your static address. A reboot is not required.
Connected over SSH? Your session will drop the moment the address changes, and you will need to reconnect to the new address. If you typed a wrong value, you could lose access to the machine, so keep a console or physical keyboard within reach.
sudo chmod 600 /etc/netplan/01-netcfg.yaml sudo netplan apply
Display IP address
Checking your IP address on Ubuntu 24.04 takes just one terminal command to confirm your network settings are working. Run the ip address show command to view all active network interfaces and verify that your new permanent IP address is correctly assigned to your system.
ip address show
The command should output something similar to the one below. Find your interface in the list and look at its inet line. It should show the address and mask length you set. A DHCP address is marked dynamic, so your static address should not carry that word.
If you still see the old address, the file probably has a typo or an indentation error, or the old default file is still active. Go back and check the file name, the spacing and the interface name. If you need to undo everything, delete the new file, rename the backup so it ends in .yaml again, and apply the settings once more. The machine then goes back to DHCP.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:bc:b2:46 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.156.130/24 brd 192.168.156.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:febc:b246/64 scope link
valid_lft forever preferred_lft forever
That should do it! Your machine now keeps the same address every time it connects. To confirm the change survives a restart, reboot once and run the check again.
Conclusion:
Setting up a static IP address on Ubuntu 24.04 ensures a stable network configuration for essential devices. You can manage your server's connectivity by following the steps above. Here are some key takeaways:
- A static IP address is crucial for devices that need a consistent network presence, such as servers and printers.
- Modifying network configurations on an Ubuntu server involves editing the YAML file under
/etc/netplan/. Use spaces for indentation, never tabs. - Always back up the default configuration file before making changes. Renaming it keeps a copy you can restore.
- Adjusting file permissions and applying the settings ensures security and functionality.
- You can verify the static IP setup using the
ip address showcommand to confirm the changes.
Implementing these steps will help you maintain an efficient and reliable networking environment. Keep a note of the address you chose and reserve it on your router if you can, so no other device is ever given the same one.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
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!