From 15c9047cb8f47813d4d71ca36c4445d767d9230b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=B6rbitz?= Date: Fri, 5 Nov 2021 00:36:44 +0100 Subject: [PATCH] iptables, nft: add masquerade example (#6979) --- pages/linux/iptables.md | 4 ++++ pages/linux/nft.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pages/linux/iptables.md b/pages/linux/iptables.md index 5b1db1769..8a182af39 100644 --- a/pages/linux/iptables.md +++ b/pages/linux/iptables.md @@ -19,6 +19,10 @@ `sudo iptables -A {{chain}} -s {{ip}} -p {{protocol}} --dport {{port}} -j {{rule}}` +- Add a NAT rule to translate all traffic from the `192.168.0.0/24` subnet to the host's public IP: + +`sudo iptables -t {{nat}} -A {{POSTROUTING}} -s {{192.168.0.0/24}} -j {{MASQUERADE}}` + - Delete chain rule: `sudo iptables -D {{chain}} {{rule_line_number}}` diff --git a/pages/linux/nft.md b/pages/linux/nft.md index 5373b3aa2..bb844b263 100644 --- a/pages/linux/nft.md +++ b/pages/linux/nft.md @@ -20,6 +20,10 @@ `sudo nft add rule {{inet}} {{filter}} {{input}} {{tcp}} {{dport \{ telnet, ssh, http, https \} accept}}` +- Add a NAT rule to translate all traffic from the `192.168.0.0/24` subnet to the host's public IP: + +`sudo nft add rule {{nat}} {{postrouting}} ip saddr {{192.168.0.0/24}} {{masquerade}}` + - Show rule handles: `sudo nft --handle --numeric list chain {{family}} {{table}} {{chain}}`