Skip to content

Instantly share code, notes, and snippets.

@tmcolby
Last active December 21, 2019 18:12
Show Gist options
  • Save tmcolby/45b9aff831d951c927ad67f1df298460 to your computer and use it in GitHub Desktop.
Save tmcolby/45b9aff831d951c927ad67f1df298460 to your computer and use it in GitHub Desktop.
docker dhcp server on localhost

https://hub.docker.com/r/networkboot/dhcpd/

How to use

The most common use-case is to provide DHCP service to the host network of the machine running Docker. For that you need to create a configuration for the DHCP server, start the container with the --net host docker run option and specify the network interface you want to provide DHCP service on.

Create data folder.

Create data/dhcpd.conf with a subnet clause for the specified network interface. If you need assistance, you can run docker run -it --rm networkboot/dhcpd man dhcpd.conf for a description of the configuration file syntax. Run docker run -it --rm --init --net host -v "$(pwd)/data":/data networkboot/dhcpd net0. dhcpd will automatically start and display its logs on the console. You can press Ctrl-C to terminate the server.

..But, FIRST:

set the interfaces static address sudo ifconfig net0 172.17.1.1
then add a default route to your local machine sudo route add -net 172.17.1.0/32 gw 172.17.1.1 netmask 255.255.255.0 so that you can reach devices that have been assigned addresses from the dhcp server.

now you can run the dhcp server docker run -it --rm --init --net host -v "$(pwd)/data":/data networkboot/dhcpd net0

default-lease-time 86400;
max-lease-time 86400;
authoritative;
log-facility local7;
subnet 172.17.1.0 netmask 255.255.255.0{
range 172.17.1.100 172.17.1.200;
option domain-name "subdomain.example.io";
option domain-name-servers 8.8.8.8, 8.8.4.4;
option routers 172.17.1.1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment