ventoy / PXE

The open source part of iVentoy.
501 stars 31 forks source link

Enable proxy dhcp to work with currently present and existing dhcp servers on the network. #13

Open jerrywoo96 opened 1 year ago

jerrywoo96 commented 1 year ago

I have a router providing dhcp, and would like iventoy to use proxy dhcp instead of changing dhcp server every time i use iventoy.

ventoy commented 1 year ago

https://iventoy.com/en/doc_ext_dhcp.html

jerrywoo96 commented 1 year ago

No, that is not what i meant. A dhcp in proxy mode provides the next server and boot file information, but does not provide ip addresses. The use case is that, on most consumer routers, it is not possible to configure next server and boot file information, and thus a proxy dhcp server fulfills only this role, while the main dhcp server only hands out ip addresses.

this is an example of dnsmasq.conf that configures dhcp to work in proxy mode and host a tftp file server, where 10.0.0.251 is the proxy dhcp and tftp file server address, working with another dhcp server that hands out ip addresses on another ip address in the network.

port=0

log-queries
log-dhcp

enable-tftp
tftp-root=/tftp

dhcp-range=10.0.0.251,proxy,255.255.255.0

dhcp-userclass=set:iPXE,iPXE
dhcp-boot=tag:iPXE,/boot.ipxe,,10.0.0.251

dhcp-boot=tag:!iPXE,/undionly.kpxe,,10.0.0.251
pxe-service=tag:!iPXE,2,,/ipxe.efi,10.0.0.251
pxe-service=tag:!iPXE,6,,/ipxe.efi,10.0.0.251
pxe-service=tag:!iPXE,7,,/ipxe.efi,10.0.0.251
pxe-service=tag:!iPXE,9,,/ipxe.efi,10.0.0.251
pxe-service=tag:!iPXE,10,,/ipxe.efi,10.0.0.251
pxe-service=tag:!iPXE,11,,/ipxe.efi,10.0.0.251

# https://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
# https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#table-options
# https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#table-processor-architecture
ventoy commented 1 year ago

iVentoy currently doesn't support DHCP proxy mode. So you must provide another DHCP proxy server to work together with the main DHCP server. In iVentoy's eye the main DHCP server and the DHCP proxy server composite one virtual third-part DHCP server.

jerrywoo96 commented 1 year ago

Is there any plan in mind this proxy dhcp feature would be added in the future so that external proxy dhcp is not needed? If not, are you able to provide me the path to the bootfile's location so i can configure the external proxy dhcp server?

N0rbert commented 1 year ago

I find proxyDHCP support very useful too. This is how LTSP and iPXE can work. I do not see proxyDHCP functionality in iventoy 1.0.18.

evmolpos commented 10 months ago

ProxyDHCP may add value and completeness to iventoy supremacy. Later on a backup/restore image fanctionality will be astonishing.

mhaseebliaqat commented 2 months ago

To configure a similar PXE/iPXE boot setup on a MikroTik router, you will need to modify the DHCP and TFTP settings accordingly. Here's how you can translate your dnsmasq configuration into MikroTik commands:

  1. Enable DHCP Server Ensure you have a DHCP server running on your MikroTik for the network range you wish to use. If not, create one:

bash Copy code /ip dhcp-server add address-pool=dhcp_pool interface= lease-time=10m name=dhcp1 /ip dhcp-server network add address=10.0.0.0/24 dns-server= gateway=10.0.0.1 /ip pool add name=dhcp_pool ranges=10.0.0.2-10.0.0.250

  1. Set Up DHCP Boot Options MikroTik uses the next-server and boot-file-name options to point to the TFTP server and the boot file. Here's how you can configure it:

bash Copy code /ip dhcp-server option add code=66 name=tftp-server value="'10.0.0.251'" add code=67 name=boot-file value="'undionly.kpxe'" add code=67 name=ipxe-file value="'boot.ipxe'" Code 66: Specifies the TFTP server IP. Code 67: Specifies the boot file to use for PXE clients.

  1. Assign DHCP Options Based on iPXE and Non-iPXE Clients You can use DHCP options in MikroTik to differentiate between iPXE and non-iPXE clients based on their user class. In your case, you are distinguishing iPXE clients with the tag iPXE. In MikroTik, we can use the following method to replicate this behavior.

a. Create a DHCP Option Set for iPXE Clients bash Copy code /ip dhcp-server option add code=67 name=ipxe-boot value="'boot.ipxe'" b. Create a DHCP Option Set for non-iPXE Clients bash Copy code /ip dhcp-server option add code=67 name=pxe-boot value="'undionly.kpxe'" c. Assign DHCP Options to Specific Clients We use option sets to apply conditions. To differentiate between iPXE and non-iPXE, we need to use a script that checks the DHCP user class (dhcp-client-class). Unfortunately, MikroTik doesn't directly support matching user-class identifiers in the same way that dnsmasq does, so you might have to manually assign or adjust by MAC address.

However, you can manually assign options based on custom rules:

bash Copy code /ip dhcp-server lease add mac-address= address=10.0.0.252 dhcp-option=ipxe-boot add mac-address= address=10.0.0.253 dhcp-option=pxe-boot

  1. Enable TFTP Server on MikroTik If you need the MikroTik router itself to serve the TFTP files, you can use MikroTik's TFTP server feature. This can serve files like undionly.kpxe or boot.ipxe:

bash Copy code /ip tftp add address=10.0.0.251 allow-remote-requests=yes src-path=/tftp-root Make sure the necessary files (boot.ipxe, undionly.kpxe, etc.) are placed in the src-path directory on the router.

  1. Configure the PXE Services MikroTik doesn’t support complex PXE-service tags out of the box, but you can set the boot-file and TFTP options as described above, which would cover basic PXE and iPXE booting.

Summary of MikroTik Configuration Commands: Set up DHCP server and pool. Create DHCP options for TFTP and boot files. Assign DHCP options to clients manually. Optionally, serve files via MikroTik’s TFTP. If your setup requires advanced matching like iPXE detection in user-class, you might need to use scripts or handle that in a more manual way with MikroTik.