首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

前言

在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这个命令自己用脚本多方便啊!

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20171219A0VHZR00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券