From 406f328a4c319158d9ceec08a66a83630dc7253c Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Tue, 12 Sep 2023 08:54:42 -0400 Subject: [PATCH] iptables: update page (#10713) * iptables: adding `--line-numbers` to list example * iptables: use long options, add backticks --------- Co-authored-by: K.B.Dharun Krishna --- pages/linux/iptables.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pages/linux/iptables.md b/pages/linux/iptables.md index 8a182af391..b2a48ce453 100644 --- a/pages/linux/iptables.md +++ b/pages/linux/iptables.md @@ -3,34 +3,34 @@ > Program that allows configuration of tables, chains and rules provided by the Linux kernel firewall. > More information: . -- View chains, rules, and packet/byte counters for the filter table: +- View chains, rules, packet/byte counters and line numbers for the filter table: -`sudo iptables -vnL` +`sudo iptables --verbose --numeric --list --line-numbers` -- Set chain policy rule: +- Set chain [P]olicy rule: -`sudo iptables -P {{chain}} {{rule}}` +`sudo iptables --policy {{chain}} {{rule}}` -- Append rule to chain policy for IP: +- [A]ppend rule to chain policy for IP: -`sudo iptables -A {{chain}} -s {{ip}} -j {{rule}}` +`sudo iptables --append {{chain}} --source {{ip}} --jump {{rule}}` -- Append rule to chain policy for IP considering protocol and port: +- [A]ppend rule to chain policy for IP considering [p]rotocol and port: -`sudo iptables -A {{chain}} -s {{ip}} -p {{protocol}} --dport {{port}} -j {{rule}}` +`sudo iptables --append {{chain}} --source {{ip}} --protocol {{protocol}} --dport {{port}} --jump {{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}}` +`sudo iptables --table {{nat}} --append {{POSTROUTING}} --source {{192.168.0.0/24}} --jump {{MASQUERADE}}` -- Delete chain rule: +- [D]elete chain rule: -`sudo iptables -D {{chain}} {{rule_line_number}}` +`sudo iptables --delete {{chain}} {{rule_line_number}}` -- Save iptables configuration of a given table to a file: +- Save `iptables` configuration of a given [t]able to a file: -`sudo iptables-save -t {{tablename}} > {{path/to/iptables_file}}` +`sudo iptables-save --table {{tablename}} > {{path/to/iptables_file}}` -- Restore iptables configuration from a file: +- Restore `iptables` configuration from a file: `sudo iptables-restore < {{path/to/iptables_file}}`