OPNsense Forum

English Forums => Virtual private networks => Topic started by: yhq_34 on February 22, 2021, 02:05:20 am

Title: wireguard dynamic WAN IP
Post by: yhq_34 on February 22, 2021, 02:05:20 am
Hi,

Is there any way to keep updating WAN IP if the ip was changed? I have found my site to site VPN was disconnected when one side WAN IP was changed.
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on February 22, 2021, 08:46:55 am
You can have the client on the side with changing IPs. Otherwise a script could check your tunnel and restart WG if necessary...
Title: Re: wireguard dynamic WAN IP
Post by: yhq_34 on February 25, 2021, 01:50:37 am
OK, is there a setting exist in the opnsense to complete this action?
Title: Re: wireguard dynamic WAN IP
Post by: jp0469 on February 27, 2021, 03:09:10 pm
I have a peer to peer Wireguard VPN set up and both networks use dynamic DNS to point to their respective public IPs. When I set up the endpoints, I used their hostnames instead of IP addresses and it seemed to work. I don't know how often they are checked and neither IP has changed since I set up the tunnel but I'm hoping it will work seamlessly.
Title: Re: wireguard dynamic WAN IP
Post by: shuvitcrew on February 27, 2021, 09:17:26 pm
Wireguard will work with host names as well, but will hang after a reboot of the system. You have to start the service after a reboot manually.
Title: Re: wireguard dynamic WAN IP
Post by: jp0469 on February 28, 2021, 04:10:50 pm
Wireguard will work with host names as well, but will hang after a reboot of the system. You have to start the service after a reboot manually.
Any idea how often the hostnames are resolved or is it a continuous thing?
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on February 28, 2021, 04:48:18 pm
ONCE, when the tunnel is started. Never afterwards, even if the DynDNS get's updated and therefore the tunnel fails...
Title: Re: wireguard dynamic WAN IP
Post by: Layer8 on April 03, 2022, 08:53:42 pm
I am running wg site 2 site with opnsense at links with dynamic IPs. So the IPs change mininimum every month while updating opnsense.

Quote
ONCE, when the tunnel is started. Never afterwards, even if the DynDNS get's updated and therefore the tunnel fails...

Is this still the case?

Is there a workaround/script/something like that to solve this problem?
Title: Re: wireguard dynamic WAN IP
Post by: zerwes on April 04, 2022, 06:25:15 am
I can confirm: DNS resolution is only done once at the initialization of the connection.
On client side you can run something like this as bash script via cron as root:
WGNAME=wg0; SRVDNS=$(sed '/^Endpoint */!d;s/^.*= *//g;s/:.*$//g' /etc/wireguard/$WGNAME.conf); CONIP=$(wg show $WGNAME | sed '/endpoint:/!d;s/ *endpoint: //g;s/:.*$//g'); DNSIP=$(dig +noall +answer $SRVDNS | sed '/\tA\t/!d;s/^.*\tA\t//g'); if [ "$CONIP" != "$DNSIP" ]; then ifdown $WGNAME: sleep 1; ifup $WGNAME; fi
Title: Re: wireguard dynamic WAN IP
Post by: Layer8 on April 04, 2022, 12:54:57 pm
Thank you. Will test this script.

I also opened a feature request here: https://github.com/opnsense/plugins/issues/2927

If you are interested in this, please support it on github.
Title: Re: wireguard dynamic WAN IP
Post by: zerwes on April 04, 2022, 05:55:47 pm
IMHO this is a classical job for monit, nothing that needs to be fixed upstream.
Title: Re: wireguard dynamic WAN IP
Post by: ferazop on June 01, 2022, 12:19:22 pm
You will probably have to change the IP addresses in your client profiles, yes. To solve this automatically, get a cheap domain and setup dynamic dns with that, or use a free dynamic dns service. And then setup Wireguard to work with your new domain or dyndns name.
techzpod (https://techzpod.com/) download mobdro (https://get-mobdrovip.com)
Title: Re: wireguard dynamic WAN IP
Post by: Vilhonator on June 01, 2022, 02:54:29 pm
You will probably have to change the IP addresses in your client profiles, yes. To solve this automatically, get a cheap domain and setup dynamic dns with that, or use a free dynamic dns service. And then setup Wireguard to work with your new domain or dyndns name.

That is pretty much easiest option.

To make wireguard (or any service which is dependent on public IP), you need to have either static IP or own domain which DNS A record can be updated using dynamic DNS service.

For VPN more complicated way would be using IPv6 address (those don't change if I'm not mistaken), but setting that to work, is less painfull than sticking a fork in your eye.
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on November 06, 2022, 11:54:07 am
Unfortunately this issue has never been resolved for opnsense, while in the GUI of pfsense you can choose a time interval for "Endpoint Hostname Resolve Interval" under VPN -> WG -> Settings.

I don't want to mess around with script/cron stuff for basic tunnel functionality. Any solution in sight?
Title: Re: wireguard dynamic WAN IP
Post by: Greelan on November 06, 2022, 12:33:46 pm
I assume you are aware that the WG script for this (same as what pfSense uses) has been added to OPNsense: https://github.com/opnsense/plugins/pull/2956

The only thing missing is a convenient button in the UI to configure the running interval for the script. But not that much more work to set up the cron job
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on November 06, 2022, 01:47:26 pm
A cron job might be in reach for me, coding GUI not... :-(

Thanks for the info anyways...

PS: Ok, I had a look in System -> Settings -> Cron, is this the "Renew DNS for Wireguard on stale connections" entry in the drop-down?

Does it really check for stale connections? Or should I simply run it every 3 min or so?

Many thanks in advance!
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on November 06, 2022, 03:26:20 pm
PPS: My local networking nerd evaluated that the underlying script of this cron job mentioned above checks for handshakes and if too long ago it restarts the wg instance. Hope I got it correct...
Title: Re: wireguard dynamic WAN IP
Post by: meyergru on November 06, 2022, 05:30:20 pm
Correct. The script checks if the last handshake was longer than 135 seconds ago and if so, restarts the connection, resulting in a new DNS lookup if name-based endpoints are used.
Title: Re: wireguard dynamic WAN IP
Post by: chemlud on November 06, 2022, 06:25:43 pm
Thanks for confirming! 8)