Closed myfreax closed 3 years ago
Hi @huangyanxiong01, the configuration data is stored in the current user's AppData
directory. Specifically, the following files are used.
The reason there are two directories each for clients and the server is due to how the information is organized. WS4W sees the server as one entity and the clients as another, so it stores data for each of those types in server_data
and clients_data
, respectively. However, WireGuard organizes the data a little differently. Since the server must know about each client, and each client must know about the server, information from both types of entities is combined into a final configuration file that WireGuard can read. These are stored in server_wg
and clients_wg
.
If you want to write a script that updates some configuration, you must be sure that you update all of the appropriate files. In addition, changing the server configuration requires that you sync the conf file with WireGuard using the following command.
wg.exe syncconf <interface> <configuration filename>
Most likely it will look like the following (using the PowerShell syntax to expand the environment variable).
wg.exe syncconf wg_server $env:appdata\WS4W\server_wg\wg_server.conf
You mentioned that you want to change the public IP address. Despite being a server setting in WS4W, this value is ultimately targeted to the config file of the client(s). While you can write a script to update the files, you will still have to apply the new client configuration to all of your clients.
Finally, if there is demand for udpating a certain value programmatically, it can be added as a new verb to the CLI.
Thank your answer. I unlikely program with C# and powerShell.My script is bash script not powerShell script. I will run it with cygwin on windows
#!/bin/bash
ip=$(curl http://api.ipify.org/)
echo $ip
sed -i "s|Endpoint=.*|Endpoint=$ip:51820|" /cygdrive/c/Users/Administrator/AppData/Roaming/WS4W/clients_wg/client.conf
sed -i "s|Endpoint=.*|Endpoint=$ip:51820|" /cygdrive/c/Users/Administrator/AppData/Roaming/WS4W/server_data/wg_server.conf
I will learn C#.Thank your work again
Cool, that is actually a really good idea to auto-detect the public IP. Maybe something I could add to the program. Either way, your script should work. However, remember that the clients are the ones that need to know the endpoint, so updating it on the server machine is not sufficient if the address changes.
A couple other notes:
Thank your work. I want to change public IP address by command. But I don't found app store configuration file. Where is configuration file?