Can an interface configuration be defined by a file?

cp /etc/config/network /etc/config/
cat random.wireguard.conf >> /etc/config/network
/etc/init.d/network restart
cp /etc/config/ /etc/config/network



Maybe to help you better you can explain:

What prevents you from adding it to the config, proper?

I don't think that would delete/replace the previous wireguard configuration, and I don't know why you would want to replace network with (that would overwrite your changes). It's good for a backup in case something goes wrong though

it has to be automated, it would be tedious to do it myself and I would definetely forget since I tend to get busy

How exactly do you plan to achieve randomization? The two sides of the VPN must remain in sync with respect to the keys/certs, and in the case of Wireguard, also the interface address. You can't randomize your interface definitions unless you are randomizing on the 'server' side and then distributing the resultant configuration (keys) to the 'client' side. If that is your plan, how would you be exchanging the keys/config to the 'client'?

That's fine, you can automate placing configs too.

That's why I asked. No need to add another layer of abstraction to your script.

It's pretty simple, I had done it before on Ubuntu. I am not sure if I understand your question though. What's being randomized is which server I connect to. My vpn provides a configuration file for all their servers, each server has a different address and key. My script would update both the wgclient and the wg interface to have the same information as the configuration file.

Oh... ok. I thought you were trying to randomize a server type config.
You can use a script with UCI syntax to delete the current VPN config, and then add a new one based on the randomizer.

1 Like

Not sure if I understand. If you are saying I can automate it by replacing the whole network config file, I don't which to do that since that would mean every config file for wireguard has to have that network config file, and these wireguard files can't be updated by luci.

If you are suggesting I can use Frollic's idea, it sounds like a good idea to just use cat, but it doesn't delete the previous wireguard information

Or just the changes you want.

Make your script delete it then (kinda difficult to understand since WG is designed to be anonymous anyways).

You could also use UCI interface commands to erase the WG network interface config in whole - without cat and altering the files.

1 Like

I am not sure if I understand, but I have to go now. I'll look at this in like 8 hours. I hope drafts are saved

Then you don't understand what the script's doing, and why.

So, I went to work only to realize today was saturday (not sunday). Had to drive back. Lol

Then you need to script adding/changing things in config thru uci commands.

1 Like

When I started to deconstruct what each line of your script is doing, I realized that you only ran "/etc/init.d/network restart" once, which is used to apply changes. This means that when you replace the network file with, wireguard is still using the configuration my script provided.

That actually works pretty well. I would need to use uci on random.wireguard.conf (since if I didn't use uci, a lot of complications would arise)

I wonder, is there a way to do this without restarting the whole network config? This is something I just thought about. Every device in the network will lose connection if I do this. This is something I can live with, but it provides much less flexibility because I am not the only user in this network. It would be nice if there was a way, even if that made the script more complicated or lenghty.

I think I understand what you are saying now, I guess there's two ways to go about this

You can try restarting just the wireguard interface:

ifdown <wireguard_interface_name>
ifup <wireguard_interface_name>

You may actually want to down it before changing the config, then up when you're done.

1 Like

That's perfect.

It's very cool how we came to a solution in such a short amount of time (ignoring the time I was absent). Now I just have to hope it works when I finish it and there's no obstacles along the way

Suggestion... start with 2 known good WG configurations and toggle between them. If that works properly, you can expand to the randomized version of it.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.