We already talked about how to Bring Your Home Network Anywhere For Free - Home VPN with Wireguard on Raspberry Pi + Pi-hole (Ubuntu Server 20.04 LTS). It is an awesome thing, especially if you have a static IP address, but if you are like most households in the world (including myself), your internet service provider (ISP) provides you with a dynamic IP address. It means that your home network's IP address changes frequently, even a couple of times a day, so your VPN connection configuration needs to be changed accordingly to keep up.
To solve that, we will utilize the Dynamic DNS solution.
Dynamic DNS is a way of assigning a custom domain name that automatically updates even as the IP address changes. This system has been around long enough that there are workarounds for these kinds of issues. For the purpose of this post, I will use a free DDNS service - No-IP.
Go to the No-IP website and choose some cool hostname and domain: You are required to sign up, so just populate the required fields and complete the registration (email confirmation and stuff). Your hostname will be pre-populated and set up for the currently logged-in IP address.
If you are not logged in from your home network, you need to change the address to point to your home network's IP address.
Once you are done setting up (don't forget to add username, No-IP will complain), we can set up our router to ping No-IP servers whenever our IP address changes.
Router Set Up
My home router is Technicolor CGA2121, but the configuration shouldn't be different for others, just browse a bit around through the configuration options. After this is done, our router should automatically call No-IP API to change the pointing IP address.
When we set up WireGuard on our Raspberry Pi in the previous post, we selected the Public IP option with the current home IP address.
$ cat /etc/pivpn/wireguard/setupVars.conf PLAT=Ubuntu OSCN=focal USING_UFW=0 IPv4dev=eth0 install_user=ubuntu install_home=/home/ubuntu VPN=wireguard pivpnPORT=51820 pivpnDNS1=10.6.0.1 pivpnDNS2= pivpnHOST=<PUBLIC IP ADDRESS> # <- We will change this INPUT_CHAIN_EDITED=0 FORWARD_CHAIN_EDITED=0 pivpnPROTO=udp pivpnMTU=1420 pivpnDEV=wg0 pivpnNET=10.6.0.0 subnetClass=24 ALLOWED_IPS="0.0.0.0/0, ::0/0" UNATTUPG=1 INSTALLED_PACKAGES=(net-tools iptables-persistent wireguard-tools qrencode)
Enter the edit mode for
$ sudo nano /etc/pivpn/wireguard/setupVars.conf
pivpnHOST to point to your DDNS hostname which you created on No-IP -
pivpnHOST=xxxx.ddns.net. Save with
New clients you generate will use the new endpoint but you need to manually edit existing clients.
Open your configuration, for example,
amel.conf, and update the line:
Endpoint = xxxx.ddns.net:51820
I hope this tutorial will help you overcome issues with dynamic IP and help you improve your online being.