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, stopping your IP from shifting when you run a home server, share files, or connect to network printers.
Ubuntu 24.04 handles network settings through a tool called Netplan, which uses plain text configuration files stored in the /etc/netplan/ folder to lock in your network details.
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
Setting up a static IP on Ubuntu 24.04 requires editing the Netplan configuration file in your terminal to replace DHCP with your chosen permanent IP address, subnet mask, gateway, and DNS servers. This ensures your computer always keeps the exact same network address whenever it connects to your router.
Ubuntu will also come with a default network config YAML file for your device containing automatically generated information that is not persistent.
sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
Next, run the command below to create a new network configuration file.
sudo nano /etc/netplan/01-netcfg.yaml
Then, enter the following network configuration details to use a static IP address for your device.
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 and exit.
Descriptions:
- ens33: ==> interface name. (Yours might be different than mine)
- addresses: ==> IP address and network mask
- routes: ==> default gateway
- [metric]: set priority (specify it if multiple NICs available)
- lower value is higher priority
- nameservers: ==> DNS server addresses
- search: ==> DNS search base
Next, adjust the permissions to protect the file and apply your settings.
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.
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!
Conclusion:
Setting up a static IP address on Ubuntu 24.04 ensures a stable network configuration for essential devices. You can effectively manage your server's connectivity by following the outlined steps. Here are some key takeaways:
- A static IP address, such as servers and printers, is crucial for devices requiring consistent network presence.
- Modifying network configurations on Ubuntu server involves editing the YAML file under
/etc/netplan/. - Always back up the default configuration file before making changes.
- 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.
How to configure static IP on Linux terminal?
Everything. So on the next line we'll add a space and we'll use the command. Address to give it an address in my case 192. 1681.194 which is its current network. Address then net mask 255255255.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!