This article explains setting up a static IP address on Ubuntu 24.04.
A static IP address is a fixed address assigned to a device on a network. It is recommended that devices that require consistent addresses, like servers, printers, or network appliances, use static IP addresses.
If you use an Ubuntu server, you should probably set up a static IP address or reserve a unique IP from a DHCP server for the Ubuntu server.
You can set up a static IP for your Ubuntu server using the steps below.
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 show
command to confirm the changes.
Implementing these steps will help you maintain an efficient and reliable networking environment.
Leave a Reply