XY BLOG

XY的BLOG

iptables 常用基本配置

Published on in Posts
Updated on
Short link: https://b.xyzt07.cn/s/2c
Share this post
A ⇄ 文
⚠️ This entry is already over one year old. It may no longer be up to date. Opinions may have changed.

列出规则及行号

iptables -L INPUT --line-numbers

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     udp  --  anywhere             anywhere             udp dpt:tftp
2    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:69
3    ACCEPT     udp  --  anywhere             anywhere             udp dpt:1194
4    INPUT_PING  icmp --  anywhere             anywhere             icmp echo-request
5    ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
6    DROP       all  --  anywhere             anywhere             state INVALID
7    PTCSRVWAN  all  --  anywhere             anywhere
8    PTCSRVLAN  all  --  anywhere             anywhere
9    ACCEPT     all  --  anywhere             anywhere             state NEW
10   ACCEPT     all  --  anywhere             anywhere             state NEW
11   OVPN       all  --  anywhere             anywhere             state NEW
12   ACCEPT     udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc
13   ACCEPT     tcp  --  anywhere             RT-AC66U_B1-35C0.    ctstate DNAT tcp dpt:6443
14   ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:10022
15   INPUT_ICMP  icmp --  anywhere             anywhere
16   DROP       all  --  anywhere             anywhere

删除指定规则

iptables -D INPUT 1(注意,这个1是行号,是iptables -L INPUT --line-numbers 所打印出来的行号)

增加规则

iptables -I INPUT -s 10.7.67.1 -p udp --dport 69 -j ACCEPT  #可不指定-s 表示所有

指定网段

iptables -I INPUT -s 10.7.0.0/16 -p udp --dport 69 -j ACCEPT  #指定网段