Skip to content

Instantly share code, notes, and snippets.

@rjhowe
Created February 3, 2025 19:20
Show Gist options
  • Select an option

  • Save rjhowe/6116c4cd96430d31260ab7c4e30c8b52 to your computer and use it in GitHub Desktop.

Select an option

Save rjhowe/6116c4cd96430d31260ab7c4e30c8b52 to your computer and use it in GitHub Desktop.
AWK to convert dhcp.conf entries to dnsmasq dhcp entries
### DHCP to DNSmasq
awk '
/host/ { if (hostname) print "dhcp-host=" mac "," ip "," hostname; hostname = $2 }
/hardware ethernet/ { mac = $3; sub(";", "", mac) }
/fixed-address/ { ip = $2; sub(";", "", ip) }
END { print "dhcp-host=" mac "," ip "," hostname }
' dhcpd.conf
### DNSmasq to DHCP
awk '
BEGIN { FS=","; }
{
split($1, mac, "=");
print "host " $3 " {";
print " hardware ethernet " mac[2] ";";
print " fixed-address " $2 ";";
print "}";
}
' dnmasq-dhcp.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment