DHCP to Static Ubuntu 24.04 LTS

by | Feb 20, 2025 | IT Tips | 0 comments

Ubuntu Server VM

Original DHCP Config

/etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            dhcp4: true
    version: 2

Static

Find the name of your ethernet adaptor. In this case the ethernet adaptor is eth0

 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:16:5e:0a:02:0c brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
    link/ether 01:32:20:42:c2:dc brd ff:ff:ff:ff:ff:ff

Move the old yaml file out of the way

# as root
mv /etc/netplan/50-cloud-init.yaml ~/
# create a new config file
vim /etc/netplan/00-config.yaml
# modify and enter the config using the example below
# make sure the permissions are root only
chmod 600 /etc/netplan/00-config.yaml

Contents of 00-config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 10.73.73.20/24
      routes:
        - to: default
          via: 10.73.73.254
      nameservers:
        addresses: [10.73.73.12, 10.73.73.9]

Finally generate and apply the netplan policy

# as root
netplan generate
netplan apply

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.