Start/stop GL-X750's wireguard client from shell

I would like to control the built-in wireguard client (which works great) from the shell. I’ve seen snippets of code but none seems to work
Is there a definative guide on how to connect/disconnect a pre-exisiting client?

/etc/init.d/wireguard stop

/etc/init.d/wireguard restart

This results in the following code containing

uci: Entry not found
.....
Cannot find device "wg0"

the message means wireguard is not started.

Ok - This wireguard configuration works from the gui but it seems that this CLI approach doesn’t work… Is there another route?

What if in my wireguard config file I’ve several “peers” (i.e. WG server endpoints) and I want to start up WG client choosing specifically one of them?
Thanks

It’s not really possible. You can use uci for it, to set the right peer … but that’s trial and error.

I see… well I might be wrong… but technically, since the web interface allows exactly that task, I should be able to achieve the same results from the terminal…
Is the web interface using UCI in the background?
In this case could you please suggest the UCI command I should try to address a specific peer in wg client startup?

Thank you @admon.
Just sharing for anyone who may be interested.
Here’s a basic script for changing my wg server endpoint and applying different vpn policy.
It seems working like a charm. Firewall rules gets updated automatically, triggered by the change of state of the wgclient interface.

#!/bin/sh

#Turning VPN down
uci set network.wgclient.disabled='1'
ubus -v call network.interface.wgclient down
ubus -v call network reload

echo "VPN is down"
sleep 2

#Change policy (e.g. 0 is for global proxy, 3 is for Target domain policy)
uci set vpnpolicy.route_policy.proxy_mode='3'
uci commit vpnpolicy

echo "Policy updated..."
sleep 1

#Choosing peer
uci set network.wgclient.config='peer_6429'

echo "Wireguard Turkey server selected"


#Turning VPN up
uci set network.wgclient.disabled='0'
ubus -v call network reload

sleep 2

ubus -v call network.interface.wgclient up
echo "VPN Connected!"

That’s cool! Hopefully the peer IDs are not dynamic … :smile:

That’s static, cabled in the wireguard config file…
Another way to achieve the same result (can’t say what’s better) is to call the same method the web interface would use (just fill in group_id & peer_id as per your config):

curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"wg-client\",\"start\",{\"group_id\":xxx,\"peer_id\":xxx}],\"id\":1}"```