DHCP setup - single node

DHCP setup of a single node

This is a specialised case. It does NOT require DHCP static reservations and does NOT rely on DNS resolution. It is therefore easily feasible in a typical homelab setup.

Caution

This setup is NOT meant for clustered nodes. Refer to the other guide if you are looking to set up an entire cluster with DHCP.

Regular installation

  • ISO Installer 1 - set interim static IP, desired hostname (e.g. pvehost); or
  • Debian-based install. 2

Install libnss-myhostname

This is a plug-in module 3 for Name Service Switch (NSS) 4 that will help you resolve your own hostname correctly.

apt install -y libnss-myhostname

Note

This will modify your /etc/nsswitch.conf file automatically.

Clean up /etc/hosts

Remove superfluous static hostname entry in the /etc/hosts file, 5 e.g. remove 10.10.10.10 pvehost.internal pvehost line completely. The result will look like this:

127.0.0.1 localhost.localdomain localhost

# 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

Caution

On regular Debian install, the line to remove is one starting with 127.0.1.1 line. This is NOT to be confused with 127.0.0.1 that shall remain intact.

On a fresh install, this is the second line and can be swiftly removed - also creates a backup of the original:

sed -i.bak '2d' /etc/hosts

Check ordering of resolved IPs

PVE will take the first of the IPs resolved as its default. This can be verified with:

hostname -i
fe80::5054:ff:fece:8594%vmbr0 10.10.10.10

It is more than likely, that your first (left-most) IP is an IPv6 and (unless you have a full IPv6 setup) a link-local one at that - not what you want.

To prefer IPv4, you can modify the default behaviour by adding this specific configuration to /etc/gai.conf file 6 - we will make a backup first:

cp /etc/gai.conf{,.bak}
cat >> /etc/gai.conf <<< "precedence ::ffff:0:0/96 100"

Now hostname -i will yield:

10.10.10.10 fe80::5054:ff:fece:8594%vmbr0

If you have a very basic setup with single IPv4 this will be enough. If you, however, have multiple IPs on multiple interfaces, you might end up with output like this:

192.168.0.10 10.10.10.10 fe80::5054:ff:fe09:a200%enp2s0 fe80::5054:ff:fece:8594%vmbr0

You will need to further tweak which one will get ordered as first by adding, e.g.:

cat >> /etc/gai.conf <<< "scopev4 ::ffff:10.10.10.0/120 1"

This is your preferred IPv4 subnet left-padded with ::ffff: and number of IPv4 subnet mask bits added up to 96, hence this will prefer 10.10.10.0/24 addresses. The check will now yield:

10.10.10.10 192.168.0.10 fe80::5054:ff:fe09:a200%enp2s0 fe80::5054:ff:fece:8594%vmbr0

Interface setup for DHCP

On a standard ISO install, change /etc/network/interfaces 7 bridge entry from static to dhcp and remove statically specified address and gateway:

auto lo

iface lo inet loopback
iface enp1s0 inet manual

auto vmbr0

iface vmbr0 inet dhcp
    bridge-ports enp1s0
    bridge-stp off
    bridge-fd 0

Caution

Debian requires you to set up your own networking for the bridge - if you want the Proxmox starting setup, 8 - as defaults to DHCP on the regular interface.

Restart and verify

Either perform full reboot, or at the least restart networking and pve-cluster service:

systemctl restart networking
systemctl restart pve-cluster

You can check addresses on your interfaces with:

ip -c a

Afterwards, you may wish to check if everything is alright with PVE:

journalctl -eu pve-cluster

It should contain a line such as (with NO errors):

pvehost pmxcfs[706]: [main] notice: resolved node name 'pvehost' to '10.10.10.10' for default node IP address

And that’s about it. You can now move your single node around without experiencing strange woes such as one covered in a separate post.