sce/roles/configure_firewall/templates/nft.conf.j2
Ivo C.S. Wingelaar 67681b6fdc
Add firewall configuration role
This role is intended for simple port forwarding via `nftables` rules.
2024-10-10 22:12:08 +02:00

25 lines
788 B
Django/Jinja

# {{ ansible_managed }}
# type nat
# The chain type will be NAT
# hook prerouting
# Apply the rules to the prerouting hook
# priority filter + 1
# Set the priority (which determine the order in which
# rules are evaluated to the predefined `filter` value).
# Flush and recreate the entire table
# https://unix.stackexchange.com/questions/537030/nftables-flush-delete-when-changing-or-creating-new-table
table inet {{ sce_nft_table_name }}
flush table inet {{ sce_nft_table_name }}
table inet {{ sce_nft_table_name }} {
chain sce_port_mapping {
type nat hook prerouting priority filter + 1;
policy accept;
{% for item in port_mapping %}
{% set from_port, to_port = item.split(':') %}
tcp dport {{ from_port }} counter redirect to :{{ to_port }}
{% endfor %}
}
}