jpmikkers / DHCPServer

Managed DHCP server implementation, written in C#
MIT License
65 stars 24 forks source link

Provide instructions and demo how to successfully run dhcp server on Linux Ubuntu #21

Open jpmikkers opened 7 months ago

n-ice-ch commented 7 months ago

Hi,

This could be a source for information: https://stackoverflow.com/questions/74940771/not-receiving-broadcast-udp-messages-when-binding-to-specific-address

jpmikkers commented 7 months ago

Binding to 0.0.0.0 is a bad idea for a DHCP server, it will start handing out IP leases on all your subnets.

From here https://stackoverflow.com/questions/13666789/receiving-udp-broadcast-packets-on-linux it seems I may have to bind another socket to the subnet broadcast address (e.g. 192.168.42.255) to receive broadcast packets on Linux.

jpmikkers commented 7 months ago

@n-ice-ch I've created a test setup with ubuntu in virtualbox, indeed it seems broadcast packets are dropped somewhere. Disabling ufw doesn't help. I suspected my router, but the broadcasts arrive fine when I send them from ubuntu to windows. .To be continued..

jpmikkers commented 7 months ago

Here's the issue: https://github.com/dotnet/runtime/issues/83525. The workaround looks clunky, will try it tomorrow.

jpmikkers commented 7 months ago

Update: got it working on Ubuntu , so the trick is to bind to 0.0.0.0:67 but before that do a SO_BINDTODEVICE (bind to a specific nic) so it will only act as a DHCP server on that nic's subnet.

see https://github.com/jpmikkers/DHCPServer/blob/netcore/DHCPServer/Library/UDPSocketLinux.cs

Meanwhile, in that branch I've refactored the code a lot to use async/await, still needs some work in the main app though.

n-ice-ch commented 7 months ago

Sounds promising.

I've worked with IPAddress.Any for meanwhile. In my case it does not matter which subnet to serve as I use it as simple PXE.

But on Linux I can serve BIOS requests only. For EFI it does not work with IPAddress.Any.

So I'm very interested on your research.

n-ice-ch commented 3 months ago

Update: got it working on Ubuntu , so the trick is to bind to 0.0.0.0:67 but before that do a SO_BINDTODEVICE (bind to a specific nic) so it will only act as a DHCP server on that nic's subnet.

see https://github.com/jpmikkers/DHCPServer/blob/netcore/DHCPServer/Library/UDPSocketLinux.cs

Meanwhile, in that branch I've refactored the code a lot to use async/await, still needs some work in the main app though.

Did you get any update for the issue on Linux?