【问题标题】:iptables Drop Policy will drop my accept rules [closed]iptables Drop Policy 将删除我的接受规则 [关闭]
【发布时间】:2014-05-14 08:41:58
【问题描述】:

我已经设置了几个 iptables 规则,最后我将策略设置为 Drop 但它会放弃一切,甚至我的规则

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:

链输入(策略接受 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(策略接受 0 个数据包,0 个字节)

pkts bytes target prot opt in out source destination

链输出(策略接受 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

【问题讨论】:

    标签: http ssh iptables policy


    【解决方案1】:

    您已经掌握了基础知识,但它们有些混乱。 INPUT 需要源 ip 和目标端口,OUTPUT 需要目标 ip 和源端口。传入的流量将是NEWESTABLISHED,从服务器服务(在客户端/服务器设计中)传出的流量将是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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-04
      • 2012-04-29
      • 2014-01-30
      • 1970-01-01
      • 2014-03-13
      • 2016-01-09
      • 2015-05-17
      • 1970-01-01
      相关资源
      最近更新 更多