海量编程文章、技术教程与实战案例

网站首页 > 技术文章 正文

deepin管理iptables脚本

yimeika 2025-05-26 02:01:27 技术文章 7 ℃


简介

CentOS上用惯了iptables,作为服务进行管理,但是在Debian上没有对应的脚本,手动做一个。


service文件

现在系统基本都是使用systemd进行管理,可以直接编辑service文件进行管理。


sudo vim /usr/lib/systemd/system/iptables.service
[Unit]
Description=iptables rules service
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore  /etc/iptables.rules
ExecReload=/usr/sbin/iptables-restore  /etc/iptables.rules
ExecStop=/usr/sbin/iptables -P INPUT ACCEPT
ExecStop=/usr/sbin/iptables -F
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

加载文件


sudo systemctl daemon-reload
sudo systemctl enable iptables
sudo systemctl start iptables
sudo systemctl reload iptables

保存配置文件

这里只能控制服务的启动、重载和关闭,不能保存配置文件。可以通过命令直接保存配置文件。

/usr/sbin/iptables-save -f /etc/iptables.rules

<script type="text/javascript" src="//mp.toutiao.com/mp/agw/mass_profit/pc_product_promotions_js?item_id=6986292223335760423"></script>

Tags:

最近发表
标签列表