How to Assign Static IP Address on Ubuntu 20.04 LTS

It is always recommended to assign a static IP address to a Linux system because static ip address will be persistent across the reboots. Recently canonical has released its stable operating system “Ubuntu 20.04 LTS (Focal Fossa)” for both desktop and servers. In this article we will demonstrate how to assign a static ip address on Ubuntu 20.04 LTS Server and desktop.

Assign Static IP Address On Ubuntu 20.04 LTS Server

In Ubuntu 20.04 LTS server, network configuration is controlled and managed by netplan utility. But during the installation, cloud-init configure a dynamic ip to interface on server if the dhcp server is available. so, to configure a static ip, first we must make sure and confirm that network interface is not managed by cloud-init.

Open cloud-init file “/etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg” and make sure entry “network: {config: disabled}” is there. In case this entry is missing, then add it manually.

[email protected]:~$ cat /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
network: {config: disabled}
[email protected]:~$

Use “ip addr show” command from the console to view ip address,

[email protected]:~$ ip add show

ip-addr-show-dynamic-ip-ubuntu-20-04-server

As we can see above, a dynamic ip is assigned automatically on interface card “enp0s3”. So, to make this ip address static, we must edit the netplan configuration file “/etc/netplan/00-installer-config.yaml”.

[email protected]:~$ sudo vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      dhcp4: true
  version: 2

Above are the default entries, which shows that interface “enp0s3” is getting the IP from DHCP server. As it is an yaml file, so while making the changes in the file we must follow correct indentation. Add the following lines to the yaml file,

network:
  ethernets:
    enp0s3:
      addresses: [192.168.1.3/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [4.2.2.2, 8.8.8.8]
  version: 2

save and close the file.

Updated-netplan-yaml-ubuntu-20-04-server

Run the following “netplan apply” command to make the above changes into the effect.

[email protected]:~$ sudo netplan apply
[email protected]:~$

Now run “ip addr show” and “ip route show” command to view ip address and route details.

[email protected]:~$ ip add show
[email protected]:~$ ip route show

Output of above command would look like below,

ip-addr-show-route-ubuntu-20-04-server

Perfect, output confirms that Static IP has been assigned successfully on interface ‘enp0s3‘. Even if we reboot the server, this ip address will be consistent.

Now, let’s move to Ubuntu 20.04 LTS desktop.

Assign Static IP Address on Ubuntu 20.04 LTS Desktop

Network configuration in Ubuntu desktop is controlled by network manager. Configuring a static ip address on Ubuntu 20.04 desktop is very easy. Login to your desktop environment and click on network icon and then choose wired settings.

network-icon-ubuntu-20-04-lts-desktop

In the next window, Click on ‘gear box’ icon under wired option,

Gear-box-icon-Ubuntu-network-icon

In the next window, Choose IPV4 Tab and then select Manual and specify the IP details like IP address, netmask, gateway and DNS Server IP.

Static-IP-Ubuntu-20-04-LTS-Desktop

Click on Apply to save these changes and we must disable and enable interface once to assign the ip address to interface.

Enable-Disable-Interface-Ubuntu-20-04-desktop

Once you enable and disable the interface then static IP should be assigned to the interface, we can verify by looking at the Details Tab from Wired Settings.

IP-Details-Ubuntu-Desktop-Ubuntu-20-04-LTS

Perfect, above confirms that static ip address has been assigned to the interface successfully. This conclude the article; I hope these steps help you to configure static IP Address on your Ubuntu 20.04 LTS server and desktop. Please do share your feedback and comments.

4 Responses

  1. Narayan says:

    Thanks for the excellent article,
    It is always recommended to assign a static IP address to a Linux system because static ip address will be persistent across the reboots. that is understood.
    where exactly i see the advantage of assigning static ip address to my linux desktop?
    How circled point 3, 4, 5 in IPv4 tab are assigned, especially entries 192.168.1.210 and 255.255.255.0. If these two are explained, then it will be great.

    • Narayan says:

      ok, ifconfig and netstat -r gives netmask and gateway. but still i would like to know the advantage of assigning static ip address to my linux desktop preferably with example applications. thanks.

      • diskdur says:

        Imagine you open a network service on your linux desktop, let’s assume it is a web server running on port 80, and you want to expose this service to the internet.

        You would have to add a port translation rule into your internet box to forward connections on your public ip to your linux desktop system. And the configuration in the box is static, you need a fixed and consistent ip addr on your internal network.

        You achieve that either with static ip that you assign by yourself, or by configuring the dhcp server inside your internet box to reserve an ip associated to your linux destop mac address.

    • Pradeep Kumar says:

      Hi Narayan,
      If your desktop is connected to the modem or a switch where DHCP server is configured with subnet “192.168.1.0/24”. So when your desktop tries to get ip from DHCP server then it will always picks one ip from the pool “192.168.1.2 – 192.168.1.254” . But if you want to map a fixed ip to desktop then you can assign that IP as static.

Leave a Reply

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

Pin It on Pinterest