Setting Up Static IP Address on Ubuntu 20.04 LTS

In this article, I am going to show you how to set up a static IP address on Ubuntu Desktop 20.04 LTS and Ubuntu Server 20.04 LTS. So, let’s get started.

Network Configuration:

In order to configure a static IP on your computer, you need at least the IP address, the network mask, the gateway/default route address, and the DNS nameserver address.

In this article, I will use the following information,

IP Address: 192.168.20.160; Netmask: 255.255.255.0 or /24; Gateway/Default route address: 192.168.20.2; DNS nameserver addresses: 192.168.20.2 and 8.8.8.8

The information above would be different for you. So, make sure to replace them with yours as required.

Setting Up Static IP on Ubuntu Desktop 20.04 LTS:

Ubuntu Desktop 20.04 LTS uses Network Manager for network configuration. You can configure a static IP on Ubuntu Desktop 20.04 LTS graphically and from the command line. In this article, I will show you the graphical method of setting a static IP address on your Ubuntu Desktop 20.04 LTS.

To configure a static IP on your Ubuntu Desktop 20.04 LTS graphically, open the Settings app from the Application Menu.

Now, go to Network.

Here, you should see all the available network interfaces of your computer. Click on the gear icon of the network interface which you want to configure a static IP address.

A new window should open. In the Details tab, your current network configuration should be displayed.

Now, go to the IPv4 tab. By default, IPv4 Method is set to Automatic (DHCP). Set it to Manual.

A new Addresses field should be displayed.

Type in your desired IPv4 address, netmask and gateway address.

You can add multiple IP addresses to the same network interface. If you add multiple IP addresses to the same network interface, the IP addresses should have the same network gateway address.

By default, DNS is set to Automatic. Click on the toggle button to disable Automatic DNS.

Now, you can add DNS nameserver address here. If you have multiple DNS nameserver addresses, you can separate them with commas (,).

Now, click on Apply to save the static IP information.

The changes won’t be applied right away. You must restart your computer or the network interface for the changes to take effect.

To restart the network interface, click on the marked toggle button to turn the network interface OFF.

Now, click on the marked toggle button to turn the network interface ON again.

Now, click on the gear icon to confirm whether the new IP information is applied to the network interface.

As you can see, the new IP information is applied to the network interface.

So, this is how you set a static IP address on Ubuntu Desktop 20.04 LTS graphically using Network Manager.

Setting Up Static IP on Ubuntu Server 20.04 LTS:

Ubuntu Server 20.04 LTS uses Netplan for network configuration by default.

The default Netplan network configuration file on Ubuntu 20.04 LTS server is /etc/netplan/00-installer-config.yaml.

In this section, I am going to show you how to configure a static IP address on Ubuntu Server 20.04 LTS.

First, find the network interface name which you want to configure a static IP address with the following command:

$ ip a

As you can see, the network interface name on my Ubuntu Server 20.04 LTS is ens33. The IP address 192.168.20.149 is assigned to the network interface ens33 currently.

The network interface name will be different for you. So, make sure to replace it with yours from now on.

Now, you have to make sure that the network interface is not managed by CloudInit.

For that, open the configuration file /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg with the following command:

$ sudo nano /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg

Now, make sure the configuration file contains the following line.

network: {config: disabled}

Now, open the Netplan configuration file /etc/netplan/00-installer-config.yaml with the following command:

$ sudo nano /etc/netplan/00-installer-config.yaml

In the default Netplan configuration (as shown in the screenshot below), the available network interfaces (ens33 in my case) will be assigned IP addresses via DHCP.

To assign a static IP address to the network interface ens33, remove everything from the Netplan configuration file /etc/netplan/00-installer-config.yaml and type in the following lines.

network:
version: 2
ethernets:
ens33:
addresses: [192.168.20.160/24]
gateway4: 192.168.20.2
nameservers:
addresses: [192.168.20.2, 8.8.8.8]

NOTE: Every line in a YAML configuration file must be indented correctly. Otherwise, Netplan will not accept the configuration file. You will see syntax error messages. Here, I have used 2 spaces for each level of indentation.

Once you’re done, save the configuration file by pressing <Ctrl> + X followed by Y and <Enter>.

Now, to make sure that the configuration file does not have any syntax errors, run the following command:

$ sudo netplan try

If everything is alright, you will see the following message. Press <Enter> to continue.

The new network configuration should be accepted.

Now, to make the changes permanent, run the following command:

$ sudo netplan apply

Now, reboot your computer with the following command:

$ sudo reboot

Once your computer boots, the new network configuration should be applied as you can see in the screenshot below.

So, this is how you configure a static IP address on Ubuntu Server 20.04 LTS. Thanks for reading this article.



from Linux Hint https://ift.tt/2VzGIEk

Post a Comment

0 Comments