set DHCP on proxmox

Francesco04

Member
Oct 1, 2024
30
0
6
Hi everyone, I'm still learning how to use Proxmox fully and I wanted to ask you if there was a way to set up DHCP on Proxmox so that if I move to another network the machine can still connect and I can connect to it.
 
Hey,

I assume you mean that the PVE host uses DHCP instead of a statically configured IP, not setting up a DHCP server on the host.

It is recommended to stick with a static IP for the PVE host, for standalone hosts changing the IP is somewhat straight forward, you basically have to update both
- /etc/network/interfaces
- and /etc/hosts
In a cluster this is more involved.

If you still decide to go with DHCP you can change
Code:
auto vmbr0
iface vmbr0 inet static
    address 192.168.17.15/23
    ...
in /etc/network/interfaces to
Code:
auto vmbr0
iface vmbr0 inet dhcp
But keep in mind you still have to update /etc/hosts manually, as PVE expects this to match its actual IP.
 
Hey,

I assume you mean that the PVE host uses DHCP instead of a statically configured IP, not setting up a DHCP server on the host.

It is recommended to stick with a static IP for the PVE host, for standalone hosts changing the IP is somewhat straight forward, you basically have to update both
- /etc/network/interfaces
- and /etc/hosts
In a cluster this is more involved.

If you still decide to go with DHCP you can change
Code:
auto vmbr0
iface vmbr0 inet static
    address 192.168.17.15/23
    ...
in /etc/network/interfaces to
Code:
auto vmbr0
iface vmbr0 inet dhcp
But keep in mind you still have to update /etc/hosts manually, as PVE expects this to match its actual IP.
thx so much for the help
 
To expand on Hannes’s point: Proxmox VE relies on its current IP being accurately reflected in /etc/hosts. Manually updating this file each time the IP changes can be tedious and error-prone, especially if you're relying on remote access.

If you're using DHCP and want to automate this step, you can add a DHCP client hook at /etc/dhcp/dhclient-exit-hooks.d/:
Bash:
# /etc/dhcp/dhclient-exit-hooks.d/update-etc-hosts

if ([ $reason = "BOUND" ] || [ $reason = "RENEW" ])
then
  sed -i "s/^.*\spve.example.com\s.*$/${new_ip_address} pve.example.com pve/" /etc/hosts
fi
Be sure to replace pve.example.com with your actual Proxmox node hostname. You can verify it using:
Bash:
hostname -A
This ensures your /etc/hosts file stays in sync with your DHCP-assigned IP.
 
Hey,

I assume you mean that the PVE host uses DHCP instead of a statically configured IP, not setting up a DHCP server on the host.

It is recommended to stick with a static IP for the PVE host, for standalone hosts changing the IP is somewhat straight forward, you basically have to update both
- /etc/network/interfaces
- and /etc/hosts
In a cluster this is more involved.

If you still decide to go with DHCP you can change
Code:
auto vmbr0
iface vmbr0 inet static
    address 192.168.17.15/23
    ...
in /etc/network/interfaces to
Code:
auto vmbr0
iface vmbr0 inet dhcp
But keep in mind you still have to update /etc/hosts manually, as PVE expects this to match its actual IP.
question and what if I wanted to change the IP with one of another class instead?
 
To expand on Hannes’s point: Proxmox VE relies on its current IP being accurately reflected in /etc/hosts. Manually updating this file each time the IP changes can be tedious and error-prone, especially if you're relying on remote access.

If you're using DHCP and want to automate this step, you can add a DHCP client hook at /etc/dhcp/dhclient-exit-hooks.d/:
Bash:
# /etc/dhcp/dhclient-exit-hooks.d/update-etc-hosts

if ([ $reason = "BOUND" ] || [ $reason = "RENEW" ])
then
  sed -i "s/^.*\spve.example.com\s.*$/${new_ip_address} pve.example.com pve/" /etc/hosts
fi
Be sure to replace pve.example.com with your actual Proxmox node hostname. You can verify it using:
Bash:
hostname -A
This ensures your /etc/hosts file stays in sync with your DHCP-assigned IP.
ahhhh understand thanks for the help guys
 
question and what if I wanted to change the IP with one of another class instead?
there is no difference between changing the IP or the subnet, both are part of the address, it doesn't matter which part of the address is changed.
 
  • Like
Reactions: Francesco04