规则定义

# 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. GIL 全局解释器

    全局解释器锁 GIL 相当于给python解释器加了一把互斥锁 每一个进程都有一把互斥锁,所有线程必须先拿到解释器,才能执行代码, 同一进程下,所有线程并发 在 Cpython 解释器下,多个进程可以 ...

  2. chart.js angular组件封装(ng6)、实战配置、插件编写

    前言 项目需要使用chart.js插件,由于项目是使用angular开发,那么我第一步就是先把chart.js改造成angular组件来使用. 本项目代码都可以在github上下载:项目git地址 a ...

  3. IScroll在某些手机浏览器上不能滑动和卡顿解决办法

    1.不能滑动,增加一句 if (scroll != null) scroll.refresh();2.卡顿,增加 <script>window.PointerEvent = undefin ...

  4. Xampp PHPStorm XDebug配置

    (1)https://xdebug.org/download.php 下载当前Xampp对应的XDebug版本. (2)将该dll放入C:\xampp\php\ext (3)修改Control Pan ...

  5. daemon_init函数:调用该函数把普通进程转变为守护进程

    #include <unistd.h> #include <syslog.h> #include <fcntl.h> #include <signal.h&g ...

  6. mysql 单表更新记录UPDATE

    1.单表更新 (1)mysql> SELECT * FROM users;+----+----------+----------+-----+------+| id   | username | ...

  7. JavaScript之Ajax Util

    ajax(即:Asynchronous JavaScript and XML(异步的 JavaScript 和 XML))经常在用,却经常忽略了底层的实现机制,今日写个小工具,大家也可拿去使用,如果写 ...

  8. webpack 配置全局 jQuery 对象

    将 lodash 添加到当前模块的上下文中 import _ from 'lodash' 但是你想每个模块都引入的话就特别麻烦,这里有插件可以帮助到您,只需在 webpack.config.js 中配 ...

  9. js查询参数

    /*参数查询*/ function GetQueryString(name){ var reg = new RegExp("(^|&)" + name + "=( ...

  10. LOJ #2587「APIO2018」铁人两项

    是不是$ vector$存图非常慢啊...... 题意:求数对$(x,y,z)$的数量使得存在一条$x$到$z$的路径上经过$y$,要求$x,y,z$两两不同  LOJ #2587 $ Solutio ...