We can configure or change the DHCP to Static IP address in the terminal using the Netplan utility. Ubuntu or Ubuntu server, by default, uses Netplan to configure the network configurations.
Since Netplan uses the YAML file for the configuration of the network, then we need to edit the YAML file in the /etc/netplan directory. Head to the /etc/netplan directory by using the cd command in the terminal.https://faddbbbf4b53694156f2afa0472a85ef.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html$ cd /etc/netplan
If we list the files in the /etc/netplan directory using the ls command,$ ls
we can have the name of the YAML file for network configuration.
Open it in a nano editor.$ sudo nano 01-network-manager-all.yaml
Provide the static IP address of your choice with the netmask, gateway, and the addresses of the nameservers using the following given syntax or paste the following lines in that YAML file.https://faddbbbf4b53694156f2afa0472a85ef.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
dhcp4: no
addresses: [10.0.2.60/24]
gateway4: 10.0.2.2
nameservers:
addresses: [192.168.18.1, 8.8.8.8]
Once you’re done, save the file and get back to the terminal.
Now, run the following command in the Ubuntu server or terminal to apply changes.$ sudo netplan apply
And reboot your system for the changes to take effect.$ sudo reboot
After rebooting your system, Run the “ip a” command to verify the changes.$ ip a
It can be seen in the screenshot above that the IP address is changed to the desired static IP address successfully.