Alex Peck
Alex Peck

Reputation: 4711

Detecting remote DHCP servers in .NET

Using Hyper-V I built a private windows domain which is fenced off from our main network. Ultimately I want to provision this domain for others to use for dev and test, so they can be domain admin.

The domain controller is running the dhcp service (other systems in my domain have dependencies on dhcp). The problem is, if some idiot (i.e. me) accidently connects the domain controller to the main network it will respond to dhcp requests (this is an assumption) and hand out invalid ip configurations.

So, I would like to write a .NET windows service which starts the local dhcp service only when no other dhcp servers are available. Ideally, this would be capable of periodically checking in the background, so if you change your virtual network config while the machine is running, dhcp can be stopped automatically and potential damage is limited.

I'm a bit stuck on how to detect remote dhcp servers. So far I have considered writing a wrapper for the dhcploc command line tool, but is there is a better/simpler alternative that would acheive the objective? Are there any caveats I should be aware of?

Thanks

Upvotes: 1

Views: 657

Answers (2)

Alex Peck
Alex Peck

Reputation: 4711

As suggested by Shay Erlichmen I posted the question on server fault here. It turns out you can specify the DHCP server only assign IP addresses to known MACs. Given that my VMs (can) all have known MACs, I can use this to lockdown the private domain DHCP server.

Upvotes: 1

Jon Grant
Jon Grant

Reputation: 11530

Someone has written a C# network sniffer you could adapt to your purposes, but this would seem overly complicated. There is no built-in DHCP support in the framework, so there is no simple method you can just call. I think for your purposes you are probably best just sticking with wrapping the command line tool as you say you are doing.

Upvotes: 0

Related Questions