linux:iptables
差别
这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
linux:iptables [2017/06/29 18:20] – 创建 memory | linux:iptables [2023/12/03 10:24] (当前版本) – 外部编辑 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
====== iptables ====== | ====== iptables ====== | ||
+ | |||
+ | {{user: | ||
+ | |||
+ | 图片来源:[[https:// | ||
===== Usage ===== | ===== Usage ===== | ||
行 7: | 行 11: | ||
service iptables save | service iptables save | ||
- | ===== Rule ===== | + | ===== Options ===== |
+ | |||
+ | ^ option ^ meaning ^ | ||
+ | | -A | append rule | | ||
+ | | -j | jump, '' | ||
+ | | -p | proto, '' | ||
+ | | -s | source, address[/ | ||
+ | | -d | destination, | ||
+ | | -m | match | | ||
+ | |||
+ | ===== Rules ===== | ||
List current iptables rules: | List current iptables rules: | ||
行 17: | 行 31: | ||
iptables -F | iptables -F | ||
- | Drop all traffic(ban all incoming traffic): | + | Allow ping(icmp): |
+ | |||
+ | iptables -A INPUT -p icmp -j ACCEPT | ||
- | iptables -A INPUT -j DROP | ||
- | | ||
Open ports: | Open ports: | ||
行 29: | 行 43: | ||
iptables -A INPUT -p tcp -s [ip] -j ACCEPT | iptables -A INPUT -p tcp -s [ip] -j ACCEPT | ||
iptables -A OUTPUT -p tcp -d [ip] -j ACCEPT | iptables -A OUTPUT -p tcp -d [ip] -j ACCEPT | ||
+ | |||
+ | Allow NTP traffic for time synchronization: | ||
+ | |||
+ | iptables -A OUTPUT -p udp --dport 123 -j ACCEPT | ||
+ | iptables -A INPUT -p udp --sport 123 -j ACCEPT | ||
+ | |||
+ | Allow established connections **important**: | ||
+ | |||
+ | iptables -A INPUT -m state --state ESTABLISHED, | ||
+ | |||
+ | Drop all other traffic(ban all incoming traffic) **put this to bottom**: | ||
+ | |||
+ | iptables -A INPUT -j DROP | ||
+ | |||
+ | ===== Router ===== | ||
+ | |||
+ | Redirect all dns query to specified ip: | ||
+ | |||
+ | iptables -t nat -A PREROUTING -p udp -s 192.168.1.0/ | ||
+ | |||
+ | Redirect all dns query to specified ip except some ip: | ||
+ | |||
+ | iptables -t nat -A PREROUTING -p udp -s 192.168.1.24 -j ACCEPT | ||
+ | iptables -t nat -A PREROUTING -p udp -s 192.168.1.0/ | ||
+ | |||
+ | |||
+ | ===== Reference ===== | ||
+ | |||
+ | * [[https:// |
linux/iptables.1498731639.txt.gz · 最后更改: 2023/12/03 10:24 (外部编辑)