Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
Release and Renew WAN DHCP address in script
« previous
next »
Print
Pages: [
1
]
Author
Topic: Release and Renew WAN DHCP address in script (Read 4130 times)
GeoffW
Newbie
Posts: 29
Karma: 0
Release and Renew WAN DHCP address in script
«
on:
January 09, 2023, 05:30:15 pm »
In the user interface, under Interfaces, Overview, you can expand out the WAN interface and get offed "Reload" and "Renew" buttons that do what I need. How do I do this in a script?
I've been searching all night. dhclient in OPNsense doesn't have a -r option, and anyway, running that appears to result in multiple instance issues; sometimes it looks like it has worked (when you do an ifconfig) but the change never appears on the user interface, so something gets missed, or maybe it's because it's running a separate instance.
Yes, I'm talking the years old problem, known both here and on pfSense, of some modems (in this case NetGear) that don't appropriately notify the DHCP client (whose address comes over the bridge provided by the modem) when the address has changed as the result of a reboot of the modem, or other disruption on their side. The connection is there but OPNsense doesn't know and never gets around to asking.
It appears we're stuck with running a cron job to check whether the network has fallen over and then take action accordingly - and that much I've found examples of here, but the examples I've found resort to rebooting OPNsense, which seems a bit extreme.
I've tried using ifconfig to take the interface down and back up, but that doesn't appear to result in a DHCP renewal ... or is there a hidden option somewhere?
Do I have any other choices, or is a full reboot really it?
(Actually, I suspect there may be another solution: change the modem from bridge to router mode and let it take care of the WAN address change while giving OPNsense a static address. But that adds another layer, so if I can avoid it I will.)
«
Last Edit: January 09, 2023, 05:31:50 pm by GeoffW
»
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: Release and Renew WAN DHCP address in script
«
Reply #1 on:
January 09, 2023, 05:42:36 pm »
The cron job is "Periodic interface reset" on the System: Settings: Cron page. As a parameter it needs the interface identifier you want to reset (lan, wan, optX). The overview or assignments page has this identifier visible nowadays.
I'm aware of the dhclient issue and some day we will address it, but it's never been high on the priority list, see
https://github.com/opnsense/core/issues/2517
Cheers,
Franco
Logged
GeoffW
Newbie
Posts: 29
Karma: 0
Re: Release and Renew WAN DHCP address in script
«
Reply #2 on:
January 10, 2023, 01:18:29 am »
Thanks for the suggestion. I had seen that Cron job but wasn't clear on what it did, and posts here indicated people were using it once-a-day at 3 or 4 am to reset PPPoE connections. It didn't seem likely it was appropriate to run it every 10 minutes on the off-chance the WAN was down.
However, and maybe this was your point, I found the script that "Periodic interface reset" calls and tested calling it from inside my script - and it does seem to do what I need. Thank you very much.
So now my script pings a few different addresses and if they all fail, or if the WAN address as reverted to the NetGear default (192.168.5.*) then I call "
/usr/local/etc/rc.configure_interface wan
" and it does its thing and the OPNsense interface reports consistently throughout, which is great.
I know there is an option to block accepting that NetGear address, but then it also blocks access to the modem management interface until a full connection comes back. I like that it might revert to that and let me still see the modem even if the outer network is still down.
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
Release and Renew WAN DHCP address in script