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.
sysadm@linuxtechi:~$ cat /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg network: {config: disabled} sysadm@linuxtechi:~$
Use “ip addr show” command from the console to view ip address,
sysadm@linuxtechi:~$ ip add show
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”.
sysadm@linuxtechi:~$ 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.
Run the following “netplan apply” command to make the above changes into the effect.
sysadm@linuxtechi:~$ sudo netplan apply sysadm@linuxtechi:~$
Now run “ip addr show” and “ip route show” command to view ip address and route details.
sysadm@linuxtechi:~$ ip add show sysadm@linuxtechi:~$ ip route show
Output of above command would look like below,
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.
In the next window, Click on ‘gear box’ icon under wired option,
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.
Click on Apply to save these changes and we must disable and enable interface once to assign the ip address to interface.
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.
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.
from Linuxtechi https://ift.tt/3dHaHlj
0 Comments