How to change a system IP address

Topic: Networking basics

Summary

Change the IP address of a Linux host by updating netplan, NetworkManager, or /etc/network/interfaces, then applying the config and optionally restarting networking. Use a temporary change with ip addr to test before making it persistent. Have console access if changing the address you are connected from. Use this when renumbering or moving a host to another subnet.

Intent: How-to

Quick answer

  • Persistent: edit netplan (e.g. under the interface set addresses: [NEW_IP/24]) or NM connection (ipv4.addresses); run netplan apply or nmcli con up ID; the new address is applied and may drop existing SSH if you changed the address you are on.
  • Temporary: ip addr flush dev eth0; ip addr add NEW_IP/24 dev eth0; add default route if needed (ip route add default via GATEWAY). Lost on reboot.
  • If you are SSH'd to the host: change in a second session or use a script that adds the new address first (ip addr add) so you can reconnect to the new IP before removing the old one; then remove old and set default route.

Prerequisites

Steps

  1. Choose persistent or temporary

    Temporary: use ip addr and ip route for a quick test; changes are lost on reboot. Persistent: use netplan or NetworkManager so the address survives reboot and is applied on boot.

  2. Apply temporary change

    ip addr flush dev eth0 (removes addresses); ip addr add 192.168.1.20/24 dev eth0; ip route add default via 192.168.1.1. Test connectivity; then apply persistent config if correct.

  3. Apply persistent change (netplan)

    Edit /etc/netplan/*.yaml: set addresses: [NEW_IP/24], gateway4 if needed, nameservers; run netplan apply. If you changed the IP you are connected to, SSH may drop; use console or a second IP to reconnect.

  4. Verify

    ip addr show; ip route; ping gateway and a remote host; ensure no duplicate IP on the subnet (arping or check from another host).

Summary

Change the host IP by updating netplan or NetworkManager (persistent) or with ip addr and ip route (temporary). If you change the address you are connected to, have console or add the new address first so you can reconnect. Use this when renumbering or moving a host to another subnet.

Prerequisites

Steps

Step 1: Choose persistent or temporary

  • Temporary: ip addr and ip route; good for testing; lost on reboot.
  • Persistent: Netplan or NetworkManager; survives reboot and is applied on boot.

Step 2: Apply temporary change

sudo ip addr flush dev eth0
sudo ip addr add 192.168.1.20/24 dev eth0
sudo ip route add default via 192.168.1.1

Verify connectivity; then apply the same in netplan/NM if you want it persistent.

Step 3: Apply persistent change (netplan)

Edit the netplan file (e.g. /etc/netplan/50-cloud-init.yaml): set addresses: [NEW_IP/24], gateway4, and nameservers as needed. Run sudo netplan apply. If the new IP is the one you SSH from, the session may drop; use console or add the new IP first so you can reconnect before removing the old one.

Step 4: Verify

ip addr show eth0
ip route
ping -c 2 GATEWAY

Ensure no other host has the same IP (duplicate IP causes flaky connectivity).

Verification

  • The interface has the new IP; default route is correct; you can reach the gateway and the internet (or intended networks).

Troubleshooting

SSH dropped and cannot reconnect — New IP may be wrong or gateway unreachable; use console to fix config or revert to the old IP.

Duplicate IP — Another host is using the same address; choose a different IP or fix the other host; check with arping or from another machine.

Next steps

Continue to