wireguard dynamic WAN IP

Started by yhq_34, February 22, 2021, 02:05:20 AM

Previous topic - Next topic
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.

You can have the client on the side with changing IPs. Otherwise a script could check your tunnel and restart WG if necessary...
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

OK, is there a setting exist in the opnsense to complete this action?

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.

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.
APU2D4, 4GB RAM, 128GB SSD, OPNsense 22.1

Quote from: 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.
Any idea how often the hostnames are resolved or is it a continuous thing?

February 28, 2021, 04:48:18 PM #6 Last Edit: February 28, 2021, 04:51:10 PM by chemlud
ONCE, when the tunnel is started. Never afterwards, even if the DynDNS get's updated and therefore the tunnel fails...
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

I am running wg site 2 site with opnsense at links with dynamic IPs. So the IPs change mininimum every month while updating opnsense.

QuoteONCE, 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?

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

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.

IMHO this is a classical job for monit, nothing that needs to be fixed upstream.

June 01, 2022, 12:19:22 PM #11 Last Edit: June 03, 2022, 02:21:07 PM by ferazop
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 download mobdro

Quote from: 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.

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.

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?
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

felix eichhorns premium katzenfutter mit der extraportion energie

A router is not a switch - A router is not a switch - A router is not a switch - A rou....

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