赞
踩
第一步:保存iptables规则到文件 /etc/iptables.rules
iptables-save > /etc/iptables.rules
第二步:将如下代码写入 /etc/rc.local
- #!/bin/sh
- iptables-restore < /etc/iptables.rules
第三步:为 /etc/rc.local 文件赋可执行权限
chmod +x /etc/rc.local
第四步:编辑文件 /lib/systemd/system/rc.local.service 内容如下:
- # SPDX-License-Identifier: LGPL-2.1+
- #
- # This file is part of systemd.
- #
- # systemd is free software; you can redistribute it and/or modify it
- # under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2.1 of the License, or
- # (at your option) any later version.
-
- # This unit gets pulled automatically into multi-user.target by
- # systemd-rc-local-generator if /etc/rc.local is executable.
- [Unit]
- Description=/etc/rc.local Compatibility
- Documentation=man:systemd-rc-local-generator(8)
- ConditionFileIsExecutable=/etc/rc.local
- After=network.target
-
- [Service]
- Type=forking
- ExecStart=/etc/rc.local start
- TimeoutSec=0
- RemainAfterExit=yes
- GuessMainPID=no
第五步:设置 rc.local 为开机启动
systemctl enable rc.local
第六步:重启系统后 查看 iptables 规则是否还在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。