How To Setup Static Ip In Ubuntu

Setting up a static IP address in Ubuntu can be a bit daunting if you’re new to the world of Linux. But fear not! I’m here to guide you through the process and share some personal tips along the way.

Introduction

For those unfamiliar, a static IP address is a fixed address assigned to your computer or device on a network. Unlike a dynamic IP address, which can change each time you connect to the network, a static IP remains constant, making it easier to access your device remotely or host services.

Step 1: Opening Terminal

To begin, open a terminal on your Ubuntu machine. You can do this by pressing Ctrl + Alt + T or by searching for “Terminal” in the system menu.

Step 2: Checking Network Interfaces

Now, let’s check the available network interfaces on your Ubuntu system. In the terminal, type the following command:

ifconfig

This command will display a list of network interfaces along with their associated IP addresses. Look for the interface you wish to set a static IP for.

Step 3: Editing Network Configuration

Next, we need to edit the network configuration file to assign a static IP address to the chosen interface. In the terminal, enter the following command to open the file in a text editor:

sudo nano /etc/netplan/01-network-manager-all.yaml

Note: The file name may differ slightly depending on your version of Ubuntu.

Within the file, you’ll see a section that resembles the following:


network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: yes

Replace the dhcp4: yes line with the following lines, making sure to replace eth0 with the name of your chosen interface:


addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

In this example, we’re assigning the IP address 192.168.1.10 with a subnet mask of /24. The gateway4 line specifies the IP address of your default gateway, and the nameservers lines specify DNS servers.

Step 4: Applying the Changes

Once you’ve finished editing the network configuration file, save the changes and exit the text editor. In Nano, you can do this by pressing Ctrl + X, followed by Y and Enter.

Now, apply the changes by running the following command in the terminal:

sudo netplan apply

Your static IP address should now be configured. To confirm, you can use the ifconfig command again and look for the interface you modified. The IP address should reflect the changes you made.

Conclusion

Congratulations! You’ve successfully set up a static IP address in Ubuntu. Having a static IP can be particularly useful for tasks such as hosting websites, running servers, or accessing your device remotely. Remember, if you ever need to make further changes to your network configuration, you can always revisit the 01-network-manager-all.yaml file. Happy networking!