Ubuntu 20.04 doesn't have /etc/network/interfaces
and uses /etc/netplan/<config file>.yaml
instead.
The .yaml
config file is auto generated and can have many names but as long as it has .yaml
extension it should work fine. Mine was 50-cloud-init.yaml
on one machine, 00-installer-config.yaml
on another.
To set the ip to 192.168.0.102
, in /etc/netplan/<config file>.yaml
:
network:
ethernets:
eth0:
dhcp4: false
addresses: [192.168.0.102/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8,8.8.4.4,192.168.0.1]
version: 2
You can look up what your current gateway is using ip route
and put that in instead of 192.168.0.1
Also instead of eth0
you can have a different name for your network. If so, keep your network's name there.
Then sudo netplan apply
This kicked me out of SSH because I was SSHed through an old ip. I had to reboot the computer manually. Restarting router is a good idea too at this point to clear possible ip conflicts.
Also I found suggestions to edit the generator of this yaml file in /etc/cloud
but I found no fool-proof docs how to do this. Instead, Canonical provides https://netplan.io/examples with a whole bunch of copy-paste configurations for the config.yaml
file, which seem like a great approach for most cases.