Ubuntu IP Address Change Print

  • 0

Ubuntu: Change Server IP/Subnet (Netplan) – ens33

This guide is for already-active servers where the NIC is known (ens33) and you are migrating to a new IP/subnet.

Warning (SSH users): Changing IP/subnet can disconnect your session. Use netplan try when possible.

1) Find your Netplan file

ls -l /etc/netplan/

Common filenames include 00-installer-config.yaml or 01-netcfg.yaml.


2) Edit the Netplan YAML

Open the config file (replace the filename):

sudo nano /etc/netplan/00-installer-config.yaml

Update these fields for the new subnet:

  • addresses (new IP/CIDR)
  • gateway4 (new gateway in the new subnet)
  • nameservers (optional but recommended)

Example (Static IPv4 on ens33):

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: no
      addresses: [10.20.30.40/24]
      gateway4: 10.20.30.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
Important: YAML indentation matters. Use spaces only (no tabs).

3) Validate & apply (safe method)

Generate/validate configuration:

sudo netplan generate

Recommended for remote servers: Try the change with auto-revert:

sudo netplan try

If networking works, confirm in the prompt to keep it.

Or apply directly (can disconnect immediately):

sudo netplan apply

4) Verify the new subnet is active

ip -br a show ens33
ip route
ping -c 3 10.20.30.1
resolvectl status

Common problems

  • Gateway must match the new subnet (example: if your new IP is 10.20.30.40/24, gateway should typically be 10.20.30.1).
  • Wrong prefix (/24 vs /23 vs /26) will break routing. Ensure CIDR is correct.
  • If your provider requires a special route setup (e.g., gateway not in-subnet), you may need explicit routes. See official docs below.

Official references:


Was this answer helpful?

« Back