mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
chore(kb): revise articles about network traffic filtering
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -240,6 +240,7 @@
|
|||||||
"nats",
|
"nats",
|
||||||
"netcat",
|
"netcat",
|
||||||
"nfsmount",
|
"nfsmount",
|
||||||
|
"nftables",
|
||||||
"nindent",
|
"nindent",
|
||||||
"nixos",
|
"nixos",
|
||||||
"nixpkgs",
|
"nixpkgs",
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ iptables-restore '/etc/iptables/rules.v4'
|
|||||||
## Further readings
|
## Further readings
|
||||||
|
|
||||||
- [`nftables`][nftables]
|
- [`nftables`][nftables]
|
||||||
|
- [How to set up a stateful firewall with iptables]
|
||||||
|
- [Simple stateful firewall]
|
||||||
|
|
||||||
### Sources
|
### Sources
|
||||||
|
|
||||||
@@ -103,5 +105,7 @@ iptables-restore '/etc/iptables/rules.v4'
|
|||||||
<!-- Files -->
|
<!-- Files -->
|
||||||
<!-- Upstream -->
|
<!-- Upstream -->
|
||||||
<!-- Others -->
|
<!-- Others -->
|
||||||
[Iptables basics]: https://www.worldstream.com/nl/article/iptables-basics/
|
|
||||||
[Archlinux wiki]: https://wiki.archlinux.org/title/Iptables
|
[Archlinux wiki]: https://wiki.archlinux.org/title/Iptables
|
||||||
|
[How to set up a stateful firewall with iptables]: https://evilshit.wordpress.com/2013/12/17/how-to-set-up-a-stateful-firewall-with-iptables/
|
||||||
|
[Iptables basics]: https://www.worldstream.com/nl/article/iptables-basics/
|
||||||
|
[Simple stateful firewall]: https://wiki.archlinux.org/title/Simple_stateful_firewall
|
||||||
|
|||||||
@@ -42,57 +42,121 @@ This allows to conveniently manage rules using files.
|
|||||||
```sh
|
```sh
|
||||||
# List tables.
|
# List tables.
|
||||||
nft list tables
|
nft list tables
|
||||||
nft list tables inet
|
nft list tables 'family_type'
|
||||||
|
|
||||||
# Add tables for the IPv4 and IPv6 layers.
|
|
||||||
nft add table inet 'net_table'
|
|
||||||
|
|
||||||
# Add tables for the ARP layer.
|
|
||||||
nft add table arp 'arp_table'
|
|
||||||
|
|
||||||
# Add a base chain called 'input_filter' to the inet 'base_table' table.
|
|
||||||
# Register it to the 'input' hook with priority 0 and type 'filter'.
|
|
||||||
nft add chain inet 'base_table' 'input_filter' "{type filter hook input priority 0;}"
|
|
||||||
|
|
||||||
# List all rules.
|
# List all rules.
|
||||||
|
nft --handle list ruleset
|
||||||
nft -a list ruleset
|
nft -a list ruleset
|
||||||
|
|
||||||
|
# List chains and rules in tables.
|
||||||
|
nft list table 'family_type' 'table_name'
|
||||||
|
|
||||||
|
# List chains.
|
||||||
|
nft list chains
|
||||||
|
nft list chains 'family_type'
|
||||||
|
|
||||||
# List rules in chains.
|
# List rules in chains.
|
||||||
nft list chain inet 'base_table' 'input_filter'
|
nft list chain 'family_type' 'table_name' 'chain_name'
|
||||||
|
|
||||||
|
# Dry run commands.
|
||||||
|
nft --check …
|
||||||
|
nft -c …
|
||||||
|
|
||||||
|
# Be verbose.
|
||||||
|
nft --echo …
|
||||||
|
nft -e …
|
||||||
|
|
||||||
|
# Add chains.
|
||||||
|
nft add chain 'family_type' 'table_name' 'chain_name' \
|
||||||
|
"{ type 'chain_type' hook 'hook_type' priority 'priority_value' ; policy 'policy' ;}"
|
||||||
|
|
||||||
|
# Edit chains.
|
||||||
|
nft chain 'family_type' 'table_name' 'chain_name' \
|
||||||
|
"{ [ type 'chain_type' hook 'hook_type' device 'device_name' priority 'priority_value' ; policy 'policy_type' ; ] }"
|
||||||
|
|
||||||
# Add rules to chains.
|
# Add rules to chains.
|
||||||
nft add rule inet 'base_table' 'input_filter' tcp dport 80 drop
|
nft add rule 'family_type' 'table_name' 'chain_name' 'handle' 'handle_value' 'statement'
|
||||||
|
|
||||||
# Delete rules.
|
# Delete rules.
|
||||||
nft delete rule inet 'base_table' 'input_filter' handle 3
|
nft delete rule inet 'base_table' 'input_filter' handle 3
|
||||||
|
|
||||||
|
# Clear rules from chains.
|
||||||
|
nft flush chain 'family_type' 'table_name' 'chain_name'
|
||||||
|
|
||||||
|
# Clear rules from tables.
|
||||||
|
nft flush table 'family_type' 'table_name'
|
||||||
|
|
||||||
# Delete chains.
|
# Delete chains.
|
||||||
# Chains can *only* be deleted if they contain no rules *and* they are not used as jump targets.
|
# Chains can *only* be deleted if they contain no rules *and* they are not used as jump targets.
|
||||||
nft delete chain inet base_table input_filter
|
nft delete chain 'family_type' 'table_name' 'chain_name'
|
||||||
|
|
||||||
# Delete tables.
|
# Delete tables.
|
||||||
nft delete table inet 'net_table'
|
nft delete table 'inet' 'net_table'
|
||||||
|
|
||||||
|
# Remove the whole ruleset.
|
||||||
|
# This leaves the system with no firewall.
|
||||||
|
nft flush ruleset
|
||||||
|
|
||||||
|
# Dump the current ruleset.
|
||||||
|
nft --stateless list ruleset > '/path/to/nftables.dump'
|
||||||
|
nft -s list ruleset > '/path/to/nftables.dump'
|
||||||
|
|
||||||
|
# Read commands from files.
|
||||||
|
nft --file 'path/to/file'
|
||||||
|
nft -f 'path/to/file'
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<!-- Uncomment if used
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Real world use cases</summary>
|
<summary>Real world use cases</summary>
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
# List tables.
|
||||||
|
nft list tables
|
||||||
|
nft list tables 'ip'
|
||||||
|
|
||||||
|
# List tables' contents.
|
||||||
|
sudo nft list table 'ip' 'filter'
|
||||||
|
|
||||||
|
# Add tables for the IPv4 and IPv6 layers.
|
||||||
|
nft add table 'inet' 'net_table'
|
||||||
|
|
||||||
|
# Add tables for the ARP layer.
|
||||||
|
nft add table 'arp' 'arp_table'
|
||||||
|
|
||||||
|
# List chains.
|
||||||
|
nft list chains
|
||||||
|
nft list chains 'ip'
|
||||||
|
|
||||||
|
# List rules in chains.
|
||||||
|
nft list chain 'inet' 'base_table' 'input_filter'
|
||||||
|
|
||||||
|
# Add a base chain called 'input_filter' to the inet 'base_table' table.
|
||||||
|
# Register it to the 'input' hook with priority 0 and type 'filter'.
|
||||||
|
nft add chain 'inet' 'base_table' 'input_filter' "{type filter hook input priority 0;}"
|
||||||
|
|
||||||
|
# Edit chains.
|
||||||
|
nft chain 'inet' 'my_table' 'my_input' '{ policy drop ; }'
|
||||||
|
|
||||||
|
# Add rules to chains.
|
||||||
|
nft add rule 'inet' 'base_table' 'input_filter' tcp dport 80 drop
|
||||||
|
|
||||||
|
# Delete chains.
|
||||||
|
nft delete chain 'inet' 'base_table' 'input_filter'
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
-->
|
|
||||||
|
|
||||||
## Further readings
|
## Further readings
|
||||||
|
|
||||||
- [`iptables`][iptables]
|
- [`iptables`][iptables]
|
||||||
|
- [How to Create Secure Stateful Firewall Rules with nftables on Linux]
|
||||||
|
|
||||||
### Sources
|
### Sources
|
||||||
|
|
||||||
- [Gentoo wiki]
|
- [Gentoo wiki]
|
||||||
|
- [Arch wiki]
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Reference
|
Reference
|
||||||
@@ -106,4 +170,6 @@ nft delete table inet 'net_table'
|
|||||||
<!-- Files -->
|
<!-- Files -->
|
||||||
<!-- Upstream -->
|
<!-- Upstream -->
|
||||||
<!-- Others -->
|
<!-- Others -->
|
||||||
|
[Arch wiki]: https://wiki.archlinux.org/title/Nftables
|
||||||
[Gentoo wiki]: https://wiki.gentoo.org/wiki/Nftables
|
[Gentoo wiki]: https://wiki.gentoo.org/wiki/Nftables
|
||||||
|
[How to Create Secure Stateful Firewall Rules with nftables on Linux]: https://www.pc-freak.net/blog/mastering-stateful-firewall-rules-nftables-ultimate-guide/
|
||||||
|
|||||||
Reference in New Issue
Block a user