Skip to content

Commit f36963f

Browse files
committed
add proxy-DHCP support via dnsmasq
1 parent 25ef084 commit f36963f

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66

77
## Overview
88

9-
The [netboot.xyz docker image](https://github.com/netbootxyz/docker-netbootxyz) allows you to easily set up a local instance of netboot.xyz. The container is a small helper application written in node.js. It provides a simple web interface for editing menus on the fly, retrieving the latest menu release of netboot.xyz, and enables mirroring the downloadable assets from Github to your location machine for faster booting of assets.
9+
The [netboot.xyz docker image](https://github.com/netbootxyz/docker-netbootxyz) allows you to easily set up a local instance of netboot.xyz. The container is a small helper application written in node.js. It provides a simple web interface for editing menus on the fly, retrieving the latest menu release of netboot.xyz, and enables mirroring the downloadable assets from Github for faster booting of assets.
1010

1111
![netboot.xyz webapp](https://netboot.xyz/images/netboot.xyz-webapp.jpg)
1212

13-
It is a great tool for developing and testing custom changes to the menus. If you have a machine without an optical drive that cannot boot from USB then having a local netboot server provides a way to install an OS. If you are looking to get started with netboot.xyz and don't want to manage iPXE menus, you should use the boot media instead of setting up a container.
13+
It is a great tool for developing and testing custom changes to the menus. If you have a machine without an optical drive that cannot boot from USB, then having a local netboot server provides a way to install an OS. If you are looking to get started with netboot.xyz and don't want to manage iPXE menus, you should use the boot media instead of setting up a container.
1414

1515
The container is built upon Alpine Linux and contains several components:
1616

1717
* netboot.xyz [webapp](https://github.com/netbootxyz/webapp)
1818
* Nginx for hosting local assets from the container
19-
* tftp-hpa
19+
* tftp server (dnsmasq)
2020
* syslog for providing tftp activity logs
21+
* optional proxy-DHCP mode
2122

2223
Services are managed in the container by [supervisord](http://supervisord.org/).
2324

2425
The container runs fine under ARM-based hosts as well as x86-64.
2526

2627
## Usage
2728

28-
The netboot.xyz docker image requires an existing DHCP server to be setup and running in order to boot from it. The image does not contain a DHCP server service. Please see the DHCP configuration setup near the end of this document for ideas on how to enable your environment to talk to the container. In most cases, you will need to specify the next-server and boot file name in the DHCP configuration. Your DHCP server will need to be assigned a static IP.
29+
The netboot.xyz docker image requires an existing DHCP server to be set up and running in order to boot from it by default. The image does not contain a full DHCP server service by default, but it **includes an optional proxy-DHCP mode**. Please see the DHCP configuration setup near the end of this document for ideas on how to enable your environment to talk to the container. In most cases, you will need to specify the next-server and boot file name in the DHCP configuration, or enable the proxy-DHCP mode. Your DHCP server will need to be assigned a static IP if using the default mode.
2930

3031
### Installing docker
3132

@@ -59,6 +60,7 @@ docker run -d \
5960
-e MENU_VERSION=2.0.76 `# optional` \
6061
-e NGINX_PORT=80 `# optional` \
6162
-e WEB_APP_PORT=3000 `# optional` \
63+
-e DHCP_RANGE_START=192.168.0.1 `# optional, enables DHCP Proxy mode. set to your network's DHCP range first IP` \
6264
-p 3000:3000 `# sets web configuration interface port, destination should match ${WEB_APP_PORT} variable above.` \
6365
-p 69:69/udp `# sets tftp port` \
6466
-p 8080:80 `# optional, destination should match ${NGINX_PORT} variable above.` \
@@ -96,13 +98,13 @@ docker compose up -d netbootxyz # start containers in the background
9698

9799
Once the container is started, the netboot.xyz web application can be accessed by the web configuration interface at `http://localhost:3000` or via the specified port.
98100

99-
Downloaded web assets will be available at `http://localhost:8080` or the specified port. If you have specified the assets volume, the assets will be available at `http://localhost:8080`.
101+
Downloaded web assets will be available at `http://localhost:8080` or the specified port. If you have specified the assets volume, the assets will be available at `http://localhost:8080`.
100102

101103
If you wish to start over from scratch, you can remove the local configuration folders and upon restart of the container, it will load the default configurations.
102104

103105
### Local Mirror Access
104106

105-
If you want to pull the Live Images images down from your own mirror, modify the boot.cfg file and override the default `live_endpoint` setting from `https://github.com/netbootxyz` and set it to your deployment IP or domain, e.g. `http://192.168.0.50:8080`. It will then redirect asset download to the local location you set for assets on port `8080` and you can download the assets by using the local assets menu down to your local server. This can result in a much faster boot and load time.
107+
If you want to pull the Live Images down from your own mirror, modify the boot.cfg file and override the default `live_endpoint` setting from `https://github.com/netbootxyz` and set it to your deployment IP or domain, e.g. `http://192.168.0.50:8080`. It will then redirect asset downloads to the local location you set for assets on port `8080` and you can download the assets using the local assets menu to your local server. This can result in a much faster boot and load time.
106108

107109
## Parameters
108110

@@ -117,16 +119,19 @@ Container images are configured using parameters passed at runtime (such as thos
117119
| `-e NGINX_PORT=80` | Specify a different port for NGINX service to listen on. |
118120
| `-e MENU_VERSION=2.0.76` | Specify a specific version of boot files you want to use from netboot.xyz (unset pulls latest) |
119121
| `-e TFTPD_OPTS='--tftp-single-port'` | Specify arguments for the TFTP server (this example makes TFTP send all data over port 69) |
122+
| `-e DHCP_RANGE_START=192.168.0.1` | Optionally enables DHCP Proxy mode. Set to your network's DHCP range first IP |
120123
| `-v /config` | Storage for boot menu files and web application config |
121124
| `-v /assets` | Storage for netboot.xyz bootable assets (live CDs and other files) |
122125

123126
## DHCP Configurations
124127

125-
This image requires the usage of a DHCP server in order to function properly. If you have an existing DHCP server, usually you will need to make some small adjustments to make your DHCP server forward requests to the netboot.xyz container. You will need to typically set your `next-server` and `boot-file-name` parameters in the DHCP configuration. This tells DHCP to forward requests to the TFTP server and then select a boot file from the TFTP server.
128+
This image requires the usage of a DHCP server in order to function properly, unless you enable the **optional proxy-DHCP mode**. If you have an existing DHCP server, you will need to make some small adjustments to forward requests to the netboot.xyz container. You will typically set your `next-server` and `boot-file-name` parameters in the DHCP configuration. This tells DHCP to forward requests to the TFTP server and then select a boot file from the TFTP server.
129+
130+
If you prefer not to modify your existing DHCP server, you can enable the **proxy-DHCP mode** by setting the `DHCP_RANGE_START` environment variable to the first IP in your DHCP range (e.g. 192.168.1.1). This mode allows netboot.xyz to provide PXE boot configuration while your existing DHCP server continues to handle IP address assignment.
126131

127132
### Examples
128133

129-
These are a few configuration examples for setting up a DHCP server. The main configuration you will need to change are `next-server` and `filename/boot-file-name`. `Next-server` tells your client to check for a host running tftp and retrieve a boot file from there. Because the docker image is hosting a tftp server, the boot files are pulled from it and then it will attempt to load the iPXE configs directly from the host. You can then modify and adjust them to your needs. See [booting from TFTP](https://netboot.xyz/docs/booting/tftp/) for more information.
134+
These are a few configuration examples for setting up a DHCP server. The main configuration you will need to change are `next-server` and `filename/boot-file-name`. `next-server` tells your client to check for a host running tftp and retrieve a boot file from there. Because the docker image is hosting a tftp server, the boot files are pulled from it and then it will attempt to load the iPXE configs directly from the host. You can then modify and adjust them to your needs. See [booting from TFTP](https://netboot.xyz/docs/booting/tftp/) for more information.
130135

131136
#### isc-dhcp-server
132137

@@ -195,3 +200,4 @@ The following bootfile names can be set as the boot file in the DHCP configurati
195200
| `netboot.xyz-arm64-snp.efi` | UEFI w/ Simple Network Protocol, attempts to boot all net devices |
196201
| `netboot.xyz-arm64-snponly.efi` | UEFI w/ Simple Network Protocol, only boots from device chained from |
197202
| `netboot.xyz-rpi4-snp.efi` | UEFI for Raspberry Pi 4, attempts to boot all net devices |
203+
```

docker-compose.yml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
- MENU_VERSION=2.0.47 # optional
99
- NGINX_PORT=80 # optional
1010
- WEB_APP_PORT=3000 # optional
11+
- DHCP_RANGE_START=192.168.0.1 # optional, enables DHCP Proxy mode. set to your network's DHCP range first IP
1112
volumes:
1213
- /path/to/config:/config # optional
1314
- /path/to/assets:/assets # optional

root/defaults/dnsmasq-dhcpproxy.conf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Only used if DHCP_RANGE_START is set, requires ENV vars changed via envsubst
2+
# DHCP Proxy range and enable verbose DHCP logging
3+
dhcp-range=${DHCP_RANGE_START},proxy
4+
log-dhcp
5+
leasefile-ro
6+
7+
# Prevents reusing servername and filename fields to avoid confusing old clients
8+
dhcp-no-override
9+
10+
# Disable multicast/broadcast discovery, and instruct client to download the boot file immediately
11+
dhcp-option=vendor:PXEClient,6,2b
12+
13+
# Based on logic in https://gist.github.com/robinsmidsrod/4008017
14+
# iPXE sends a 175 option, checking suboptions
15+
dhcp-match=set:ipxe-http,175,19
16+
dhcp-match=set:ipxe-https,175,20
17+
dhcp-match=set:ipxe-menu,175,39
18+
# pcbios specific
19+
dhcp-match=set:ipxe-pxe,175,33
20+
dhcp-match=set:ipxe-bzimage,175,24
21+
dhcp-match=set:ipxe-iscsi,175,17
22+
# efi specific
23+
dhcp-match=set:ipxe-efi,175,36
24+
# combination
25+
# set ipxe-ok tag if we have correct combination
26+
# http && menu && iscsi ((pxe && bzimage) || efi)
27+
tag-if=set:ipxe-ok,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-pxe,tag:ipxe-bzimage
28+
tag-if=set:ipxe-ok,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-efi
29+
30+
# Match BIOS PXE clients
31+
dhcp-match=set:bios,60,PXEClient:Arch:00000
32+
# Match UEFI 32-bit PXE clients
33+
dhcp-match=set:efi32,60,PXEClient:Arch:00002
34+
# Match UEFI 32-bit (variant 1) PXE clients
35+
dhcp-match=set:efi32-1,60,PXEClient:Arch:00006
36+
# Match UEFI 64-bit PXE clients
37+
dhcp-match=set:efi64,60,PXEClient:Arch:00007
38+
# Match UEFI 64-bit (variant 1) PXE clients
39+
dhcp-match=set:efi64-1,60,PXEClient:Arch:00008
40+
# Match UEFI 64-bit (BC variant) PXE clients
41+
dhcp-match=set:efi64-2,60,PXEClient:Arch:00009
42+
# Match ARM64 UEFI clients
43+
dhcp-match=set:arm64-efi,60,PXEClient:Arch:0000A
44+
# Match Raspberry Pi 4 (aarch64) architecture based on Option 60 (PXEClient vendor class)
45+
dhcp-match=set:rpi4,60,PXEClient:Arch:00011:UNDI:003000
46+
47+
# Serve appropriate bootloaders for non-iPXE clients (initial PXE boot)
48+
# Legacy BIOS (not iPXE)
49+
pxe-service=tag:bios,tag:!ipxe-ok,X86PC,"Legacy BIOS",netboot.xyz-undionly.kpxe
50+
# UEFI 32-bit (not iPXE)
51+
pxe-service=tag:efi32,tag:!ipxe-ok,BC_EFI,"UEFI 32-bit",netboot.xyz.efi
52+
# UEFI 64-bit (not iPXE)
53+
pxe-service=tag:efi64,tag:!ipxe-ok,X86-64_EFI,"UEFI 64-bit",netboot.xyz.efi
54+
# ARM64 UEFI (not iPXE)
55+
pxe-service=tag:arm64-efi,tag:!ipxe-ok,ARM64_EFI,"ARM64 UEFI",netboot.xyz-arm64.efi
56+
# Raspberry Pi Boot (using rpi4 tag, not iPXE)
57+
pxe-service=tag:rpi4,tag:!ipxe-ok,0,"Raspberry Pi Boot",netboot.xyz-rpi4-snp.efi
58+
59+
# DHCP Boot options for non-iPXE clients using envsubst for dynamic IP handling
60+
dhcp-boot=tag:bios,netboot.xyz.kpxe,,${CONTAINER_IP}
61+
dhcp-boot=tag:efi32,netboot.xyz.efi,,${CONTAINER_IP}
62+
dhcp-boot=tag:efi32-1,netboot.xyz.efi,,${CONTAINER_IP}
63+
dhcp-boot=tag:efi64,netboot.xyz.efi,,${CONTAINER_IP}
64+
dhcp-boot=tag:efi64-1,netboot.xyz.efi,,${CONTAINER_IP}
65+
dhcp-boot=tag:efi64-2,netboot.xyz.efi,,${CONTAINER_IP}
66+
dhcp-boot=tag:rpi4,netboot.xyz-rpi4-snp.efi,,${CONTAINER_IP}

root/init.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ mkdir -p \
1616
[[ ! -f /config/nginx/site-confs/default ]] &&
1717
envsubst </defaults/default >/config/nginx/site-confs/default
1818

19-
# create dnsmasq config
19+
# create dnsmasq config, and conditionally add DHCP proxy support
2020
if [[ ! -f /config/dnsmasq/dnsmasq.conf ]]; then
2121
cp /defaults/dnsmasq.conf /config/dnsmasq/dnsmasq.conf
22+
23+
if [ -n "${DHCP_RANGE_START}" ]; then
24+
echo "[netbootxyz-init] Enabling DHCP Proxy mode for DHCP_RANGE_START=${DHCP_RANGE_START}"
25+
26+
# Get the container's IP address using hostname if not already set
27+
if [ -z "${CONTAINER_IP}" ]; then
28+
CONTAINER_IP=$(hostname -i)
29+
export CONTAINER_IP
30+
fi
31+
envsubst </defaults/dnsmasq-dhcpproxy.conf >>/config/dnsmasq/dnsmasq.conf
32+
fi
2233
fi
2334

2435
# Ownership

0 commit comments

Comments
 (0)