How to configure static IP on Ubuntu?

Overview

This is a step-by-step tutorial on how to configure a static IP address on an Ubuntu server using netplan and a desktop computer with NetworkManager. For servers, a static IP address is advised since it is more reliable than a dynamic IP address assigned by a DHCP server.

Some service providers may provide two separate customers the same IP address due to a lack of IP addresses or to cut costs. In this case, the customer might face some connection issues. While static IP numbers are user-specific, they do not result in the same issues, but you should still be cautious because your IP address might be used inappropriately in a number of ways.

All recent Ubuntu releases, including the most current are compatible with this guide. Both the GUI and command line methods for setting a static IP address that Ubuntu provides are discussed here.

Prerequisites

There are certain prerequisites that need to be met before you begin:

  • An ubuntu system or server

  • Root privilege or access via sudo command

Get Started

Step-1: Accessing the .yaml file

  • Type the following command to check the name of your system network interface:

ip a
  • Type the following command to go to the netplan directory:

cd /etc/netplan
  • Type the following command to list the files in the netplan directory:

ls

Step-2: Changing the network configuration in .yaml file

  • Type the following command to open the configuration file, replace the file name with your .yaml file:

sudo nano 50-cloud-init.yaml
  • Change the following configurations in the file.

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:    #Modify this line according to your preferred network interface name.
      dhcp4: false
      addresses:
        - 192.168.1.10/24    #Replace with your IP Address
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
  • After making the modifications shown above, press ctrl+x then Y and press enter to save the changes done.

  • Apply the changes using the following command:

sudo netplan apply
  • Type the following command to verify the changes and network configuration.

ip addr show dev ens3

Conclusion

Now you can access your Ubuntu server using the static IP you have set in this process. You can also set up multiple IPs using this process.

Last updated