Hi. In this article, we'll be learning how to configure a Static IP address on a Linux (Ubuntu) machine both from the terminal and the GUI using Ubuntu's default network configuration tool called "Netplan".
What is Netplan
Netplan is the default network configuration tool for managing networks in Ubuntu. It uses YAML files that are located in /etc/netplan/. It supports two renderers to control network interfaces on Ubuntu-based systems which are NetworkManager and systemd(networkd). NetworkManager is mostly used on the client's desktop machine as it is GUI based while systemd(networkd) is used on servers without a GUI.
A. Configuring Static IP using NetworkManager (GUI)
By default, Ubuntu uses NetworkManager as the renderer to control network interfaces as shown in the image below
To configure the static IP through the GUI which uses NetworkManager behind the scenes:
- Go to your Network settings as shown in the image below
Select IPV4
Enter the IP details and click Apply as shown in the image below
B. Configuring Static IP from the terminal using systemd(networkd)
The network interface can be managed either by NetworkManager or networkd, but it cannot be managed by both at the same time. Therefore, to configure a network interface using networkd, the NetworkManager renderer has to be stopped and disabled.
NOTE: Most of the commands have to be run as root (sudo)
Step 1:
stop and disable NetworkManager using "systemctl stop" and "systemctl disable"
Step 2:
Create a YAML file
Using your editor of choice (vim, nano etc), create the YAML file and save it in /etc/netplan
version - version of the network configuration format
renderer - make ubuntu use networkd as the renderer
ethernets - device type (an ethernet card in this case. A wireless card will be wifis)
enp0s3 - the network interface to be statically configured
dhcp4 - false. Disable dynamic ip configuration
addresses - configure the ip address
gateway4 - configure the default gateway
nameservers - configure the dns servers
Step 3:
Apply the changes "netplan apply"
Step 4:
Verify the IP "ifconfig"
Verify the default gateway "route -n"
Voila! QED!