How to set a static IP address on Ubuntu 16.04?

You can follow these steps:

Open the terminal by pressing Ctrl+Alt+T.
Type the command “sudo vi /etc/network/interfaces” and press Enter. This will open the “interfaces” file in the vim text editor with root privileges.
Find the line for the network interface you want to configure (e.g., “iface eth0 inet dhcp”) and replace “dhcp” with “static”.
Add the following lines with your desired IP address, gateway, and subnet mask:

address 192.168.0.12
netmask 255.255.255.0
gateway 192.168.0.1

Save and close the file by pressing Ctrl+O, Enter, and then Ctrl+X.
Restart the networking service to apply the changes by typing the command “sudo service networking restart” and pressing Enter.
Your network interface should now have a static IP address. You can confirm the change by using the “ip addr show” command.d..