0

I would like to modify iptables after VPN connection. What is the best approach to achieve that ?

I already tried through systemd with a custom unit in NetworkManager dispatcher.d directory but it seems to only work at boot, not if VPN is stopped and restarted - if I wrote it right :

[Unit]
Description=iptables setup
Requires=nordvpnd.service
After=nordvpn.service

[Service]
Type=simple
ExecStart=/usr/local/bin/setup_iptables.sh

[Install]
WantedBy=multi-user.target

I could monitor tun0, if up and configured, parsing the result of :

ip address ls dev tun0

but that would mean delay between update. Ex. test every 5 sec. could mean at least 4 sec. when iptables is not configured as it should.

My last idea would be to run setup_iptables.sh every time /usr/bin/nordvpn is called, but how to achieve that ?

Thanks

0
1

Does /usr/bin/nordvpn return immediately after it is called or does it return after completing the VPN connection?

In the latter case, just rename /usr/bin/nordvpn to /usr/bin/nordvpn.original and create a script /usr/bin/nordvpn that first calls /usr/bin/nordvpn.original and then /usr/local/bin/setup_iptables.sh (this is called a "wrapper script").

If /usr/bin/nordvpn returns immediately, it's harder, because you need in your wrapper script to somehow check if VPN connection has been established (maybe by pinging something particular?) and if yes, then run /usr/local/bin/setup_iptables.sh.

1
  • Very nice : many thanks ! – John Doe Jan 20 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.