Skip to content

Instantly share code, notes, and snippets.

@theodric
Created March 7, 2023 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theodric/8446d974c7989de60cfce59966e480f4 to your computer and use it in GitHub Desktop.
Save theodric/8446d974c7989de60cfce59966e480f4 to your computer and use it in GitHub Desktop.
VPN killswitch
cat /etc/udev/rules.d/81-vpn-firewall.rules
KERNEL=="tun0", ACTION=="add", RUN+="/usr/bin/forward.sh add"
KERNEL=="tun0", ACTION=="remove", RUN+="/usr/bin/forward.sh remove"
cat /usr/bin/forward.sh
#!/bin/bash
#
# forward.sh
# VER 0.1
#
# Reloads the ferm firewall ruleset and is invoked by
# the udev via /etc/udev/rules.d/81-vpn-firewall.rules.
#
#
LOGGER=/usr/bin/logger
LOGGER_TAG=$0
UDEV_ACTION=$1
MSG_FW_RULE_ADD="Enabling forwarding"
MSG_FW_RULE_REMOVE="Disabling forwarding"
MSG_UDEV_ACTION_UNKNOWN="dafuq"
case "$UDEV_ACTION" in
add)
$LOGGER -t $LOGGER_TAG $MSG_FW_RULE_ADD
$FERM $FERM_CONF
sysctl net.ipv4.ip_forward=1
;;
remove)
$LOGGER -t $LOGGER_TAG $MSG_FW_RULE_REMOVE
sysctl net.ipv4.ip_forward=0
$FERM $FERM_CONF
;;
*)
$LOGGER -t $LOGGER_TAG $MSG_UDEV_ACTION_UNKNOWN
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment