How to Configure Static IP on Ubuntu and Rocky Linux
In real production environments, servers do not rely on DHCP.
They use static IP addresses so services like SSH, Ansible, Node Exporter, and databases remain consistently reachable.
In this article, we will configure static IP addresses on:
Ubuntu Server 22.04
Rocky Linux 9
Network Architecture
In the last article, we created an internal network in the range 172.29.10.0/24.
Now, we will configure the VMs with the following IP addresses:
Ubuntu:
172.29.10.10Rocky:
172.29.10.20
Both machines will use172.29.10.254as the gateway IP. We will introduce a dedicated router VM later in the series. For now, we reserve.254as the gateway address
⚠️Tip: Never change the gateway or primary IP remotely without console access.
Configure Static IP on Ubuntu Server (Netplan)
Modern Ubuntu Server (including 22.04 and 24.04) uses Netplan for network configuration.
First, we need to identify the network interface. Run
ip aand look for something likeens33The netplan files are located in
/etc/netplan.
In a fresh Ubuntu Server installation, you will see50-cloud-init.yaml.
When you open it, you will see that it configuresens33using DHCP. To prevent cloud-init from overwriting our static configuration, we need to disable its network management.
We can disable cloud-init by creating a file
/etc/cloud/cloud.cfg.d/99-disable-network-config.cfgwithnetwork: {config: disabled}
You can use the below one-liner to do itecho 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfgAfter the reboot, the cloud-init will be disabled. But don't reboot yet.
Now to configure static IP, we have to create a file inside
/etc/netplansimilar to the50-cloud-init.yaml
Open a new YAML file:sudo nano /etc/netplan/01-static-ip.yamlEnter the following content into this file and save it:
network: version: 2 renderer: networkd ethernets: ens33: dhcp4: no addresses: - 172.29.10.10/24 routes: - to: default via: 172.29.10.254 nameservers: addresses: - 172.29.10.254 - 1.1.1.1Now, first we should check the changes. Run
sudo netplan try.
This step is significant, especially when configuring networking over SSH.
This gives 120 seconds to try the new changes.
If new configurations are not accepted within the 120-second window, the changes are automatically reverted.
In the previous step, you may have seen a file permissions too open warning. Let's fix it. Run the following commands.
sudo chmod 600 /etc/netplan/01-static-ip.yaml sudo chown root:root /etc/netplan/01-static-ip.yaml sudo netplan tryThe warning should now be gone
To verify the configuration, let's try to SSH on the new IP using our host machine.
SSH connection was successful; that means our configuration is working. Now, to save the configuration, just run
sudo netplan apply. You can do it from within the SSH.
After runningip a, you should see the new IP address172.29.10.10.
The DHCP-assigned IP may still appear temporarily.
Configuring Static IP on Rocky Linux
Rocky Linux uses NetworkManager, which can be managed via the nmcli command-line tool. Using nmcli is straightforward and efficient.
First, let's identify the interface name using
sudo nmcli con showand check the current IP withip a
As you can see above, the interface name is
ens160. Do not confuseNAMEwithDEVICEin nmcli output.NAMEcan be Wired Connection x or sankalp too, whereasDEVICEwill match what's shown in the output ofip a.Run the below command to set a static IP for the interface name you obtained above
sudo nmcli con mod '<NAME>' ipv4.method manual ipv4.addresses '172.29.10.20/24' ipv4.gateway '172.29.10.254' ipv4.dns '172.29.10.254,1.1.1.1' connection.autoconnect yesNow, run
sudo nmcli dev reapply '<DEVICE>', use theDEVICEname here. This will apply the new changes instantly.nmclidoes not provide an automatic rollback mechanism likenetplan tryCheck with
ip a, and you should see a new IP in your interface.
What's Next?
Now that our Ubuntu and Rocky Linux VMs have static IPs, the network is stable and predictable.
In the next article, we will build a dedicated gateway VM at 172.29.10.254, configure IP forwarding, and provide internet access to our internal machines.
This will evolve our setup into a structured multi-VM lab architecture, similar to real production environments.
Series Roadmap
Configuring Static IP on Ubuntu and Rocky ✅
Building a Gateway VM for Multi-VM Lab Architecture
Multi-VM DevOps Lab Architecture

