DHCP Improvement (Code Attached)

The addon_core_dhcp_server utilizes the standard ISC DHCP server which supports the full DHCP standard.

The only issue is the HA’s code that enumerates/converts YAML into the dhcpd.conf, only accepts three named parameter for each host (ip, mac, name).

This makes sense because it’s a hassle to predict the alternative options and name them all.

However, if the user would like to specify other DHCP options, such as Option 66 (TFTP Server), it makes sense to allow them as it’s the standard and supported by the ISC server.

A simple option is to alter the YAML enumeration (the for host in (bashio:config) loop in the /run.sh script).

This can be valuable for users who need to use TFTP for flashing bricked devices, etc.

I’m not requesting a new feature. I’m simply sharing a simple explanation and code, in the event the HA developers are interested in adding it.

Thank you.

# Create DHCP Hosts by enumerating Host List & Keys (IP, MAC, Name, or DHCP Option)
for host in $(bashio::config 'hosts|keys'); do
    NAME=$(bashio::config "hosts[${host}].name")

    {
        echo "host ${NAME} {"

	# Iterate all Hosts
	for key in $(bashio::config "hosts[${host}]|keys"); do
		VALUE=$(bashio::config "hosts[${host}].${key}")

		# Validate: Named options
		if [[ "${key}" == "ip" ]]; then
			echo "  fixed-address ${VALUE};"
		elif [[ "${key}" == "mac" ]]; then
			echo "  hardware ethernet ${VALUE};"
		
		# Validate: Numeric DHCP Option
		elif [[ "${key}" =~ ^[0-9]+$ ]]; then
			if (( key > 0 && key < 255 )); then
				echo "  option ${key} ${VALUE};"
			fi
		fi
	done

        echo "}"
    } >> "${CONFIG}"
done

You could submit a pull request here: Pull requests · home-assistant/addons · GitHub

1 Like

Thank you.

I received the impression that the community didn’t see any need for the improvement and I thought that I’d save a couple hours of documentation edits and general logistics with a first time contribution – in the event that community members intentionally removed the original DHCP features.

Although to be fair, it also (implicitly) corrects a minor issue where the hostname is added improperly.

At your suggestion I went forward with the pull request and documented. I’ve added example usage in the hope it might help others understand how this can be useful Home Assistant deployments.