How to Set Up a Static IP Address in Ubuntu 24.04

ubuntu

Introduction

Setting up a static IP address on Ubuntu 24.04 is essential for servers, virtual machines, and any system requiring a permanent IP for remote access or network stability. In this guide, we’ll walk you through configuring a static IP address using Netplan, Ubuntu’s default network management tool.


Why Use a Static IP?

A static IP address ensures that your system retains the same IP address even after reboots. Some use cases include:

  • Hosting a web server (e.g., Apache, Nginx, WordPress)
  • Remote access via SSH
  • Network file sharing (NFS, Samba)
  • Assigning specific devices in private networks

Step 1: Identify Your Network Interface

Before configuring a static IP, identify the network interface name using:

ip a

Look for an interface like eth0, ens33, or enp0s3. You will use this name in the Netplan configuration.


Step 2: Locate Netplan Configuration File

Netplan is the default network configuration tool in Ubuntu. The configuration files are located in /etc/netplan/. To list them, run:

ls /etc/netplan/

You will typically see a file named 00-installer-config.yaml or 50-cloud-init.yaml.


Step 3: Edit Netplan Configuration File

Open the Netplan configuration file with a text editor:

sudo nano /etc/netplan/50-cloud-init.yaml

Modify it to include a static IP address, replacing enp0s3 with your actual interface name:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses:
        - 192.168.1.100/24  # Set your static IP
      routes:
        - to: default
          via: 192.168.1.1  # Set your gateway
      nameservers:
        addresses:
          - 8.8.8.8  # Google DNS
          - 8.8.4.4

Notes:

  • Replace 192.168.1.100/24 with your desired static IP and subnet.
  • Set the via value to your router’s gateway IP.
  • Use Google’s public DNS (8.8.8.8, 8.8.4.4) or your preferred nameservers.

Step 4: Apply the Configuration

Save the file (CTRL + X, then Y, then Enter) and apply the changes:

sudo netplan apply

If you experience issues, test the configuration first:

sudo netplan try

If no errors appear, your static IP is now set.


Step 5: Verify Your Static IP

To check if the static IP is applied correctly, run:

ip a

You should see your assigned IP (192.168.1.100 in this case) associated with the network interface.

You can also check connectivity with:

ping 8.8.8.8

If the ping is successful, your internet connection is working with the static IP.


Step 6: Restart Networking (If Needed)

If the new IP does not take effect, restart the network service:

sudo systemctl restart systemd-networkd

Or reboot the system:

sudo reboot

Conclusion

Configuring a static IP address on Ubuntu 24.04 ensures that your system retains a consistent network identity. This is especially useful for servers, remote access, and local networking.

Following this guide, you have successfully set up and verified a permanent static IP using Netplan.

Stay tuned for more DevOps and Linux tutorials!

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

View all posts by AmritMatti →

Leave a Reply

Your email address will not be published. Required fields are marked *