防火墙iptables的简单使用
规则定义
# service iptables start
# chkconfig iptables on
想让规则生效,则shell命令行下执行
sh /bin/iptables.sh即可
[root@node3 ~]# cat /bin/iptables.sh
#!/bin/bash
# 清理防火墙规则
/sbin/iptables -F # 放行已经建立的连接
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # for ssh
/sbin/iptables -A INPUT -p tcp --dport -j ACCEPT # 放行 tcp 8555端口
/sbin/iptables -A INPUT -p tcp --dport -j ACCEPT #for ping:
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type fragmentation-needed -j ACCEPT /sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT #for DNS:
/sbin/iptables -A INPUT -p tcp --source-port -j ACCEPT
/sbin/iptables -A INPUT -p udp --source-port -j ACCEPT
#for ntp:
/sbin/iptables -A INPUT -p udp --source-port -j ACCEPT
/sbin/iptables -A INPUT -p udp --destination-port -j ACCEPT ### 拒绝input和forward所有
/sbin/iptables -A INPUT -j DROP
/sbin/iptables -A FORWARD -j DROP
#!/bin/bash
### Required modules
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_owner
/sbin/modprobe ipt_REJECT ### Clean Rules
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -F
iptables -t nat -F
#iptables -t mangle -F
iptables -X
iptables -t nat -X
#iptables -t mangle -X ### Drop all pocket,first
iptables -P INPUT DROP
#iptables -P OUTPUT DROP
iptables -P FORWARD DROP ### Create New chains
iptables -N bad_tcp_packets
#iptables -N allowed
iptables -N icmp_packets ### Bad_tcp_packets chain
/sbin/iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags ACK,FIN FIN -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags ACK,PSH PSH -j DROP
/sbin/iptables -A bad_tcp_packets -p tcp --tcp-flags ACK,URG URG -j DROP ### ICMP Rules
iptables -A icmp_packets -p icmp --icmp-type -j ACCEPT
iptables -A icmp_packets -p icmp --icmp-type -j ACCEPT
#iptables -A icmp_packets -p icmp -j DROP ### LookBack and Private interface
iptables -A INPUT -p ALL -i lo -j ACCEPT
iptables -A INPUT -p ALL -i eth1 -j ACCEPT ##keepalived
#iptables -A INPUT -i eth1 -p vrrp -s 192.168.254.122 -j ACCEPT ### INPUT chain
iptables -A INPUT -p tcp -j bad_tcp_packets
iptables -A INPUT -p icmp -j icmp_packets
iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT #限制源IP的访问数量
iptables -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above --connlimit-mask -j REJECT --reject-with icmp-port-unreachable
iptables -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above --connlimit-mask -j REJECT --reject-with icmp-port-unreachable
iptables -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above --connlimit-mask -j REJECT --reject-with icmp-port-unreachable # Count Limit
#iptables -A INPUT -m limit --limit /minute --limit-burst -j LOG --log-level INFO --log-prefix "IPT INPUT PACKET DIED:" iptables -I INPUT -p udp --dport -j ACCEPT ### Open Ports
Public_access=""
Server_access="873 1500"
Company_access="" ### Allow Ips Servers_ip="192.168.254.0/24 10.11.0.0/16"
Company_ip="1.1.1.1"
### Public access Rules
for port in $Public_access
do
iptables -A INPUT -p tcp --dport $port -i eth0 -j ACCEPT
done ### Servers access Rules
for port in $Server_access
do
for ip in $Servers_ip
do
iptables -A INPUT -p tcp --dport $port -s $ip -i eth0 -j ACCEPT
done
done ### Company access Rules
for port in $Company_access
do
for ip in $Company_ip
do
iptables -A INPUT -p tcp --dport $port -s $ip -i eth0 -j ACCEPT
done
done
# 邮箱服务器将25端口映射到2500端口上
iptables -t nat -A PREROUTING -p tcp --dport 2500 -j REDIRECT --to-ports 25
# 25端口转到2500端口
iptables -t nat -A PREROUTING -p tcp --dport 25 -j REDIRECT --to-ports 2500
#####指定访问ip的 2500 to 25 #####
iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp -m tcp --dport 2500 -j REDIRECT --to-ports 25
# 将访问指定ip的25号端口映射到2500上
iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp -m tcp --dport 25 -j REDIRECT --to-ports 2500
防火墙iptables的简单使用的更多相关文章
- [转] Linux下防火墙iptables用法规则详及其防火墙配置
from: http://www.cnblogs.com/yi-meng/p/3213925.html 备注: 排版还不错,建议看以上的链接. iptables规则 规则--顾名思义就是规矩和原则,和 ...
- linux 防火墙iptables简明教程
前几天微魔部落再次遭受到个别别有用心的攻击者的攻击,顺便给自己充个电,复习了一下linux下常见的防火墙iptables的一些内容,但是无奈网上的很多教程都较为繁琐,本着简明化学习的目的,微魔为大家剔 ...
- Linux防火墙iptables简明教程
前几天微魔部落再次遭受到个别别有用心的攻击者的攻击,顺便给自己充个电,复习了一下linux下常见的防火墙iptables的一些内容,但是无奈网上的很多教程都较为繁琐,本着简明化学习的目的,微魔为大家剔 ...
- Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]
Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...
- Linux防火墙iptables学习
http://blog.chinaunix.net/uid-9950859-id-98277.html 要在网上传输的数据会被分成许多小的数据包,我们一旦接通了网络,会有很多数据包进入,离开,或者经过 ...
- Linux下防火墙iptables用法规则详及其防火墙配置
转:http://www.linuxidc.com/Linux/2012-08/67952.htm iptables规则 规则--顾名思义就是规矩和原则,和现实生活中的事情是一样的,国有国法,家有家规 ...
- CentOS防火墙iptables的配置方法详解
CentOS系统也是基于linux中的它的防火墙其实就是iptables了,下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助. iptables是与Linux ...
- Linux防火墙(Iptables)的开启与关闭
Linux防火墙(iptables)的开启与关闭 Linux中的防火墙主要是对iptables的设置和管理. 1. Linux防火墙(Iptables)重启系统生效 开启: chkconfig ipt ...
- 【iptables】linux网络防火墙-iptables基础详解(重要)
一:前言 防火墙,其实说白了讲,就是用于实现Linux下访问控制的功能的,它分为硬件的或者软件的防火墙两种.无论是在哪个网络中,防火墙工作的地方一定是在网络的边缘.而我们的任务就是需要去定义到底防 ...
随机推荐
- Golang入门教程(十三)延迟函数defer详解
前言 大家都知道go语言的defer功能很强大,对于资源管理非常方便,但是如果没用好,也会有陷阱哦.Go 语言中延迟函数 defer 充当着 try...catch 的重任,使用起来也非常简便,然而在 ...
- Vue 架构
vue 一.认识Vue 定义:一个构建数据驱动的 web 界面的渐进式框架 优点: 1.可以完全通过客户端浏览器渲染页面,服务器端只提供数据 2.方便构建单页面应用程序(SPA) 二.引入Vue &l ...
- range和xrange的区别
range和xrange的区别 python3里面只有range,返回结果是一个生成器,官方文档是这样描述的 class range(object): """ range ...
- Vue.js入门系列教程(三)
序言
- MyEclipse2017 隐藏回车换行符
Preferences->Text Editor->Show Whitespace characters(configure visibility)->Transparency Le ...
- ubuntu 中文变成小方框 口
今天打开ubuntu所有原来是中文的地方都变成口口口口 ,下面是解决办法,其实很简单,更新一下字体库就可以了 1. 进入到字体的目录下 /usr/share/fonts/ ,输入下面的命令 c ...
- Django之CRM项目Day6-公私户转换问题解决 班主任功能
1.解决公户转私户的问题 数据库中加锁: begin; 开始事务 select * from user where id=1 for update; 加锁 commit; 结束事务 dja ...
- AbstractQueuedSynchronizer源码解析
1.简介 AbstractQueuedSynchronizer队列同步器,用来实现锁或者其他同步组件的基础框架 AbstractQueuedSynchronizer使用int类型的volatile变量 ...
- js监听浏览器返回事件
$(function(){ pushHistory(); window.addEventListener("popstate", function(e) { window.loca ...
- Django REST Framework API Guide 05
本节大纲 1.Serializer fields 2.Serializer relations Serializer fields 1.serializer 字段定义在fields.py文件内 2.导 ...