Let’s see your current configuration
cat /etc/netplan/00-installer-config.yaml
in this file, our network adapter enp0s3 is getting the IP address through DHCP
before applying static IP we will require a couple of things
your default route
your network adapter name
for knowing your default route
route -n
look for gateway column having destination 0.0.0.0, in this case 192.168.1.1 is default route
for the name of the network adapter
run ip a , and see the highlighted section in the picture below
ip a
we have both of our requirements now let’s assign static IP by editing the file that you saw before
vim /etc/netplan/00-installer-config.yaml
network:
version: 2
ethernets:
# It is the name of your adapter (you will have different)
enp0s3:
# IP addresses you want , multiple also can be give byseparating with comma
addresses: [192.168.1.161/24]
routes:
- to: 0.0.0.0/0
# via is your default route
via: 192.168.1.1
metric: 100
nameservers:
# you can have different DNS server here like for google or cloudfare , 8.8.8.8
addresses: [127.0.0.53]
this change will only run on boot, for a quick reflection run
sudo netplan apply
NOTE: be aware you will lose ssh connection from the terminal if you are accessing remotely