首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Debian/Ubuntu-shell脚本来管理iptables安全策略

Debian/Ubuntu-shell脚本来管理iptables安全策略

作者头像
企鹅号小编
发布2018-02-08 15:37:10
8350
发布2018-02-08 15:37:10
举报
文章被收录于专栏:编程编程

前言

在Centos上都有iptables-services或者firewalld等iptables管理工具。那在Debian系列用什么管理工具呢?

使用Debian

Debian安装完以后,要设置安全策略,发现没有iptables-services管理工具,What?好吧!只能找找有什么工具,发现有一个ufw。不是没有管理工具,只是我不会用。

shell脚本管理

ufw用不惯就不强求,自己写个脚本来解决:

#!/bin/bash
source /etc/profile
function save(){
iptables-save  > /etc/iptables.rules
}
function restart(){
iptables-restore 
}
function stop(){
iptables -t nat -F
iptables -t nat -X
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
iptables -F
iptables -X
iptables -P FORWARD ACCEPT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t raw -F
iptables -t raw -P PREROUTING ACCEPT
iptables -t raw -P OUTPUT ACCEPT
}
if [ "$1" == "save" ]
then
save
elif [[ "$1" == "reload" || "$1" == "restart" ]]
then
restart
elif [[ "$1" == "stop" ]]
then
stop
else
echo "$0 [save|restart|reload|stop]"
fi

总结

只要知道iptables这个命令自己用脚本多方便啊!

本文来自企鹅号 - 运维小菜媒体

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文来自企鹅号 - 运维小菜媒体

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档