tldr/pages/linux/iptables.md

30 lines
1.0 KiB
Markdown
Raw Normal View History

2016-03-06 15:50:33 +00:00
# iptables
> Configure tables, chains and rules of the Linux kernel IPv4 firewall.
> Use `ip6tables` to set rules for IPv6 traffic. See also: `iptables-save`, `iptables-restore`.
> More information: <https://manned.org/iptables>.
2016-03-06 15:50:33 +00:00
- View chains, rules, packet/byte counters and line numbers for the filter table:
2016-03-06 15:50:33 +00:00
`sudo iptables --verbose --numeric --list --line-numbers`
2016-03-06 15:50:33 +00:00
- Set chain [P]olicy rule:
2016-03-06 15:50:33 +00:00
`sudo iptables --policy {{chain}} {{rule}}`
2016-03-06 15:50:33 +00:00
- [A]ppend rule to chain policy for IP:
2016-03-06 15:50:33 +00:00
`sudo iptables --append {{chain}} --source {{ip}} --jump {{rule}}`
2016-03-06 15:50:33 +00:00
- [A]ppend rule to chain policy for IP considering [p]rotocol and port:
2016-03-06 15:50:33 +00:00
`sudo iptables --append {{chain}} --source {{ip}} --protocol {{tcp|udp|icmp|...}} --dport {{port}} --jump {{rule}}`
2016-03-06 15:50:33 +00:00
- Add a NAT rule to translate all traffic from the `192.168.0.0/24` subnet to the host's public IP:
`sudo iptables --table {{nat}} --append {{POSTROUTING}} --source {{192.168.0.0/24}} --jump {{MASQUERADE}}`
- [D]elete chain rule:
2016-03-06 15:50:33 +00:00
`sudo iptables --delete {{chain}} {{rule_line_number}}`