V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
digimoon
V2EX  ›  问与答

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

  •  
  •   digimoon · 2015-04-13 12:05:22 +08:00 · 4955 次点击
    这是一个创建于 3316 天前的主题,其中的信息可能已经有所发展或是发生改变。
    iptables的规则写在/etc/sysconfig/iptables,重启系统后发现规则不能载入
    翻了一下log发现是因为规则里面有用到ipset,但是ipset的列表重启后不能在iptables之前先建好导致载入失败
    有什么比较好的解决方法吗?除了启动外希望systemctl restart iptables也能自动载入
    6 条回复    2015-04-14 08:01:49 +08:00
    icloudnet
        1
    icloudnet  
       2015-04-13 13:24:50 +08:00
    这是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
       2015-04-13 13:51:03 +08:00
    @icloudnet 不是这个问题。
    例如:
    iptables -t nat -A TEST -m set --match-set whitelist dst -j RETURN
    如果你不先用ipset创建whitelist的话这条命令就会报错,而启动系统的时候iptables会比ipset先导入这条规则
    ryd994
        3
    ryd994  
       2015-04-13 14:14:59 +08:00 via Android
    可以试试Fedora的ipset-service包,反正是试验田里的东西,向来直接拿也没事,不行的话你还是可以解包参考配置怎么写
    另外可以设为不自动启动,然后在rc.local里做好ipset后启动
    rentaro
        4
    rentaro  
       2015-04-13 14:21:19 +08:00
    systemd 支持处理依赖关系,在 service 的配置文件中写明依赖
    digimoon
        5
    digimoon  
    OP
       2015-04-13 15:43:28 +08:00
    @rentaro
    能有详细教程么?
    看了其他systemd的配置文件,知道用requires before after等来处理依赖和顺序,问题是没有ipset这么一个target或service,应该怎么添加一个让iptables来依赖?
    ryd994
        6
    ryd994  
       2015-04-14 08:01:49 +08:00 via Android
    @digimoon 两个选择
    prestart挂脚本
    写一个service
    文档看man就行:man systemd.service
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1119 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:01 · PVG 03:01 · LAX 12:01 · JFK 15:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.