techbits.io

Change the IP address of a Proxmox host

Why even visit? Here's a one-liner: sed -i 's/oldip/newip/g' /etc/network/interfaces /etc/hosts && systemctl restart networking - You're welcome!

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 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 @techbits@fosstodon.org.

Tagged with: #linux #proxmox

Share this article:

Comments

Related posts

Proxmox: iSCSI LUN as Shared Storage
#proxmox #iscsi #virtualisation

Proxmox: iSCSI LUN as Shared Storage

While checking out an ASUSTOR NAS (the Lockerstor 6 Gen2), I tested various configurations of storage and storage types. As part of that, I set up…

Basic systemctl commands
#linux

Basic systemctl commands

Systemctl is a command line utility that is used to manage services on Linux systems, and if you don't regularly manage Linux systems, you might find…

Sending Proxmox VE 8 Syslogs to a Log Aggregator
#proxmox #debian #linux

Sending Proxmox VE 8 Syslogs to a Log Aggregator

A Log Aggregator or Log Management system allows you to delve into system and software logs for many machines, or create alerts for particular issues…