killswitch 1.1 KB

12345678910111213
  1. # IPv4 kill switch: traffic must be either (1) to the WireGuard interface, (2) marked as a WireGuard packet, (3) to a local address, or (4) to the Docker network
  2. docker_network="$(ip -o addr show dev eth0 | awk '$3 == "inet" {print $4}')"
  3. docker_network_rule=$([ ! -z "$docker_network" ] && echo "! -d $docker_network" || echo "")
  4. iptables -I OUTPUT ! -o $interface -m mark ! --mark $(wg show $interface fwmark) -m addrtype ! --dst-type LOCAL $docker_network_rule -j REJECT
  5. # IPv6 kill switch: traffic must be either (1) to the WireGuard interface, (2) marked as a WireGuard packet, (3) to a local address, or (4) to the Docker network
  6. docker6_network="$(ip -o addr show dev eth0 | awk '$3 == "inet6" {print $4}')"
  7. if [[ "$docker6_network" ]]; then
  8. docker6_network_rule=$([ ! -z "$docker6_network" ] && echo "! -d $docker6_network" || echo "")
  9. ip6tables -I OUTPUT ! -o $interface -m mark ! --mark $(wg show $interface fwmark) -m addrtype ! --dst-type LOCAL $docker6_network_rule -j REJECT
  10. else
  11. echo "Skipping IPv6 kill switch setup since IPv6 interface was not found" >&2
  12. fi