2021-07-26 13:09:41 +03:00
|
|
|
#!/usr/sbin/nft -f
|
|
|
|
#
|
|
|
|
# Initially based on: https://wiki.nftables.org/wiki-nftables/index.php/Simple_ruleset_for_a_server
|
|
|
|
#
|
|
|
|
|
|
|
|
flush ruleset
|
|
|
|
|
2025-01-27 23:04:00 +03:00
|
|
|
# List updated daily by update-firehol-nftables.sh
|
|
|
|
include "/etc/nftables/firehol_level1-ipv4.nft"
|
2021-07-29 10:16:00 +03:00
|
|
|
|
2021-07-26 13:09:41 +03:00
|
|
|
# Notes:
|
|
|
|
# - tables hold chains, chains hold rules
|
|
|
|
# - inet is for both ipv4 and ipv6
|
|
|
|
table inet filter {
|
2025-01-27 23:04:00 +03:00
|
|
|
set firehol_level1-ipv4 {
|
2021-07-27 22:03:23 +03:00
|
|
|
type ipv4_addr
|
2021-07-26 13:09:41 +03:00
|
|
|
# if the set contains prefixes we need to use the interval flag
|
|
|
|
flags interval
|
2025-01-27 23:04:00 +03:00
|
|
|
elements = $FIREHOL_LEVEL1_IPV4
|
2021-07-31 21:46:50 +03:00
|
|
|
}
|
|
|
|
|
2021-07-27 22:03:23 +03:00
|
|
|
chain input {
|
2021-07-26 13:09:41 +03:00
|
|
|
type filter hook input priority 0;
|
|
|
|
|
2021-07-30 09:37:30 +03:00
|
|
|
ct state {established, related} accept comment "Allow traffic from established and related packets"
|
2021-07-26 13:09:41 +03:00
|
|
|
|
2021-07-30 09:37:30 +03:00
|
|
|
ct state invalid counter drop comment "Early drop of invalid connections"
|
2021-07-26 13:09:41 +03:00
|
|
|
|
2025-01-27 23:04:00 +03:00
|
|
|
ip saddr @firehol_level1-ipv4 counter drop comment "Early drop of incoming packets matching firehol_level1-ipv4 list"
|
2021-07-31 21:46:50 +03:00
|
|
|
|
2021-07-30 09:37:30 +03:00
|
|
|
iifname lo accept comment "Allow from loopback"
|
2021-07-26 13:09:41 +03:00
|
|
|
|
2021-07-30 09:37:30 +03:00
|
|
|
ip protocol icmp limit rate 4/second accept comment "Allow ICMP"
|
|
|
|
ip6 nexthdr ipv6-icmp limit rate 4/second accept comment "Allow IPv6 ICMP"
|
|
|
|
ip protocol igmp limit rate 4/second accept comment "Allow IGMP"
|
2021-07-26 13:09:41 +03:00
|
|
|
|
2021-07-27 21:22:32 +03:00
|
|
|
{# SSH rules #}
|
2021-07-30 09:37:30 +03:00
|
|
|
ip saddr 0.0.0.0/0 ct state new tcp dport 22 counter accept comment "Allow SSH"
|
|
|
|
ip6 saddr ::/0 ct state new tcp dport 22 counter accept comment "Allow SSH"
|
2021-07-27 21:22:32 +03:00
|
|
|
|
|
|
|
{# Web rules #}
|
|
|
|
{% if 'web' in group_names %}
|
2021-07-30 09:37:30 +03:00
|
|
|
ip saddr 0.0.0.0/0 ct state new tcp dport 80 counter accept comment "Allow HTTP"
|
|
|
|
ip saddr 0.0.0.0/0 ct state new tcp dport 443 counter accept comment "Allow HTTPS"
|
|
|
|
ip6 saddr ::/0 ct state new tcp dport 80 counter accept comment "Allow HTTP"
|
|
|
|
ip6 saddr ::/0 ct state new tcp dport 443 counter accept comment "Allow HTTPS"
|
2021-07-27 21:22:32 +03:00
|
|
|
{% endif %}
|
|
|
|
|
2021-09-28 07:34:25 +03:00
|
|
|
ip saddr 0.0.0.0/0 ct state new udp dport 60001-60003 counter accept comment "Allow mosh"
|
|
|
|
ip6 saddr ::/0 ct state new udp dport 60001-60003 counter accept comment "Allow mosh"
|
2021-09-05 16:23:42 +03:00
|
|
|
|
2021-07-27 21:22:32 +03:00
|
|
|
{# Extra rules #}
|
|
|
|
{% if extra_iptables_rules is defined %}
|
|
|
|
{% for rule in extra_iptables_rules %}
|
|
|
|
ip saddr {{ ghetto_ipsets[rule.acl].src }} ct state new {{ rule.protocol }} dport {{ rule.port }} counter accept
|
|
|
|
|
|
|
|
{% if ghetto_ipsets[rule.acl].ipv6src is defined %}
|
|
|
|
ip6 saddr {{ ghetto_ipsets[rule.acl].ipv6src }} ct state new {{ rule.protocol }} dport {{ rule.port }} counter accept
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2021-07-26 13:09:41 +03:00
|
|
|
|
|
|
|
# everything else
|
|
|
|
reject with icmpx type port-unreachable
|
2021-07-27 22:03:23 +03:00
|
|
|
}
|
|
|
|
chain forward {
|
|
|
|
type filter hook forward priority 0;
|
|
|
|
}
|
|
|
|
chain output {
|
|
|
|
type filter hook output priority 0;
|
2021-07-29 10:16:00 +03:00
|
|
|
|
2025-01-27 23:04:00 +03:00
|
|
|
ip daddr @firehol_level1-ipv4 counter drop comment "Drop outgoing packets matching firehol_level1-ipv4 list"
|
2021-07-27 22:03:23 +03:00
|
|
|
}
|
2021-07-26 13:09:41 +03:00
|
|
|
}
|