CyberShadow / dhcptest

Cross-platform DHCP test client
https://blog.cy.md/2013/01/10/dhcp-test-client
363 stars 57 forks source link

--bind option is not working on a different machine from the dhcp server #15

Closed mingzhaodotname closed 6 years ago

mingzhaodotname commented 6 years ago

I tried to use --bind option to send out the DHCP request to test the DHCP server on another machine. However, it never receives the DHCP offer from the DHCP server. But I can see the DHCP offer comes back by using dhcpdump.

I also noticed that sometimes it cannot send out the DHCP discovery without --bind.

CyberShadow commented 6 years ago

That's something that would depend on your OS. dhcptest is not doing anything unusual here.

mingzhaodotname commented 6 years ago

Thanks a lot for your reply, and looking into this issue.

I'm testing with Ubuntu 16.04. I created two VMs with Virtualbox. One VM is setup for the DHCP server, and the other VMs runs dhcptest. These two VMs are configured as the same internal network with VirtualBox.

Is there anything wrong with my setting? What would you suggest to use dhcptest so that I can use --bind to received DHCP offer? Thanks so much.

CyberShadow commented 6 years ago

--bind simply selects a specific network interface to use. By default, dhcptest will bind to all interfaces.

dhcptest needs to run as root in order to bind to the DHCP port and receive DHCP answers. Also make sure that there isn't a DHCP client running at the same time.

mingzhaodotname commented 6 years ago

Yes, I do run it as root (e.g. sudo ./dhcptest --bind 192.168.1.3 --query), and I checked that there isn't a DHCP client is running. Actually, if there is one running, I won't be able to run dhcptest because of port conflict :-)

I assume that when I use --bind, dhcptest can still get DHCP OFFER packet. Is that expected or not?

CyberShadow commented 6 years ago

Yes, but only if you specify the local address of the network interface corresponding to the network on which the DHCP server is running.

On Nov 4, 2017 23:37, "Ming Zhao" notifications@github.com wrote:

Yes, I do run it as root (e.g. sudo ./dhcptest --bind 192.168.1.3 --query), and I checked that there isn't a DHCP client is running. Actually, if there is one running, I won't be able to run dhcptest because of port conflict :-)

I assume that when I use --bind, dhcptest can still get DHCP OFFER packet. Is that expected or not?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CyberShadow/dhcptest/issues/15#issuecomment-341948659, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJ0fgUWTGBgrE-RUZkXtgVtOZNY2u_Aks5szTt3gaJpZM4QSQB3 .

mingzhaodotname commented 6 years ago

In my experiment, The DHCP server and dhcptest are on different machines. DHCP server has IP address 192.168.1.105/24, and dhcptest has IP address 192.168.1.3/24. They can ping each other. And when I run: sudo ./dhcptest --bind 192.168.1.3 --query and also run dhcpdump on the same host, I can see that DHCP DISCOVER packet is sent from 192.168.1.3, and also DHCP OFFER packet was received from 192.168.1.105.

So, I should see DHCP OFFER from dhcptest as well, right? But the problem is that I didn't see that. Is there anything wrong with what I did or am I missing anything?

CyberShadow commented 6 years ago

I think that should work, also without --bind. One thing you can look into is checking the MAC addresses. Other than the hardware address in the packet header, there is also another address in the DHCP packet, and by default dhcptest generates a random address for that field. Perhaps the DHCP server is using that address in its reply? In which case you should tell dhcptest to use the MAC address of the real network interface.

rom1212 commented 6 years ago

I found that --bind option doesn't work, even with the --mac option.

Did you test it on Ubuntu before? I'm using ISC-DHCP-SERVER on Ubuntu 16.04.

CyberShadow commented 6 years ago

On Nov 6, 2017 12:18, "romans1212notes" notifications@github.com wrote:

I found that --bind option doesn't work, even with the --mac option.

Did you test it on Ubuntu before?

Yes.

I'm using ISC-DHCP-SERVER on Ubuntu 16.04

Can you attach a packet log?

mingzhaodotname commented 6 years ago

Thanks a lot for looking into this.

I'm attaching logs from both the client side and the server side, including information about the interfaces, dhcptest command, tcpdump, and tcpdump.

Please feel free to let me know if you need anything else. Thanks a lot.

client.log.txt server.log.txt

mingzhaodotname commented 6 years ago

sorry, is there any update :-)?

CyberShadow commented 6 years ago

I added an --iface option, which should work much better than --bind. Please try that instead.

CyberShadow commented 6 years ago

I'm guessing this issue is resolved. Please leave a comment otherwise.