Informational Website publish

Blog

News about our company, tutorials about IT and much more you will find in this page.

How to Set Up a Static IPv4 Address in Ubuntu 24

Janeiro 9th, 2025

Understanding Network Configuration Options in Ubuntu 24

There are different ways to configure a Static IPv4 Address in Ubuntu 24. Whether you prefer using Netplan (the default tool), systemd-networkd, or the legacy interfaces method, this guide will walk you through each approach step-by-step.


Method 1: Configuring Static IPv4 Address in Ubuntu

Netplan is the default network configuration tool in Ubuntu 24. Follow these steps to configure a static IPv4 address:

Step 1: Identify Your Network Interface Name

Open a terminal and type:

ip a

Look for your network interface name (e.g., eth0, enp0s3, etc.).

Check which network is up:

3: wlp0s20f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000

Step 2: Edit the Netplan Configuration File

Netplan configuration files are located in /etc/netplan/. Open the file (e.g., 01-netcfg.yaml):

sudo nano /etc/netplan/01-netcfg.yaml

Step 3: Modify the Configuration File

Replace the existing configuration with the following, customizing it for your network:

Example:

network:
  version: 2
  ethernets:
    eno1np0:     # Replace with your network interface name
      addresses:
        - 192.168.10.5/24   # Replace with your static IP and subnet mask
      nameservers:
        addresses: [1.1.1.1,8.8.8.8]   # Replace with DNS server IPs
      routes:
        - to: default
          via: 192.168.1.1    # Replace with your gateway IP

Step 4: Apply the Configuration

Save and apply the configuration:

sudo netplan apply

Step 5: Verify the Configuration

Check the new IP configuration:

ip a

Test connectivity:

ping google.com

Method 2: Configuring Static IPv4 Address in Ubuntu with systemd-networkd (Without netplan)

For those who prefer not to use Netplan, you can configure the network using systemd-networkd.

Step 1: Disable Netplan (Optional)

If Netplan is enabled, disable it:

sudo mv /etc/netplan /etc/netplan.bak
sudo systemctl disable systemd-networkd-wait-online

Step 2: Create a Network Configuration File

Create a configuration file in /etc/systemd/network/:

sudo nano /etc/systemd/network/10-static.network

Step 3: Add the Configuration

Add the following content:

[Match]
Name=<interface_name>  # Replace with your network interface name

[Network]
Address=<static_IP>/<prefix>  # Replace with your static IP and subnet mask
Gateway=<gateway_IP>         # Replace with your gateway IP
DNS=<dns_server_1> <dns_server_2>  # Replace with DNS servers

Example:

[Match]
Name=enp0s3

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8 8.8.4.4

Step 4: Restart the Network

Enable and restart the service:

sudo systemctl enable systemd-networkd
sudo systemctl restart systemd-networkd

Step 5: Edit resolved.conf

Go to systemd directory open resolved.conf

sudo nano /etc/resolv.conf

Then add DNS to the file

[Resolved]
DNS=8.8.8.8 1.1.1.1

Step 6: Verify the Configuration

Check the network interface:

ip a

Test connectivity:

ping google.com

Method 3: Configuring Static IPv4 Address in Ubuntu with Network Interfaces(Legacy Method)

For users familiar with older methods, you can use the ifupdown package.

Step 1: Install ifupdown

If not already installed:

sudo apt update
sudo apt install ifupdown

Step 2: Edit the Interfaces File

Edit the /etc/network/interfaces file:

sudo nano /etc/network/interfaces

Step 3: Add the Configuration

Add the following:

Example:

auto enp0s3   # Replace with your network interface name
iface enp0s3 inet static
    address 192.168.1.100   # Replace with your static IP
    netmask 255.255.255.0   # Replace with your subnet mask
    gateway 192.168.1.1     # Replace with your gateway
    dns-nameservers 8.8.8.8 8.8.4.4  # Replace with DNS servers

Step 4: Restart Networking

Apply the changes:

sudo systemctl restart systemd-networkd

Step 5: Verify the Configuration

Check the IP configuration:

ip a

Test connectivity:

ping google.com

Conclusion

This tutorial covered three different ways to configure a static IPv4 address on Ubuntu 24. While Netplan is the default, both systemd-networkd and the legacy /etc/network/interfaces method provide alternatives for different use cases. Choose the approach that best fits your environment and preferences.

If you encounter any issues or have questions, feel free to ask for help using our method of contact.

If you are interested in Configuring a Static IPv4 Address in AlmaLinux 9.