Ubuntu 24.04 uses Netplan for network configuration. On VPS and dedicated servers, you may need to configure a static IPv4 address manually after an operating system installation, network change or server migration.
This guide explains how to configure a static IPv4 address, gateway and DNS servers on Ubuntu 24.04 using Netplan.
Step 1: Find Your Network Interface
First, identify the network interface used by your server:
ip addr
You can also use:
ip link
Common network interface names include:
eth0
ens3
ens18
enp1s0
For this example, we will use:
ens18
Step 2: Check Your Current Network Configuration
Before making any changes, check the current IPv4 address and routing configuration:
ip -4 addr
Check the default gateway:
ip route
You may see something similar to:
default via 192.0.2.1 dev ens18
192.0.2.0/24 dev ens18 proto kernel scope link src 192.0.2.10
Make sure you know your correct:
- IPv4 address
- Subnet prefix
- Default gateway
- Network interface
- DNS servers
Using incorrect network information can make your server unreachable.
Step 3: Locate the Netplan Configuration File
Netplan configuration files are stored in:
/etc/netplan/
List the available files:
ls -l /etc/netplan/
Common filenames include:
00-installer-config.yaml
01-netcfg.yaml
50-cloud-init.yaml
Open the appropriate configuration file:
sudo nano /etc/netplan/50-cloud-init.yaml
Your filename may be different.
Step 4: Configure the Static IPv4 Address
For this example, we will use:
IP Address: 192.0.2.10
Subnet: /24
Gateway: 192.0.2.1
Interface: ens18
Configure Netplan as follows:
network:
version: 2
renderer: networkd
ethernets:
ens18:
dhcp4: false
addresses:
- 192.0.2.10/24
routes:
- to: default
via: 192.0.2.1
nameservers:
addresses:
- 1.1.1.1
- 9.9.9.9
Replace the example network information with the values assigned to your server.
Step 5: Validate the Configuration
Before applying the new configuration, validate it:
sudo netplan generate
If Netplan does not report any errors, test the configuration:
sudo netplan try
This step is especially important when configuring a remote server over SSH.
If the new network configuration causes connectivity problems and you cannot confirm it, Netplan can revert the changes automatically.
Step 6: Apply the Static IP Configuration
Once you have confirmed the configuration is correct, apply it:
sudo netplan apply
Your static IPv4 configuration should now be active.
Step 7: Verify the IP Address
Check the configured IPv4 address:
ip -4 addr show ens18
Check the routing table:
ip route
You should see your static IPv4 address and default route.
Step 8: Test Internet Connectivity
Test connectivity to an external IP address:
ping -c 4 1.1.1.1
Then test DNS resolution:
ping -c 4 google.com
If the first command works but the second does not, the problem is likely related to DNS configuration.
Configure Custom DNS Servers
You can change the DNS servers in the nameservers section.
For example:
nameservers:
addresses:
- 1.1.1.1
- 9.9.9.9
Other DNS resolvers can also be used depending on your requirements.
Static IP with Multiple IPv4 Addresses
A server can have multiple static IPv4 addresses assigned to the same network interface.
For example:
addresses:
- 192.0.2.10/24
- 192.0.2.20/24
- 192.0.2.21/24
If you need to configure several IPv4 addresses, see our guide:
How to Add Multiple IP Addresses on Ubuntu 24.04 with Netplan
Troubleshooting
Server Loses Network Connectivity
If you lose connectivity after changing Netplan, verify:
- The IPv4 address is correct.
- The subnet prefix is correct.
- The gateway is correct.
- The interface name is correct.
- YAML indentation is correct.
You can validate the configuration with:
sudo netplan generate
Check the Default Gateway
Run:
ip route
You should normally see a default route similar to:
default via 192.0.2.1 dev ens18
Check DNS Resolution
Run:
resolvectl status
You can also test DNS resolution with:
getent hosts idoncloud.com
Check Network Connectivity
Useful Linux network troubleshooting commands include:
ip addr
ip route
ping
traceroute
mtr
These tools can help determine whether a connectivity issue is related to the local server, routing, DNS or the upstream network.
Important Note for Dedicated Servers and VPS
Network configurations vary between hosting providers.
Some providers use routed subnets, point-to-point configurations, custom gateways or additional routing requirements.
Always verify the assigned network configuration before changing Netplan on a remote production server.
IDONCLOUD Infrastructure
Looking for reliable Linux infrastructure?
IDONCLOUD provides VPS and Dedicated Servers for Linux workloads, with IPv4, IPv6 and high-bandwidth network options.
Visit idoncloud.com to explore our infrastructure.
Related Guides
- How to Add Multiple IP Addresses on Ubuntu 24.04 with Netplan
- How to Configure IPv6 on Ubuntu
- How to Test Server Network Speed with iperf3
- How to Diagnose Packet Loss with MTR
- How to Optimize Ubuntu for 10Gbps Networking