2016-03-06 18:50:33 +03:00
|
|
|
# iptables
|
|
|
|
|
2017-07-20 21:53:15 +03:00
|
|
|
> Program that allows configuration of tables, chains and rules provided by the Linux kernel firewall.
|
2016-03-06 18:50:33 +03:00
|
|
|
|
2018-08-12 19:23:48 +03:00
|
|
|
- View chains, rules, and packet/byte counters for all tables:
|
2016-03-06 18:50:33 +03:00
|
|
|
|
2018-08-12 19:23:48 +03:00
|
|
|
`sudo iptables -vnL`
|
2016-03-06 18:50:33 +03:00
|
|
|
|
|
|
|
- Set chain policy rule:
|
|
|
|
|
2017-12-11 18:36:15 +03:00
|
|
|
`sudo iptables -P {{chain}} {{rule}}`
|
2016-03-06 18:50:33 +03:00
|
|
|
|
|
|
|
- Append rule to chain policy for IP:
|
|
|
|
|
|
|
|
`sudo iptables -A {{chain}} -s {{ip}} -j {{rule}}`
|
|
|
|
|
|
|
|
- Append rule to chain policy for IP considering protocol and port:
|
|
|
|
|
|
|
|
`sudo iptables -A {{chain}} -s {{ip}} -p {{protocol}} --dport {{port}} -j {{rule}}`
|
|
|
|
|
|
|
|
- Delete chain rule:
|
|
|
|
|
|
|
|
`sudo iptables -D {{chain}} {{rule_line_number}}`
|
|
|
|
|
2018-08-12 19:23:48 +03:00
|
|
|
- Save iptables configuration of a given table to a file:
|
2016-03-06 18:50:33 +03:00
|
|
|
|
2018-08-12 19:23:48 +03:00
|
|
|
`sudo iptables-save -t {{tablename}} > {{path/to/iptables_file}}`
|
|
|
|
|
|
|
|
- Restore iptables configuration from a file:
|
|
|
|
|
|
|
|
`sudo iptables-restore < {{path/to/iptables_file}}`
|