Hello,
I have a 4G router that changes public ip every time I turn it off + another router with openwrt connected at the back + wireguard installed.
The problem is that wireguard keeps in memory the last connection ip, so every time the network is started, no connection to wireguard.
I found a troubleshooting solution while waiting for the development of wg-dynamic :
#Install :
opkg update && opkg install openssh-client openssh-keygen
#Create the RSA key :
ssh-keygen -t rsa -b 4096 #do not put a passphrase for the key, left empty
#Transfer the public key :
cat ~/.ssh/id_rsa.pub | ssh root@serverIP "cat - >> ~/.ssh/authorized_keys"
#Test the connection :
ssh -i ~/.ssh/id_rsa root@serverIP
#Configure an alias for this connection, to create this file :
nano ~/.ssh/config
#Add :
Host wgssh # what you want, I use wgssh for the example
HostName serverIP
User root
IdentityFile ~/.ssh/id_rsa
Port 22
#Test the connection :
ssh wgssh
#The command to restart the wireguard interface server from openwrt :
ssh -t wgssh 'systemctl restart wg-quick@wg0.service ; /bin/bash' & exit
#I chose cron to run the command every time I start openwrt, another possible solution:
export VISUAL=nano; crontab -e
#Add :
@reboot ssh -t wgssh 'systemctl restart wg-quick@wg0.service ; /bin/bash' & exit
#Or in Luci in Local Startup add the line before exit 0
#Important : wireguard must be started with systemd on the server, if not:
wg-quick down wg0
systemctl start wg-quick@wg0.service
If you have any suggestions to improve the trick or better solution to propose, please leave a comment.