Setting Up Static IP in Ubuntu

ubuntu server homelab

Determining Network Interface Card (NIC) name

sudo lshw -c network

Under the Ethernet Interface copy the logical name.

Finding Netmask

ip a

Against the NIC name you should see a sequence of the format XXX.XXX.XXX.XXX/YY.

Where XXX.XXX.XXX.XXX is the dynamically assigned IP address and YY is the Netmask. Copy the Netmask.

Finding Default Gateway

ip r | grep 'default'

Copy the sequence of the format ZZZ.ZZZ.ZZZ.ZZZ which is the Default Gateway.

Creating Configuration File

cd /etc/netplan

If you already have a file similar to 00-installer-config.yaml modify it else create one.

network:
version: 2
ethernets:
<name>:
dhcp4: false
addresses:
- XXX.XXX.XXX.XXX/YY
routes:
- to: default
via: ZZZ.ZZZ.ZZZ.ZZZ
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

where,

Testing and Applying Changes

sudo netplan try

If there are no errors press Enter to apply the changes.