Created
February 3, 2025 19:20
-
-
Save rjhowe/6116c4cd96430d31260ab7c4e30c8b52 to your computer and use it in GitHub Desktop.
AWK to convert dhcp.conf entries to dnsmasq dhcp entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 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