How To Setup Static Ip Ubuntu

Setting up a static IP address on Ubuntu can be a bit intimidating at first, but with a little guidance, it’s actually quite straightforward. In this article, I will walk you through the process step by step, sharing my personal insights and tips along the way. So let’s get started!

Why Set Up a Static IP Address?

Before we dive into the how-to, let’s take a moment to understand why setting up a static IP address can be beneficial. A static IP address allows your computer to have a consistent and permanent IP address on your local network. This can be particularly useful when you want to access services on your Ubuntu machine from other devices, or when you need to configure port forwarding on your router.

Step 1: Find Your Network Interface

The first step is to identify the network interface for which you want to set up a static IP address. To do this, open a terminal window and enter the following command:

ifconfig

This command will display a list of network interfaces on your system. Look for the one that is connected to your local network, typically labeled as “eth0” or “enp0sX”. Note down the name of the interface for later use.

Step 2: Edit Network Configuration File

Next, we need to edit the network configuration file to set up the static IP address. In the terminal, enter the following command:

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

This will open the network configuration file in the nano text editor. Look for the section that corresponds to the network interface you identified earlier. It should start with “ethernets” or “network” followed by the interface name. Within that section, add the following lines:


addresses: [your_static_ip_address/your_subnet_mask]
gateway4: your_gateway_ip_address
nameservers:
addresses: [your_dns_server_ip_address]

Replace “your_static_ip_address” with the desired static IP address you want to set, “your_subnet_mask” with the subnet mask for your network, “your_gateway_ip_address” with the IP address of your router, and “your_dns_server_ip_address” with the IP address of your DNS server.

Once you have made the necessary changes, save the file and exit the text editor. In nano, you can do this by pressing Ctrl+O and then Ctrl+X.

Step 3: Apply the Configuration

Now it’s time to apply the changes we made to the network configuration file. In the terminal, enter the following command:

sudo netplan apply

This command will apply the new network configuration and activate the static IP address on your Ubuntu machine.

Step 4: Verify the Configuration

To ensure that the static IP address has been successfully set up, you can use the following command in the terminal:

ifconfig

This command will display the network interfaces along with their respective IP addresses. Look for the interface you configured and verify that the IP address matches the one you set.

Conclusion

Congratulations! You have successfully set up a static IP address on Ubuntu. This will provide you with a consistent and reliable network configuration for your Ubuntu machine. Whether you are hosting services or simply want to have more control over your network setup, a static IP address can greatly enhance your Ubuntu experience.

Remember, always double-check your network configuration and consult your network administrator or Internet Service Provider if you encounter any issues.