Dynamic IP/DHCP recycle

Hey all,

I have a couple of Dynamic IP/DHCP interfaces on the router, and I was looking for smart ways to recycle/switch IPs on the interface periodically e.g. every 2 weeks. Apart from going into the router and renewing the interface (and possibly even resetting the switch), does anyone have a more automated solution to it?

Thanks in advance

What do you mean by recycle/switch IPs, are you wanting the IPs changed or just a new DHCP request sent out? Are these provided by your ISP or some other DHCP server that you control? Is this your WAN interface?

You could try using “sudo dhclient -r” to release the IP and “sudo dhclient” to renew it; note that if the interface that you’re doing this for provides your access to the router then you’ll lose it once the IP is released.

If it works for what you want you could create small script and add it to cron, probably wait a few seconds between the release and renew though.

Disclaimer, there’s good chance I don’t know what I’m talking about.

Is this really needed? Normally, when DHCP lease time is 50% up, existing lease is renewed, making address semi permanent.
Note: renewal of existing lease doesn’t use dhcp relay, so make sure renew dhcp packets aren’t blocked by firewall along the path.
And for the path you intend to use: Schedule some script that does a health check of dhcp lease, if unhealthy release/renew

I just want a new IP assigned to the interface periodically - the IP is provided directly by the ISP and I have no intermediary DHCP servers that I control in this. The DHCP interface doesn’t give me access to the router so we’re good - it’s just used for outbound traffic.

Thanks for the commands, will test them out next week and report back.

Yes very much needed - the IP assigned never changes unless I force it. The ISP assigns it.

Also you can use task scheduler and VyOS CLI oper commands release dhcp interface ethX
https://docs.vyos.io/en/latest/configuration/system/task-scheduler.html
https://docs.vyos.io/en/latest/automation/command-scripting.html

Thanks, I tried the command but when renewing the interface it gave me the same IP again.

That’s what some dhcp servers do. Even an expired or released lease will be remembered, to try to assign it when same client comes back.
Only if pool depletes, address is handed out to others.
Changing your MAC address could get you another IP. If ISP allows.

Still don’t understand why you need all this though.