Run script whe openvpn is disabled



  • I've tried to run a script when openvpn goes down, like:
    down '/var/etc/openvpn/route.sh'

    This script simple add a route, but openvpn logs show this warning:
    Failed running command (–up/--down): could not execute external program

    The script is executable, have no error and root is the owner.



  • Not sure if i understand what you are trying to do.
    What is your final goal?
    If you want to add a route when the tunnel goes down:

    Create a static route and add the same route as two higher-prioritised routes to the "custom commands" field.

    eg:
    Add a static route for 10.0.0.0/24 pointing to 172.16.0.2
    When the tunnel is up 10.0.0.0/24 should be routed to the other side of the tunnel (tunnelsubnet 192.168.0.0/29)
    –>custom commands:
    route 10.0.0.0 255.255.255.128; route 10.0.0.128 255.255.255.128

    in the routing table it would look like this:

    IPv4
    Destination Gateway Flags Refs Use Mtu Netif Expire
    10.0.0.0/24 172.16.0.2 UGS 0 0 1500 vr0
    10.0.0.0/25 192.168.0.6 UGS 0 0 1500 tun0
    10.0.0.128/25 192.168.0.6 UGS 0 0 1500 tun0



  • I want to add a route to an MPLS when openvpn goes down.
    Your explanation looks right, i was thinking, how the pfsense will route packets to 10.0.0.10 (for example)if there is two route for the same subnet?
    then I remembered that routers use more especific route first.

    thank you GruensFroeschli, it's resolved for me, but i believe that others may try to call an script for other reasons and get same error, someone can explain why this happen?



  • I don't really know why you had problems. I never really needed up/down scripts on a pfSense yet.
    On linux i once had similar problems but they were actual bugs in OpenVPN itself which i solved by using a different version of OpenVPN.


Log in to reply