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 ?
- A Static IP is an IP assigned to the device instead of the IP that was assigned to it by the DHCP Server
- As the name suggests, the IP remains static i.e., it doesn’t change unlike Dynamic IP
- This can be achieved by two methods:
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
ls
# View the contents of the file
# Replace <filename> with the name of the file in your machine
cat <filename>
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
network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.0.128/24
gateway4: 192.168.0.1
nameservers:
addresses: [192.168.0.1]
# 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 192.168.0.128/24. /24 denotes the subnet
# gateway4 is usually the IP address of your router i.e., 192.168.0.1 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 [8.8.8.8] 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
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.
2. Select the device that you want to reserve an address and enter the MAC Address and IP for the device. Click on “Save”
3. You should now see an address reservation entry for your device in the device list as shown below
Congratulations!! You have successfully set up a Static IP for your machine from your router
Pingback:Nginx Proxy Manager on Docker - Reverse Proxy » EasyCode