Search
Close this search box.

Set Static IP on Ubuntu 20.04 | 18.04

Table of Contents

How to set Static IP on Ubuntu 20.04 | 18.04

Static IP on Ubuntu: A Comprehensive Guide

Are you a Linux user who wants to configure a static IP address on Ubuntu? If yes, then this article is for you. Here, we will explain what a static IP address is, why it is essential, and how you can configure it on Ubuntu.

 

What is a Static IP Address?

 

A static IP address is a fixed IP address assigned to a device on a network. It remains the same even if you restart the device or the router. In contrast, a dynamic IP address is assigned automatically by the router or the DHCP server each time the device connects to the network.

Why Should I Set a Static IP on Ubuntu?

Setting a static IP address on Ubuntu has several benefits:

  1. Remote Access: If you want to access your Ubuntu machine remotely, you will need to set a static IP address. With a dynamic IP address, the IP address will change each time the device connects to the network, making remote access difficult.

  2. Port Forwarding: If you want to run a server on your Ubuntu machine, you will need to set up port forwarding on your router. With a static IP address, you can forward ports to your Ubuntu machine without worrying about the IP address changing.

  3. DNS Configuration: If you want to configure DNS settings for your Ubuntu machine, you will need to set a static IP address. DNS servers use IP addresses to resolve domain names, and a static IP address ensures that the DNS server can always find your machine.

How to Configure a Static IP on Ubuntu?

Now that you know why a static IP address is important let’s learn how to configure it on Ubuntu.

To set a static IP address, we will use a command-line utility. The utility is called Netplan and was developed by Canonical. Netplan configures network interfaces with YAML files. Configuring an interface using the same technique to get a dynamic IP or setting a static IP with the same method is possible.

 

In this article, we will explain how to set static IP on Ubuntu 20.04 | 18.04

 

Step 1: Getting your system up and running

 

  1. Sign in to your system or register a newly created one by logging in to your VPSie account
  2. Connect by SSH using the credentials we emailed you.
  3. Once you have logged into your Ubuntu instance, run these commands to update your system.
apt-get update && apt-get upgrade -y

 

 

Step 2: Set Static IP

 

Using Terminal, open the /etc/netplan directory. This is where you will find the YAML configuration file you will use to change the IP address.  

 

I have a YAML file named 00-installer-config.yaml. If you’re configuring a static IP address, copy the below configuration and paste it. The YAML file must also be padded correctly.

 

network:
  version: 2
  ethernets:
     ens33:
        dhcp4: false
        addresses: [162.220.13.12/24]
        gateway4: 1162,220.13.248
        nameservers:
          addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1]

Run the netplan command after you have saved the file. This will make the changes permanent.

 

 

sudo netplan apply

 

If you want to check the new IP address, you can use the below command; the IP address can also be limited in many other ways; here, we are using “ifconfig.

ifconfig

 

That’s it! Thanks for reading! I hope it was informative for you! 

 

Port knocking on Linux

Setting a static IP on Ubuntu is important for network stability and reliability. A static IP address ensures that your device always has the same IP address, which is necessary for connecting to devices on the same network and running services such as web servers or file sharing.

To set a static IP on Ubuntu, you will need to edit the /etc/network/interfaces file. First, open a terminal window and type “sudo nano /etc/network/interfaces” to open the file for editing. Then, find the section for your network interface (such as eth0 or wlan0) and add the following lines:

javascript
iface eth0
inet static
 
address 192.168.1.100
 
netmask 255.255.255.0
 
gateway 192.168.1.1
 
dns-nameservers
8.8.8.8
 

Replace “eth0” with the name of your network interface, and use the IP address, netmask, gateway, and DNS servers appropriate for your network.

 To check your current IP address on Ubuntu, open a terminal window and type “ip addr show”. Your IP address will be listed under the appropriate network interface (such as eth0 or wlan0).

No, setting a static IP should not affect your ability to connect to the internet as long as you set the correct gateway and DNS servers for your network.

Make a Comment
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.