iptables防火墙脚本应用 推荐
2013-09-09 23:26
411 查看
本脚本修改自鸟哥的经典iptables防火墙脚本,做了简化适用于单机服务器环境
1、将防火墙规则文件放置在相应的目录内
(1)防火墙规则
iptables.rule 如下:
iptables.allow 如下:
iptables.deny 如下:
(2)放置目录:
# mkdir -p /usr/local/virus/iptables
# cp /tools/iptables.* /usr/local/virus/iptables/
2、授予权限
# cd /usr/local/virus/iptables/
# chmod 700 iptables.*
3、加入开启自启动
# vim /etc/rc.d/rc.local
1、将防火墙规则文件放置在相应的目录内
(1)防火墙规则
iptables.rule 如下:
#!/bin/bash ######################################################################### EXTIF="em1" INIF="em2" INNET="" export EXTIF INIF INNET ########################################################################## echo "1" /proc/sys/net/ipv4/tcp_syncookies echo "1" /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts for i in /proc/sys/net/ipv4/conf/*/{rp_filter,log_martians};do echo "1" > $i done for i in /proc/sys/net/ipv4/conf/*/{accept_source_route,accept_redirects,\ send_redirects};do echo "0" > $i done ########################################################################### PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin; export PATH iptables -F iptables -X iptables -Z iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT ############################################################################ if [ -f /usr/local/virus/iptables/iptables.deny ]; then sh /usr/local/virus/iptables/iptables.deny fi if [ -f /usr/local/virus/iptables/iptables.allow ]; then sh /usr/local/virus/iptables/iptables.allow fi if [ -f /usr/local/virus/iptables/iptables.http ]; then sh /usr/local/virus/iptables/iptables.http fi ############################################################################# AICMP="0 3 3/4 4 11 12 14 16 18" for tyicmp in $AICMP do iptables -A INPUT -i $EXTIF -p icmp --icmp-type $tyicmp -j ACCEPT done iptables -A INPUT -s 172.16.0.1 -p icmp --icmp-type 8 -j ACCEPT #Cacti Request ############################################################################# #iptables -A INPUT -p TCP -i $EXTIF --dport 21 --sport 1024:65534 -j ACCEPT #FTP iptables -A INPUT -p TCP -i $EXTIF --dport 1230:1234 --sport 1024:65534 -j ACCEPT #Game_Server iptables -A INPUT -p TCP -i $EXTIF --dport 22 --sport 1024:65534 -j ACCEPT #SSH #iptables -A INPUT -p TCP -i $EXTIF --dport 25 --sport 1024:65534 -j ACCEPT #SMTP #iptables -A INPUT -p UDP -i $EXTIF --dport 53 --sport 1024:65534 -j ACCEPT #DNS #iptables -A INPUT -p TCP -i $EXTIF --dport 53 --sport 1024:65534 -j ACCEPT #DNS iptables -A INPUT -p TCP -i $EXTIF --dport 80 --sport 1024:65534 -j ACCEPT #WWW iptables -A INPUT -p TCP -i $EXTIF --dport 3306 --sport 1024:65534 -j ACCEPT #MySQL iptables -A INPUT -p UDP -i $EXTIF --dport 161 --sport 1024:65534 -j ACCEPT #SNMP #iptables -A INPUT -p TCP -i $EXTIF --dport 110 --sport 1024:65534 -j ACCEPT #POP3 #iptables -A INPUT -p TCP -i $EXTIF --dport 443 --sport 1024:65534 -j ACCEPT #HTTPS ############################################################################## /etc/init.d/iptables save
iptables.allow 如下:
#! /bin/bash iptables -A INPUT -i $EXTIF -s 172.16.0.1 -p tcp --dport 22 -j ACCEPT
iptables.deny 如下:
#! /bin/bash iptables -A INPUT -i $EXTIF -s 172.16.0.2 -j DROP
(2)放置目录:
# mkdir -p /usr/local/virus/iptables
# cp /tools/iptables.* /usr/local/virus/iptables/
2、授予权限
# cd /usr/local/virus/iptables/
# chmod 700 iptables.*
3、加入开启自启动
# vim /etc/rc.d/rc.local
#YX Firewall /usr/local/virus/iptables/iptables.rule
相关文章推荐
- 默认Iptables防火墙规则的小实验[附脚本] 推荐
- 安全的Web主机iptables防火墙脚本 推荐
- Linux下主机充当防火墙的巧妙应用之iptables! 推荐
- 趣味应用组策略的脚本 推荐
- inux上iptables防火墙的基本应用教程
- (转载)Linux上iptables防火墙的基本应用教程
- iptables防火墙详解(三)规则的导出、导入以及编写防火墙脚本
- 嵌入式 iptables防火墙应用实例
- 自动甄别黑白名单的iptables安全脚本 推荐
- 实用防火墙(Iptables)脚本分析
- Linux上iptables防火墙的基本应用教程
- DDOS攻击类型以及iptables防范ddos脚本 推荐
- Linux上iptables防火墙的基本应用教程
- Linux系列-Red Hat5平台下的Iptables防火墙应用(一)翻出老家底——咱们来学Iptables
- iptables 做mail防火墙脚本
- Linux iptables防火墙详解 + 配置抗DDOS攻击策略实战 推荐
- iptables防火墙详解及使用layer7阻止qq,酷狗,等P2P软件 推荐
- 保护你的Web服务器 iptables防火墙脚本全解读
- iptables 防火墙笔记 3 :黑名单脚本
- 防火墙iptables之常用脚本