noxrepo / pox

The POX network software platform
https://noxrepo.github.io/pox-doc/html/
Apache License 2.0
619 stars 470 forks source link

Clients IPs are not changed with DHCP #282

Closed MohsenBs closed 1 year ago

MohsenBs commented 1 year ago

Hi

I am using Meininet that install on Ubuntu 20.04

image image

MurphyMc commented 1 year ago

If I remember right, POX's default address pool implementation rotates the entries it serves by default, so this is probably because dhclient itself is requesting the same address and POX is granting it. You could confirm this by watching the DHCP traffic with Wireshark or something.

It wouldn't be too hard to tweak POX's server to not allow the client to re-request the same address. But if all you want to do is get a new address, I think in the past I have done this by just messing with dhclient. Specifically, dhclient keeps track of the addresses it has previously leased in a file somewhere. You could just delete this file before requesting a new address, but I think I've had success telling it to use /dev/null as the file, since that obviously can't actually save the lease information.

TLDR: I think if you stick -lf /dev/null into your dhclient command line, it might do what you want.

You could also try using udhcpc (from busybox) instead of dhclient. I've found it better suited for experimental configurations.

MohsenBs commented 1 year ago

Thank you for your continuous support that gives us motivation to learn.

I use (-lf /dev/null) as you see still takes the same address

image
MohsenBs commented 1 year ago

If I remember right, POX's default address pool implementation rotates the entries it serves by default, so this is probably because dhclient itself is requesting the same address and POX is granting it. You could confirm this by watching the DHCP traffic with Wireshark or something.

It wouldn't be too hard to tweak POX's server to not allow the client to re-request the same address. But if all you want to do is get a new address, I think in the past I have done this by just messing with dhclient. Specifically, dhclient keeps track of the addresses it has previously leased in a file somewhere. You could just delete this file before requesting a new address, but I think I've had success telling it to use /dev/null as the file, since that obviously can't actually save the lease information.

TLDR: I think if you stick -lf /dev/null into your dhclient command line, it might do what you want.

You could also try using udhcpc (from busybox) instead of dhclient. I've found it better suited for experimental configurations.

I also use the below command : $ dhclient -r $ rm /var/lib/dhcp/dhclient*
$ dhclient

same problem

MurphyMc commented 1 year ago

Try editing pox/proto/dhcpd.py line 444.

It's currently:

        offer = pool[0]

Try this instead:

        import random
        offer = random.choice(pool)
MohsenBs commented 1 year ago

-lf /dev/null The address has not changed, but it is taking random, not sequential

image image
MurphyMc commented 1 year ago

POX is not logging any releases. This is because dhclient is not successfully sending it because it tries to unicast it to the server, which requires that it ARP for the server's Ethernet address. But there is no actual server to respond to the ARP request. Run the POX component proto.arp_responder --no-learn --10.0.0.254 (changing the IP address to be whatever your DHCP server's IP address is supposed to be).

I tested this and it basically worked, but it turned up a bug in dhcpd (I don't think I've ever had a reason to actually use releases). I tried to fix it and pushed it to halosaur.