How to Set Up a Static IP on Ubuntu 24.04
You set up a static IP on Ubuntu 24.04 by configuring its network settings using Netplan, the default network configuration utility.
A static IP address is a fixed network address assigned to your device, meaning it never changes. This is different from a dynamic IP, which your router assigns temporarily and can change periodically.
Using a static IP is crucial for devices that need to be reliably accessible, such as servers or network printers. For instance, if you’re hosting a game server on your Ubuntu 24.04 system, a static IP ensures players can always find it without the address fluctuating.
Netplan uses simple YAML files to manage network configurations, and we’ll walk you through the precise steps to assign that permanent IP address to your Ubuntu 24.04 machine.
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
Ubuntu uses a config file for servers’ IP configurations. If you have a desktop computer, you will have a GUI to manage your device’s IP configuration.
Ubuntu will also come with a default network config YAML file for your device containing automatically generated information that is not persistent.
You will need to disable this config to set up your static IP.
Run the command below to rename and disable the default config file.
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
After configuring your static IP, run the command below to show the results.
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!