Assign Static IP address in Ubuntu 22.04 server

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

  1. your default route

  2. your network adapter name

for knowing your default route

route -n

look for gateway column having destination, in this case 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
  version: 2
    # It is the name of your adapter  (you will have different)
      # IP addresses you want , multiple also can be give byseparating with comma
      addresses: []
        - to:
          # via is your default route
          metric: 100
        # you can have different DNS server here like for google or cloudfare ,
        addresses: []

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