What's new

Changing WireGuard Interface Address From wgclient.postconf Script?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

HarryMuscle

Senior Member
I use TorGuard as my VPN provider and unfortunately they only remember WireGuard client keys on their servers for a limited period of time so if you're like me and don't use your connecting constantly you have to use their API to re-register the keys. No problem with scripting that via the wgclient.postconf script though.

The issue I'm running into, however, is that the response of that API call returns the IP address that I'm supposed to use for the WireGuard interface. Unfortunately, when the wgclient.postconf script gets called the WireGuard interface hasn't been created yet so I can't change its address.

Doing this from the wgclient-start script won't work either cause the API call that gives me the interface address to use needs to be done before the connection is established. Basically I get the info in wgclient.postconf but I need to apply it in wgclient-start or somehow after the interface is created. I could probably write a temporary file to communicate between the two scripts but I'm not liking that idea, seems too hackish and wastes writes to the flash memory

So I'm wondering if anyone has any idea on how to change the WireGuard interface address from the wgclient.postconf script.

Thanks,
Harry
 
I use TorGuard as my VPN provider and unfortunately they only remember WireGuard client keys on their servers for a limited period of time so if you're like me and don't use your connecting constantly you have to use their API to re-register the keys. No problem with scripting that via the wgclient.postconf script though.

The issue I'm running into, however, is that the response of that API call returns the IP address that I'm supposed to use for the WireGuard interface. Unfortunately, when the wgclient.postconf script gets called the WireGuard interface hasn't been created yet so I can't change its address.

Doing this from the wgclient-start script won't work either cause the API call that gives me the interface address to use needs to be done before the connection is established. Basically I get the info in wgclient.postconf but I need to apply it in wgclient-start or somehow after the interface is created. I could probably write a temporary file to communicate between the two scripts but I'm not liking that idea, seems too hackish and wastes writes to the flash memory

So I'm wondering if anyone has any idea on how to change the WireGuard interface address from the wgclient.postconf script.

Thanks,
Harry
You should be able to change everything in the postconf file. The config about to be used is retrieved in $1. Like
Code:
#!/bin/sh 
CONFIG=$1 
source /usr/sbin/helper.sh 
pc_replace "Address=<your nvram address>" "Address=<your new address>" $CONFIG

Before doing this you could start by dumping the file to see how it looks:
Code:
cat $1 > /tmp/wgc1.conf
 
Call your API in the postconf script, get the IP address and then use the pc_replace utility merlin created to change the IP address in the config file.

See the bottom of


Or, from the startup script, get your IP address from the API and use the wg set command to change the IP address of the interface.
 
HA! The Zeb beat me to it
 
I use TorGuard as my VPN provider and unfortunately they only remember WireGuard client keys on their servers for a limited period of time so if you're like me and don't use your connecting constantly you have to use their API to re-register the keys. No problem with scripting that via the wgclient.postconf script though.

The issue I'm running into, however, is that the response of that API call returns the IP address that I'm supposed to use for the WireGuard interface. Unfortunately, when the wgclient.postconf script gets called the WireGuard interface hasn't been created yet so I can't change its address.

Doing this from the wgclient-start script won't work either cause the API call that gives me the interface address to use needs to be done before the connection is established. Basically I get the info in wgclient.postconf but I need to apply it in wgclient-start or somehow after the interface is created. I could probably write a temporary file to communicate between the two scripts but I'm not liking that idea, seems too hackish and wastes writes to the flash memory

So I'm wondering if anyone has any idea on how to change the WireGuard interface address from the wgclient.postconf script.

Thanks,
Harry
Thinking about this one more time. The interface ip address is actually nothing wireguard concernes itself with. The interface is created using "ip" and then told to be type: wireguard. So, your right. It wont be a part of config file sent to wg from fw. Usually programs scrape and removes this (Address, DNS, etc) information from the config file otherwise wg doesnt start.
But it will play lots of parts when fw sets up firewall and such so just changing the interface address after its up may be a bad idea.

But the postconf script is called really early and later, when fw setup the interface it reads the address from nvram. So you should be able to change the nvram variable in the postconf script and fw will use your new value when setting everything up. Like:
Code:
nvram set wgc1_addr aaa.bbb.ccc.ddd/xx
nvram commit

It may work
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top