第一步:保存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 为开机启动文章来源:https://www.toymoban.com/news/detail-756318.html
systemctl enable rc.local
第六步:重启系统后 查看 iptables 规则是否还在文章来源地址https://www.toymoban.com/news/detail-756318.html
到了这里,关于配置Ubuntu18.04使iptables规则重启系统后仍然有效的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!