Configure Static IP Address on Ubuntu 22.04|20.04|18.04

Posted on 138 views

In today’s guide, we are going to see how to configure a static IP address on Ubuntu server 22.04|20.04|18.04. After installing Ubuntu 22.04|20.04|18.04 Server or Desktop, the default setting it to obtain an IP address automatically via DHCP server. This means that you will have to configure a Static IP address Manually.

Method 1: Manually edit Network Configuration files

To get a Static Ip Address on Ubuntu server 22.04|20.04|18.04, you’ll edit interfaces configuration file located at /etc/network/interfaces. You can use vi/vim editor or nano editor for this purpose.

In this example, we’ll use vim editor and configure our server to use the IP address of, netmask, dns server and default gateway being

Open /etc/network/interfaces

sudo vim /etc/network/interfaces

If you prefer nano editor, use:

sudo nano /etc/netwok/interfaces

Then add the following lines replacing with your IP information.

auto eth0
iface eth0 inet static

Save the configuration changes and quit. You can also update DNS server settings at runtime by adding the lines inside /etc/resolv.conf file.

$ sudo vim /etc/resolv.conf

For the changes to take effect, restart your network daemon by

sudo ifdown eth0 && sudo ifup eth0

Don’t forget to replace eth0 with your network card name.

Check that you have an ip address on eth0 interface by typing

$ ifconfig -a
## OR
$ ip addr

If you cannot see ip address, gateway, and netmask info, restart your computer. Just type the command reboot on the terminal

sudo reboot

Method 2: Use Netplan YAML network configuration

On Ubuntu 22.04|20.04|18.04, you can use Netplan which is a YAML network configuration tool to set static IP address.

This configuration assumes your network interface is called eth0. This may vary depending on your working environment.

Create a network configuration file.

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

Then configure like below.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
  version: 2
  renderer: networkd
      dhcp4: no
      # Ser IP address & subnet mask
      addresses: []
      # Set default gateway
        # Set DNS name servers
        addresses: [,]
      dhcp6: no

When done making the changes, save the configuration file and apply your network settings.

sudo netplan apply

To confirm your network settings, use the command:

$ ip addr 

If you don’t need IPv6, it’s possible to disable it like follows.

echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p 

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.