ubuntu 22.04 assign ethernet static ip

Some routers don’t have a DHCP reservation feature, such as the Bell Home Hub 3000, Home Hub 4000, Giga Hub. These models do allow for setting a reserved DHCP range. E.g.

Assign IP from 20 and up. That leaves 2-19 free to use.

On Ubuntu 22.04, the plan is:

Install netplan.io apt install netplan.io

Verify the cable is actually connected using ip link

n# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:83:41:29:5e:69 brd ff:ff:ff:ff:ff:ff
3: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 1c:83:41:29:5e:6a brd ff:ff:ff:ff:ff:ff
4: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether 70:cf:49:9d:93:79 brd ff:ff:ff:ff:ff:ff

Seeing LOWER_UP means the data link layer is connected. Seeing UP means IP layer is also established.

Create configuration for the interface

/etc/netplan/01-network-manager-all.yaml

# /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp4s0:
      addresses:
        - 192.168.2.5/32
      routes:
        - to: default
          via: 192.168.2.1
      nameservers:
        addresses: [192.168.2.1, 1.1.1.1]

Here, I wanted 192.168.2.5 for the static IP.

Apply (restart) interface

netplan apply

Verify IP

Can use landscape-sysinfo or ip address

Leave a Reply

Your email address will not be published. Required fields are marked *