规则定义

# 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的简单使用的更多相关文章

  1. [转] Linux下防火墙iptables用法规则详及其防火墙配置

    from: http://www.cnblogs.com/yi-meng/p/3213925.html 备注: 排版还不错,建议看以上的链接. iptables规则 规则--顾名思义就是规矩和原则,和 ...

  2. linux 防火墙iptables简明教程

    前几天微魔部落再次遭受到个别别有用心的攻击者的攻击,顺便给自己充个电,复习了一下linux下常见的防火墙iptables的一些内容,但是无奈网上的很多教程都较为繁琐,本着简明化学习的目的,微魔为大家剔 ...

  3. Linux防火墙iptables简明教程

    前几天微魔部落再次遭受到个别别有用心的攻击者的攻击,顺便给自己充个电,复习了一下linux下常见的防火墙iptables的一些内容,但是无奈网上的很多教程都较为繁琐,本着简明化学习的目的,微魔为大家剔 ...

  4. Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]

     Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...

  5. Linux防火墙iptables学习

    http://blog.chinaunix.net/uid-9950859-id-98277.html 要在网上传输的数据会被分成许多小的数据包,我们一旦接通了网络,会有很多数据包进入,离开,或者经过 ...

  6. Linux下防火墙iptables用法规则详及其防火墙配置

    转:http://www.linuxidc.com/Linux/2012-08/67952.htm iptables规则 规则--顾名思义就是规矩和原则,和现实生活中的事情是一样的,国有国法,家有家规 ...

  7. CentOS防火墙iptables的配置方法详解

    CentOS系统也是基于linux中的它的防火墙其实就是iptables了,下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助. iptables是与Linux ...

  8. Linux防火墙(Iptables)的开启与关闭

    Linux防火墙(iptables)的开启与关闭 Linux中的防火墙主要是对iptables的设置和管理. 1. Linux防火墙(Iptables)重启系统生效 开启: chkconfig ipt ...

  9. 【iptables】linux网络防火墙-iptables基础详解(重要)

    一:前言   防火墙,其实说白了讲,就是用于实现Linux下访问控制的功能的,它分为硬件的或者软件的防火墙两种.无论是在哪个网络中,防火墙工作的地方一定是在网络的边缘.而我们的任务就是需要去定义到底防 ...

随机推荐

  1. HDU - 1272 小希的迷宫(并查集判断环)

    https://cn.vjudge.net/problem/HDU-1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardo ...

  2. 流媒体技术学习笔记之(十八)Ubuntu 16.04.3 如何编译 FFmpeg 记录

    官方文档:https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu 一.最简单安装: apt-get install ffmpeg 二.安装最新版本 大 ...

  3. 关于REST API设计的文章整理

    1. rest api uri设计的7个准则(1)uri末尾不需要出现斜杠/(2)在uri中使用斜杠/表达层级关系(3)在uri中可以使用连接符-提升可读性(4)在uri中不允许出现下划线字符_(5) ...

  4. Vue.Draggable/SortableJS 的排序功能,在VUE中的使用

    此插件git: https://github.com/SortableJS/Vue.Draggable 基于Sortable.js http://www.cnblogs.com/xiangsj/p/6 ...

  5. RMQ st算法 区间最值模板

    #include<bits/stdc++.h> ; ; int f[N][Logn],a[N],lg[N],n,m; int main(){ cin>>n>>m; ...

  6. Log4j2 快速开始

    1.配置 默认 Log4j2可以将自己配置为记录错误及更高级别日志,并将消息记录到控制台中. [显示配置]1.检测log4j.configurationFile系统属性,如果属性存在,就从指定文件加载 ...

  7. rabbitMQ学习3-RPC远程过程调用

    将一个函数运行在远程计算机上并且等待获取那里的结果,这个称作远程过程调用(Remote Procedure Call)或者 RPC. RPC是一个计算机通信协议. 比喻 将计算机服务运行理解为厨师做饭 ...

  8. luogu P4314 CPU监控

    传送门 这是个远古巨坑阿qwq 没有历史最大值还是能比较好做的.可能会有一个想法,就是直接维护线段树每个结点出现过的历史最大值,每次最大值变化就更新.但是有个问题:可能一个点能影响历史最大值的标记还没 ...

  9. luogu P3980 [NOI2008]志愿者招募

    传送门 网络流又一神仙套路应用 首先考虑列不等式,设\(x_i\)为第i种人的个数,记\(b_{i,j}\)为第i种人第j天是否能工作,那么可以列出n个不等式,第j个为\(\sum_{i=1}^{m} ...

  10. 【Vue】定义组件 data 必须是一个函数返回的对象

    Vue 实例的数据对象.Vue 将会递归将 data 的属性转换为 getter/setter,从而让 data 的属性能够响应数据变化.对象必须是纯粹的对象 (含有零个或多个的 key/value ...