Follow these steps to assign static IP to Ubuntu server.
If the server was provisioned with CloudInit, do the following first. The filename may vary.
1
sudo cat /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
and make sure it is set to disabled
network: {config: disabled}
Next, you should run the following command to figure out what your nic is and make a note of it because you will need this information when we change the network config.
1
2
3
ip link
Now we need to edit the network config
1
sudo nano /etc/netplan/00-installer-config.yaml
And change it to the below. Make sure to update the nic id. The nic id in the code below is ens3.
1
2
3
4
5
6
7
8
9
10
11
12
13
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.2.xxx/24
routes:
- to: default
via: 192.168.2.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Now apply the changes
1
2
3
sudo netplan apply
Verify the change
1
2
3
ip addr show dev ens3