Switch Wireguard connection on / off via the digital input RUT 241

Hi folks,

I hope you can help me. I would like to switch my Wireguard connections off and on again via the digital input.
Is the digital input 0 = Wireguard Connections switched off
Is the digital input 1 = wireguard connection switched on

How exactly do I have to do this? Can you help me with this?

Many thanks in advance
Walle

Hello,

To toggle WireGuard connections on and off based on a digital input, you can leverage the I/O Juggler feature on your router and configure it to execute scripts depending on the state of the digital input. Here’s an example guide:


Step 1: Prepare the Scripts

  1. Access the Router’s CLI
    Log in to the router’s Command-Line Interface (CLI) using SSH or directly through a terminal.
  2. Navigate to the /etc Directory
    Run:
cd /etc
  1. Create the Scripts
  • WireGuard ON Script (wgon.sh):
    Create a new file using vi:
vi wgon.sh

Press i to enter insert mode and add the following:

#!/bin/ash
uci set network.<wireguard_interface>.disabled='0'
uci commit network
/etc/init.d/network restart

After making changes, hit Esc and write :wq and press Enter.

Replace <wireguard_interface> with the name of your WireGuard interface. You can find this using the ifconfig command or in WebUI (Services → VPN → Wireguard)

  • WireGuard OFF Script (wgoff.sh):
    Similarly, create another file:
vi wgoff.sh

Press i and add:

#!/bin/ash
uci set network.<wireguard_interface>.disabled='1'
uci commit network
/etc/init.d/network restart
  1. Make the Scripts Executable
    Run the following commands to make the scripts executable:
chmod 777 wgon.sh
chmod 777 wgoff.sh

Step 2: Configure I/O Juggler

  1. Access the WebUI
    Log in to the router’s web interface.
  2. Navigate to I/O Juggler
    Go to Services → Input/Output → I/O Juggler.
  3. Create Actions
  1. Set Up Triggers
  1. Save and Apply Changes
    Click Save & Apply to finalize the configuration.

If you encounter any issues or require further guidance, feel free to ask.

Best regards,

Thanks for the detailed instructions, I will test it and get back to you.

Cheers

It works fine!

Best regards
Walle

Great to hear! If you need further assistance in the future, feel free to reach out.

Kind regards,

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