Created
December 11, 2017 18:16
-
-
Save rkorotaev/3efa7e6a3b27b6275368820eec04bc24 to your computer and use it in GitHub Desktop.
Домашний файрвол
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/sbin/nft -f | |
flush ruleset | |
# Определяем интерфейсы | |
define nic_wan = ppp0 | |
define nic_lan = wlp1s0 | |
define nic_ip6 = he-ipv6 | |
define nic_n64 = nat64 | |
# Белый IP-адрес выданный провайдером | |
define ipv4_white = a.dd.re.ss | |
table ip nat { | |
chain prerouting { | |
type nat hook prerouting priority 0; | |
} | |
chain postrouting { | |
type nat hook postrouting priority 100; | |
# Делаем NAT | |
oifname $nic_wan snat $ipv4_white | |
} | |
} | |
table inet filter { | |
chain input { | |
type filter hook input priority 0; | |
# Разрешаем работу локального интерфейса | |
iif lo accept | |
# Разрешаем LAN подключиться (DHCP, NDP, DNS, прокси и прочее) | |
iifname $nic_lan accept | |
# Разрешаем SSH | |
tcp dport 22 accept | |
# Разрешаем ICMP для IPv4 | |
ip protocol icmp icmp type { echo-request, echo-reply, destination-unreachable, \ | |
time-exceeded, parameter-problem } accept | |
# Разрешаем ICMP для IPv6 (RFC4890) | |
ip6 nexthdr icmpv6 icmpv6 type { echo-request, echo-reply, destination-unreachable, \ | |
packet-too-big, time-exceeded, parameter-problem } accept | |
# Поддерживаем открытыми уже установленные соединения | |
ct state { established, related } accept | |
# Остальное отбрасываем | |
counter drop | |
} | |
chain forward { | |
type filter hook forward priority 0; | |
# Разрешаем трафик для IPv6-интернета выходить через туннель HE.net | |
iifname $nic_lan oifname $nic_ip6 accept | |
# Разрешаем трафику для IPv4-интернета заходить в NAT64 для преобразования | |
iifname $nic_lan oifname $nic_n64 accept | |
# ... разрешаем NAT64 выходить в IPv4-интернет через VPN | |
iifname $nic_n64 oifname $nic_wan accept | |
# Разрешаем ICMP для IPv4 | |
ip protocol icmp icmp type { echo-request, echo-reply, destination-unreachable, \ | |
time-exceeded, parameter-problem } accept | |
# Разрешаем ICMP для IPv6 (RFC4890) | |
ip6 nexthdr icmpv6 icmpv6 type { echo-request, echo-reply, destination-unreachable, \ | |
packet-too-big, time-exceeded, parameter-problem } accept | |
# Поддерживаем открытыми уже установленные соединения | |
ct state { established, related } accept | |
# Остальное отбрасываем | |
counter drop | |
} | |
chain output { | |
type filter hook output priority 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment