This is a simple article that explain how to change the IP from dynamic to static.
Step 1: Change IP in Netplan
Ubuntu 22.04 use the latest Netplan as the default network management tool.
Netplan configuration files are written in YAML syntax with a .yaml
file extension. To configure a network interface with Netplan, you need to create a YAML description for the interface, and Netplan will generate the required configuration files for the chosen renderer tool.
Netplan supports two renderers, NetworkManager and Systemd-networkd. NetworkManager is mostly used on Desktop machines, while the Systemd-networkd is used on servers without a GUI.
To see what network cards and the IP that are automatically assigned, we use the following command:
ip link
Output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:a0:98:33:3d:f4 brd ff:ff:ff:ff:ff:ff
Now we can edit the Netplan config by editing the file located in /etc/netplan/:
sudo nano /etc/netplan/00-installer-config.yaml
The file lock like
/etc/netplan/00-installer-config.yaml
network:
version: 2
ethernets:
ens3:
dhcp4: yes
We need to change a few things.
/etc/netplan/00-installer-config.yaml
network:
version: 2
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.1.221/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
When editing Yaml files, make sure you follow the YAML code indent standards. If the syntax is not correct, the changes will not be applied.
Step 2: Appling the settings
Once done, save the file and apply the changes by running the following command:
sudo netplan apply
That’s it! You have assigned a static IP to your Ubuntu server.