Change the IP address of a Proxmox host

Change the IP address of a Proxmox host

Proxmox has come a long way since 2008, and the amount that can be configured in the frontend is quite staggering, but sometimes you long for the good old days and want to drop into the terminal. It's just Debian, after all... Hello? Where's everyone gone? Ok, fine, let's start with changing the IP through the web UI:

Changing the IP through the Web UI

There are two changes to make. First, go to System > Network, choose the 'Linux Bridge' interface and click Edit. Enter the new IP here and click OK.

Now click 'Apply Configuration' and the system will reload the network configuration.

Now go to System > Hosts, change the IP address on the line with the hostname and click Save.

Changing the IP with a One-Liner

TL;DR: here's a one-liner:
sed -i 's/oldip/newip/g' /etc/network/interfaces /etc/hosts && systemctl restart networking

The above UI changes are essentially just updating these files:

  • /etc/network/interfaces - This updates the actual NIC/interface address
  • /etc/hosts - If a server hostname is in the hosts file, a system won't perform a DNS lookup for that address. Therefore, host/IP pairings in the hosts file need to be correct.

While you could edit both files manually, change the old IP to the new IP, that's just not as fun as using a one-liner to do it for you! In this example, 192.168.10.177 is the old IP and 192.168.10.10 is the new IP:

# The first command will show you the proposed changes
# without editing any files:

root@prox:~# sed 's/192.168.10.177/192.168.10.10/g' /etc/network/interfaces /etc/hosts
auto lo
iface lo inet loopback

iface enp3s0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 192.168.10.10/24
        gateway 192.168.10.1
        bridge-ports enp3s0
        bridge-stp off
        bridge-fd 0

iface wlp2s0 inet manual
127.0.0.1 localhost.localdomain localhost
192.168.10.10 delta.local delta

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

___________________________________________________________________

# Adding -i will edit the file in place:

root@prox:~# sed -i 's/192.168.10.177/192.168.10.10/g' /etc/network/interfaces /etc/hosts
root@prox:~# systemctl restart networking

### One-liner ###

root@prox :~# sed -i 's/192.168.10.177/192.168.10.10/g' /etc/network/interfaces /etc/hosts && systemctl restart networking
If you're changing more than just the IP address (i.e. you're changing the network/subnet mask/default gateway too), you'll probably want to manually edit both files or edit through the Web UI.

If you can do it with a one-liner, I'm certainly going to try. Hopefully, this helps you, but if you think I've missed something, please leave a comment or let me know over at @techbitsio.



Great! Next, complete checkout for full access to techbits.io
Welcome back! You've successfully signed in
You've successfully subscribed to techbits.io
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated