Wireguard how-to start and stop via Button

Hi,

I installed another System GLinet MT-300a with OpenWRT 22.03.5. I followed the Wireguard client setup and can connect to my Wireguard Server.
All :+1: so far, OpenWRT installer and GUI performing very well meanwhile (I started with OpenWRT on Linksys WRT54 some days ago.)

Now I would like to be able to switch VPN on via the HW button. I created a simple script in
/etc/rc.button/BTN_1 which reacts well on the button.

#!/bin/sh 

logger "the button was ${BUTTON} and the action was ${ACTION}"

Now to the missing part, how to I stop/start the VPN interface manually?
Is ifdown and ifup a reasonable approach or should it be done differently?

Hi

i tried this

ping 169.254.255.254
PING 169.254.255.254 (169.254.255.254): 56 data bytes
64 bytes from 169.254.255.254: seq=0 ttl=63 time=7.627 ms
64 bytes from 169.254.255.254: seq=1 ttl=63 time=7.753 ms

then

root@dmz1:~# ifdown wg
root@dmz1:~# ping 169.254.255.254
PING 169.254.255.254 (169.254.255.254): 56 data bytes

timeout

then

root@dmz1:~# ifup wg
root@dmz1:~# ping 169.254.255.254
PING 169.254.255.254 (169.254.255.254): 56 data bytes
64 bytes from 169.254.255.254: seq=0 ttl=63 time=8.474 ms
64 bytes from 169.254.255.254: seq=1 ttl=63 time=8.628 ms

wireguard is back

looks like it is the way

1 Like

Somethings things are easier as expected.

For the record the script

root@wlan7:/etc/rc.button# cat /etc/rc.button/BTN_1 
#!/bin/sh 

#logger "the button was ${BUTTON} and the action was ${ACTION}"

WGIF="vpn"

if [ "$ACTION" = "released" ] && [ "$BUTTON" = "BTN_1" ];
then
        logger "Wireguard off"
        /sbin/ifdown ${WGIF}
fi

if [ "$ACTION" = "pressed" ] &&  [ "$BUTTON" = "BTN_1" ];
then                          
        logger "Wireguard on"
        /sbin/ifup ${WGIF}
fi
1 Like

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