drop config for centos 7
[dotFiles.git] / usr / local / bin / zerotier.sh
blobc1570c0ccab9c7769c16e9061fd8119d0e864288
1 #!/usr/bin/env bash
3 # Route between ZeroTier and Physical Networks
4 # Save this file to "/usr/local/bin/zerotier.sh"
5 # and assigned execution "chmod +x /usr/local/bin/zerotier.sh"
8 _nft=/usr/sbin/nft
9 _ztiface=ztqxxxxxxx
10 _interfaces="{ wlp1s0, enp0s2 }"
12 __zerotier_clear() {
13 if $_nft list table inet zerotier >> /dev/null 2>&1; then
14 # https://wiki.nftables.org/wiki-nftables/index.php/List_of_updates_since_Linux_kernel_3.13#6.3
15 # when kernel < 6.3
16 # $_nft table inet zerotier; $_nft flush table inet zerotier; $_nft delete table inet zerotier
17 $_nft destroy table inet zerotier
21 __zerotier_add() {
22 __zerotier_clear
23 $_nft table inet zerotier
25 $_nft create chain inet zerotier zerotier_postrouting \{ type nat hook postrouting priority srcnat\; policy accept\; \}
26 $_nft create chain inet zerotier zerotier_forward \{ type filter hook forward priority filter\; policy accept\; \}
28 $_nft add rule inet zerotier zerotier_postrouting oifname $_interfaces counter masquerade
29 $_nft add rule inet zerotier zerotier_forward iifname $_interfaces oifname $_ztiface ct state related,established counter accept
30 $_nft add rule inet zerotier zerotier_forward iifname $_ztiface oifname $_interfaces counter accept
33 case $1 in
34 add) __zerotier_add ;;
35 clear) __zerotier_clear ;;
36 esac