Open Source DHCP proxy

发布时间 2023-11-01 13:46:47作者: lvmxh
There are several open-source projects: DHCP-replay in github https://github.com/topics/dhcp-relay

Seems https://github.com/Mirantis/dhcp-relay looks good.  And it is  Apache-2.0 license

start a DHCP proxy on a host

git clone https://github.com/Mirantis/dhcp-relay
cd dhcp-relay
make all
 
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=proxy.golang.org go build --tags "netgo osusergo static_build" -ldflags='-s -w -extldflags "-static"' -a -o '/home/user/dhcp-relay/BUILD/dhcp-relay'
 
sudo ./BUILD/dhcp-relay -debug -dhcp-server-address 192.168.122.1 -debug-server localhost:8082

send DHCP request on another host

sudo nmap --script broadcast-dhcp-discover

Check result on DHCP proxy host

Then we can check the logs on the host run DHCP proxy as follow

2023/10/31 02:46:37 DBG | Received  bytes of data from socket
2023/10/31 02:46:37 DBG | Received 358 bytes of data from socket
2023/10/31 02:46:37 INF | --> 0x64080343: DHCP-DISCOVER [316], IfIndex=2, Src=192.168.122.54:68(52:54:00:2f:19:ff), Dst=255.255.255.255:67(ff:ff:ff:ff:ff:ff)
2023/10/31 02:46:37 DBG | Option 82 -> Sub-option: Type=1, Len=1, Data=[32], ASCII="2"
2023/10/31 02:46:37 DBG | Sent 321 bytes of data to socket
2023/10/31 02:46:37 INF | <-- 0x64080343: DHCP-DISCOVER [321], Src=0.0.0.0:67, Dst=192.168.122.1:67
2023/10/31 02:46:40 DBG | Received  bytes of data from socket
2023/10/31 02:46:40 DBG | Received 342 bytes of data from socket
2023/10/31 02:46:40 INF | --> 0x64080343: DHCP-OFFER [297], IfIndex=2, Src=192.168.122.1:67(52:54:00:7e:c2:89), Dst=192.168.122.171:67(52:54:00:2b:ad:08)
2023/10/31 02:46:40 DBG | Boot File Name:
2023/10/31 02:46:40 DBG | Option 82 -> Sub-option: Type=1, Len=1, Data=[32], ASCII="2"
2023/10/31 02:46:40 DBG | Sent 334 bytes of data to socket
2023/10/31 02:46:40 INF | <-- 0x64080343: DHCP-OFFER [292], IfIndex=2, Src=0.0.0.0:67, Dst=255.255.255.255:68

or dump pacakge