我已经设置了几个iptables规则,最后我设置了要删除的策略 但是,即使是我的规则也会丢掉所有的东西
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -s 127.0.0.1 -p tcp -m state --state NEW,ESTABLISHED -m multiport --sports 110,25,143 -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --dport 3690 -j ACCEPT
iptables -A OUTPUT -p tcp -s 127.0.0.1 --sport 3690 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --sport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --sport 22 --dport 22 -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
但我无法访问我的网站或ssh。请帮助,提前谢谢
Iptables -nvL:
Chain INPUT(策略ACCEPT 3158数据包,285K字节)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/0
tcp dpt:3306状态NEW,ESTABLISHED
0 0 ACCEPT tcp -- * * 82.115.26.145 0.0.0.0/0 tcp dpt:3306 state NEW,ESTABLISHED
0 0 ACCEPT tcp -- * * 82.115.26.145 0.0.0.0/0 tcp dpt:3690
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:80 state NEW,ESTABLISHED
0 0 ACCEPT tcp -- * * 82.115.26.145 0.0.0.0/0 tcp spt:22 dpt:22
Chain FORWARD(策略ACCEPT 0包,0字节)
pkts bytes target prot opt in out source destination
Chain OUTPUT(策略ACCEPT 1152数据包,160K字节)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * lo 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT tcp -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:3306 state NEW,ESTABLISHED
0 0 ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/0 state NEW,ESTABLISHED multiport sports 110,25,143
0 0 ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/0 tcp spt:3690
但假设所有链的策略都是DROP
答案 0 :(得分:0)
你有基本面,但他们有点混淆。 INPUT
需要源IP和目标端口,OUTPUT
需要目标IP和源端口。进入的流量将为NEW
或ESTABLISHED
,从服务器服务(在客户端/服务器设计中)流出的流量将为ESTABLISHED
。
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -d x.x.x.x --sport 3306 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --dport 3690 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -d x.x.x.x --sport 3690 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s x.x.x.x --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -d x.x.x.x --sport 22 -m state --state ESTABLISHED -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP