digimoon
V2EX  ›  问与答

centos7 如何在 iptables 载入规则前先创建 ipset 列表?

  •  
  •   digimoon · Apr 13, 2015 · 5621 views
    This topic created in 4051 days ago, the information mentioned may be changed or developed.
    iptables的规则写在/etc/sysconfig/iptables,重启系统后发现规则不能载入
    翻了一下log发现是因为规则里面有用到ipset,但是ipset的列表重启后不能在iptables之前先建好导致载入失败
    有什么比较好的解决方法吗?除了启动外希望systemctl restart iptables也能自动载入
    6 replies    2015-04-14 08:01:49 +08:00
    icloudnet
        1
    icloudnet  
       Apr 13, 2015
    这是6.5下操作,估摸7也差不多:
    $ iptables-restore < /etc/iptables.firewall.rules
    $ service iptables save
    $ servce iptables restart
    iptables -L

    https://icloud.net/blog/120/the-most-important-iptables-rules-for-your-linux-server/
    digimoon
        2
    digimoon  
    OP
       Apr 13, 2015
    @icloudnet 不是这个问题。
    例如:
    iptables -t nat -A TEST -m set --match-set whitelist dst -j RETURN
    如果你不先用ipset创建whitelist的话这条命令就会报错,而启动系统的时候iptables会比ipset先导入这条规则
    ryd994
        3
    ryd994  
       Apr 13, 2015 via Android
    可以试试Fedora的ipset-service包,反正是试验田里的东西,向来直接拿也没事,不行的话你还是可以解包参考配置怎么写
    另外可以设为不自动启动,然后在rc.local里做好ipset后启动
    rentaro
        4
    rentaro  
       Apr 13, 2015
    systemd 支持处理依赖关系,在 service 的配置文件中写明依赖
    digimoon
        5
    digimoon  
    OP
       Apr 13, 2015
    @rentaro
    能有详细教程么?
    看了其他systemd的配置文件,知道用requires before after等来处理依赖和顺序,问题是没有ipset这么一个target或service,应该怎么添加一个让iptables来依赖?
    ryd994
        6
    ryd994  
       Apr 14, 2015 via Android
    @digimoon 两个选择
    prestart挂脚本
    写一个service
    文档看man就行:man systemd.service
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2866 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:28 · PVG 20:28 · LAX 05:28 · JFK 08:28
    ♥ Do have faith in what you're doing.