setup-scripts/setup-nftables

47 lines
991 B
Plaintext
Raw Normal View History

2022-10-28 15:25:47 +00:00
#!/bin/sh
set -e
apt-get -y install nftables
systemctl enable nftables
printf \
'#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
2022-12-23 10:01:48 +00:00
type filter hook input priority 0; policy drop;
2022-10-28 15:25:47 +00:00
# loopback
2022-12-12 11:53:32 +00:00
iifname lo accept
2022-10-28 15:25:47 +00:00
# established/related connections
2022-12-12 11:53:32 +00:00
ct state established,related accept
2022-10-28 15:25:47 +00:00
# invalid connections
2022-12-12 11:53:32 +00:00
ct state invalid drop
2022-10-28 15:25:47 +00:00
# no ping floods
2022-12-12 11:53:32 +00:00
ip protocol icmp icmp type echo-request limit rate 1/second accept
ip6 nexthdr icmpv6 icmpv6 type echo-request limit rate 1/second accept
2022-10-28 15:25:47 +00:00
# HTTP and HTTPS
2022-12-12 11:53:32 +00:00
tcp dport 80 ct state new limit rate 10/second accept
tcp dport 443 ct state new limit rate 100/second accept
2022-10-28 15:25:47 +00:00
# SSH from MiA/MiB
2022-12-12 11:53:32 +00:00
tcp dport 22 ip saddr 83.149.165.216/29 ct state new limit rate 2/second accept
2022-10-28 15:25:47 +00:00
}
chain forward {
2022-12-23 10:01:48 +00:00
type filter hook forward priority 0; policy drop;
2022-10-28 15:25:47 +00:00
}
chain output {
2022-12-23 10:01:48 +00:00
type filter hook output priority 0; policy accept;
2022-10-28 15:25:47 +00:00
# no SSH
2022-12-12 11:53:32 +00:00
tcp dport 22 drop
2022-10-28 15:25:47 +00:00
}
}' > /etc/nftables.conf
systemctl restart nftables