Static IP in Ubuntu – Step-by-Step Guide

Static IP in Ubuntu – Step-by-Step Guide

In this tutorial, let’s learn how to set up a static IP in Ubuntu

What is a Static IP ?

Why Static IP?

  • Having a Static IP makes it easy to find the device you are looking for since the IP remains fixed
  • In other words Static IP address is useful if you host a website from home, a file server in your network and in many other cases. Since, a static IP address never changes, other devices in the network always know exactly how to contact the device

Method 1 – Steps to Setup Static IP on Ubuntu

1. We will be configuring a static IP using netplan and Network Manager on Ubuntu. In order to do this, Navigate to the netplan directory and find the network configuration file as shown below.

The network configuration file can have different names like 01-network-manager-all.yaml, 01-netcfg.yaml, 50-cloud-init.yaml, NN_interfaceName.yaml or it might be different in your case.

In my case, it is 01-network-manager-all.yaml

# Navigate to the netplan directory
cd /etc/netplan

# View the files in this directory

# View the contents of the file 
# Replace <filename> with the name of the file in your machine
cat <filename>
Static IP

2. In order to configure a Static IP we will need to modify this file as shown below. Before this, we need to find the name of the network interface using the ip link command. It is usually eth0 for ethernet and wlan0 for Wi-Fi

# Find the network interface name (Example shown in the picture below - eth0 is the interface in my case)
ip link

# Use an editor of your choice to edit the file
# I will be using nano in this case
# Edit the file using nano as root
sudo nano 01-network-manager-all.yaml
# Modify the contents as shown below
  version: 2
  renderer: NetworkManager
      dhcp4: no
          addresses: []
# Save the file using Ctrl + O and use Ctrl + X to exit

# In the file replace the network interface name with the network interface name on your machine
# dhcp4: no specifies the system to not use DHCP to get an IP
# Addresses specified the required static IP for the system. In this case it is /24 denotes the subnet
# gateway4 is usually the IP address of your router i.e., in this case
# nameservers consists of the list of DNS. In this case the DNS is provided by the router, hence DNS is also specified with the router ip address. You can use custom DNS like google dns [] or any other alternative

# After saving the file apply the netplan using below command
sudo netplan apply

# Verify the changes are reflected
ip addr show

# Verify the interface now has the static IP configured newly
# If the changes are not reflected reboot the system
sudo reboot now
Static IP

Congratulations!! You have successfully set up a Static IP on your Ubuntu Machine

Method 2 – Steps to Setup Static IP from the Router Configuration via Address Reservation

1. Log in to your Router Configuration and go to the DHCP Server Settings. This might be different based on your router, refer to your router configuration on google and navigate to this page. Click on “ADD” to add an address reservation.

Static IP

2. Select the device that you want to reserve an address and enter the MAC Address and IP for the device. Click on “Save”

Static IP

3. You should now see an address reservation entry for your device in the device list as shown below

Static IP

Congratulations!! You have successfully set up a Static IP for your machine from your router

3060cookie-checkStatic IP in Ubuntu – Step-by-Step Guide

One Comment

  1. Pingback:Nginx Proxy Manager on Docker - Reverse Proxy » EasyCode

Leave a Comment

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