V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kmdd33
V2EX  ›  程序员

iptables 添加白名单时出现问题

  •  
  •   kmdd33 · 2018-04-28 22:44:31 +08:00 · 1771 次点击
    这是一个创建于 2182 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目的: https://www.cloudflare.com/ips-v4 把 cloudflare 的这些 ip 段添加到白名单中,从而去除 error 521

    我执行的步骤:

    iptables -I INPUT -p tcp -m multiport --dports http,https -s "103.22.200.0/22" -j ACCEPT

    iptables -I INPUT -p tcp -m multiport --dports http,https -s "103.31.4.0/22" -j ACCEPT

    iptables -I INPUT -p tcp -m multiport --dports http,https -s "104.16.0.0/12" -j ACCEPT

    iptables -I INPUT -p tcp -m multiport --dports http,https -s "108.162.192.0/18" -j ACCEPT

    然后:

    service iptables save

    iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] 这个时候应该这些规则新添加到 /etc/sysconfig/iptables 里面了吧?但是我登录服务器打开这个文件,发现里面没有刚刚新添加的白名单规则啊

    问题 2:当我执行 service iptables restart

    Redirecting to /bin/systemctl restart iptables.service 光标开始停止在下面了

    iptables 目前是激活的状态,请问同学们,我是不是哪里操作错了,如何修正,谢谢。

    7 条回复    2018-04-30 22:16:27 +08:00
    JHerschel
        1
    JHerschel  
       2018-04-28 23:19:01 +08:00
    试试看 iptables-save 呢, 它会把规则输出到 stdout. 然后你再瞧瞧输出.
    kmdd33
        2
    kmdd33  
    OP
       2018-04-28 23:39:16 +08:00
    输入 service iptables save 后显示

    iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]


    但是为什么输入 service iptables restart 后光标停止在下面了?一直在闪的状态
    JHerschel
        3
    JHerschel  
       2018-04-29 00:08:29 +08:00
    嗯,,,,,那你试试 bash -x /etc/init.d/iptables restart, 结合 shell 文件看它卡在哪个位置了.
    kmdd33
        4
    kmdd33  
    OP
       2018-04-29 00:17:34 +08:00
    @JHerschel No such file or directory
    JHerschel
        5
    JHerschel  
       2018-04-29 00:29:09 +08:00
    @kmdd33
    脚本位置可能不一样, 替换成你自己机器的那个位置噻.
    snoopygao
        6
    snoopygao  
       2018-04-29 14:35:37 +08:00 via iPhone
    iptables-save > /etc/iptables.ruls

    vi /etc/network/interfaces


    pre-up iptables-restore < /etc/iptables.ruls
    kmdd33
        7
    kmdd33  
    OP
       2018-04-30 22:16:27 +08:00
    @snoopygao 看我这笨脑子,没看明白你要表达的意思
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   981 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:09 · PVG 04:09 · LAX 13:09 · JFK 16:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.