1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-23 22:15:28 +02:00

iptables: update page (#10713)

* iptables: adding `--line-numbers` to list example
* iptables: use long options, add backticks

---------

Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
This commit is contained in:
Miroslav Shubernetskiy 2023-09-12 08:54:42 -04:00 committed by GitHub
parent 6f8ca02a42
commit 406f328a4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,34 +3,34 @@
> Program that allows configuration of tables, chains and rules provided by the Linux kernel firewall.
> More information: <https://www.netfilter.org/projects/iptables/>.
- 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}}`