Nftables: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Initial Config= # Disable firewalld and enable nftables: ## <code>systemctl disable --now firewalld</code> ## <code>systemctl mask firewalld</code> ## <code>nft flush ruleset</code> ## <code>systemctl enable --now nftables</code> # Create a new inet table called "filter":<br/><code>nft add table inet filter</code> # Create a chain called "INPUT" (in the filter table):<br/><code>nft add chain inet filter INPUT { type filter hook input priority 0 \; policy accept\; }</co...") |
No edit summary |
||
Line 16: | Line 16: | ||
#* ''Probably a good idea to add this last (at the bottom of the chain):'' | #* ''Probably a good idea to add this last (at the bottom of the chain):'' | ||
#* or, better yet... '''log''' and drop traffic:<br/><code>nft add rule inet filter INPUT log prefix \"Dropped\: \" flags all counter drop comment \"default drop all\"</code> | #* or, better yet... '''log''' and drop traffic:<br/><code>nft add rule inet filter INPUT log prefix \"Dropped\: \" flags all counter drop comment \"default drop all\"</code> | ||
=Other Commands= | |||
====List filter table (of type inet), with line/position (handle) numbers==== | |||
<code>nft -a list table inet filter</code> | |||
====Add new rule at a given position==== | |||
(inserts before handle 6) | |||
<code>nft insert rule inet filter INPUT position 6 ip saddr 10.144.91.0/24 udp dport 1812 accept</code> | |||
(inserts after handle 7) | |||
<code>nft add rule inet filter INPUT position 7 ip saddr 10.144.91.0/24 udp dport 1813 accept</code> | |||
====Delete rule at a given position==== | |||
<code>nft delete rule inet filter INPUT handle 5</code> | |||
====List all rules==== | |||
<code>nft list ruleset</code> | |||
====Export all rules to a file==== | |||
<code>nft list ruleset > <file></code> | |||
====Import rules from a file==== | |||
<code>nft -f <file></code> | |||
====Save rules (make changes persistent)==== | |||
<code>nft list ruleset > /etc/sysconfig/nftables.conf</code> |
Revision as of 01:50, 18 November 2023
Initial Config
- Disable firewalld and enable nftables:
systemctl disable --now firewalld
systemctl mask firewalld
nft flush ruleset
systemctl enable --now nftables
- Create a new inet table called "filter":
nft add table inet filter
- Create a chain called "INPUT" (in the filter table):
nft add chain inet filter INPUT { type filter hook input priority 0 \; policy accept\; }
- defines type: filter, hook: input, priority: 0 (highest)
- Create a new rule allowing localhost traffic (in the INPUT chain):
nft add rule inet filter INPUT iif lo accept
- Create a new rule allowing established connections (in the INPUT chain):
nft add rule inet filter INPUT ct state established,related accept
- Create a new rule allowing 80/tcp and 22/tcp (in the INPUT chain):
nft add rule inet filter INPUT tcp dport {80, 22} accept
- Obviously this is optional and dependent on what you're trying to accomplish.
- Create a new rule to count and drop all other traffic (in the INPUT chain):
nft add rule inet filter INPUT counter drop
- Probably a good idea to add this last (at the bottom of the chain):
- or, better yet... log and drop traffic:
nft add rule inet filter INPUT log prefix \"Dropped\: \" flags all counter drop comment \"default drop all\"
Other Commands
List filter table (of type inet), with line/position (handle) numbers
nft -a list table inet filter
Add new rule at a given position
(inserts before handle 6)
nft insert rule inet filter INPUT position 6 ip saddr 10.144.91.0/24 udp dport 1812 accept
(inserts after handle 7)
nft add rule inet filter INPUT position 7 ip saddr 10.144.91.0/24 udp dport 1813 accept
Delete rule at a given position
nft delete rule inet filter INPUT handle 5
List all rules
nft list ruleset
Export all rules to a file
nft list ruleset > <file>
Import rules from a file
nft -f <file>
Save rules (make changes persistent)
nft list ruleset > /etc/sysconfig/nftables.conf