开启ip段192.168.1.0/24端的80口

开启ip段211.123.16.123/24端ip段的80口

# iptables -I INPUT -p tcp --dport 80 -j DROP 

# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT

# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT

以上是临时设置。

1.先备份iptables

# cp /etc/sysconfig/iptables /var/tmp

2.然后保存iptables

# service iptables save

3.重启防火墙

#service iptables restart

以下是端口,先全部封再开某些的IP

iptables -I INPUT -p tcp --dport 9889 -j DROP

iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 9889 -j ACCEPT

如果用了NAT转发记得配合以下才能生效

iptables -I FORWARD -p tcp --dport 80 -j DROP

iptables -I FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
常用的IPTABLES规则如下:
1. 只能收发邮件,别的都关闭

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -j DROP

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p udp --dport 53 -j ACCEPT

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 25 -j ACCEPT

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 110 -j ACCEPT

2. IPSEC NAT 策略

iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT

iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:80

iptables -t nat -A PREROUTING -p tcp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:500

iptables -t nat -A PREROUTING -p udp --dport 4500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:4500

3.FTP服务器的NAT

iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.100.200 -j ACCEPT

iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:21

4.只允许访问指定网址

iptables -A Filter -p udp --dport 53 -j ACCEPT

iptables -A Filter -p tcp --dport 53 -j ACCEPT

iptables -A Filter -d www.3322.org -j ACCEPT

iptables -A Filter -d img.cn99.com -j ACCEPT

iptables -A Filter -j DROP

5.开放一个IP的一些端口,其它都封闭

iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d www.pconline.com.cn -j ACCEPT

iptables -A Filter -p tcp --dport 25 -s 192.168.100.200 -j ACCEPT

iptables -A Filter -p tcp --dport 109 -s 192.168.100.200 -j ACCEPT

iptables -A Filter -p tcp --dport 110 -s 192.168.100.200 -j ACCEPT

iptables -A Filter -p tcp --dport 53 -j ACCEPT

iptables -A Filter -p udp --dport 53 -j ACCEPT

iptables -A Filter -j DROP

6.多个端口

iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT

7.连续端口

iptables -A Filter -p tcp -m multiport --source-port 22,53,80,110 -s 192.168.20.3 -j REJECT iptables -A Filter -p tcp --source-port 2:80 -s 192.168.20.3 -j REJECT

8.指定时间上网

iptables -A Filter -s 10.10.10.253 -m time --timestart 6:00 --timestop 11:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP

iptables -A Filter -m time --timestart 12:00 --timestop 13:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

iptables -A Filter -m time --timestart 17:30 --timestop 8:30 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

9.禁止多个端口服务

iptables -A Filter -m multiport -p tcp --dport 21,23,80 -j ACCEPT

10.将WAN 口NAT到PC

iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1

11.将WAN口8000端口NAT到192。168。100。200的80端口

iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:80

12.MAIL服务器要转的端口

iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:110

iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:25

13.只允许PING 202。96。134。133,别的服务都禁止

iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT

iptables -A Filter -j DROP

14.禁用BT配置

iptables –A Filter –p tcp –dport 6000:20000 –j DROP

15.禁用QQ防火墙配置

iptables -A Filter -p udp --dport ! 53 -j DROP

iptables -A Filter -d 218.17.209.0/24 -j DROP

iptables -A Filter -d 218.18.95.0/24 -j DROP

iptables -A Filter -d 219.133.40.177 -j DROP

16.基于MAC,只能收发邮件,其它都拒绝

iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -j DROP

iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT

iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT

17.禁用MSN配置

iptables -A Filter -p udp --dport 9 -j DROP

iptables -A Filter -p tcp --dport 1863 -j DROP

iptables -A Filter -p tcp --dport 80 -d 207.68.178.238 -j DROP

iptables -A Filter -p tcp --dport 80 -d 207.46.110.0/24 -j DROP

18.只允许PING 202。96。134。133 其它公网IP都不许PING

iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT

iptables -A Filter -p icmp -j DROP

19.禁止某个MAC地址访问internet:

iptables -I Filter -m mac --mac-source 00:20:18:8F:72:F8 -j DROP

20.禁止某个IP地址的PING:

iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

21.禁止某个IP地址服务:

iptables –A Filter -p tcp -s 192.168.0.1 --dport 80 -j DROP

iptables –A Filter -p udp -s 192.168.0.1 --dport 53 -j DROP

22.只允许某些服务,其他都拒绝(2条规则)

iptables -A Filter -p tcp -s 192.168.0.1 --dport 1000 -j ACCEPT

iptables -A Filter -j DROP

23.禁止某个IP地址的某个端口服务

iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j ACCEPT

iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j DROP

24.禁止某个MAC地址的某个端口服务

iptables -I Filter -p tcp -m mac --mac-source 00:20:18:8F:72:F8 --dport 80 -j DROP

25.禁止某个MAC地址访问internet:

iptables -I Filter -m mac --mac-source 00:11:22:33:44:55 -j DROP

26.禁止某个IP地址的PING:

iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

6.iptables常用规则的更多相关文章

  1. iptables常用规则:屏蔽IP地址、禁用ping、协议设置、NAT与转发、负载平衡、自定义链

    iptables常用规则:屏蔽IP地址.禁用ping.协议设置.NAT与转发.负载平衡.自定义链 时间 -- :: IT社区推荐资讯 原文 http://itindex.net/detail/4772 ...

  2. (转)iptables常用规则:屏蔽IP地址、禁用ping、协议设置、NAT与转发、负载平衡、自定义链

    转自:http://lesca.me/archives/iptables-examples.html 本文介绍25个常用的iptables用法.如果你对iptables还不甚了解,可以参考上一篇ipt ...

  3. iptables常用规则

    删除现有规则 iptables -F (OR) iptables --flush 设置默认链策略 iptables的filter表中有三种链:INPUT, FORWARD和OUTPUT.默认的链策略是 ...

  4. 25个iptables常用示例

    本文将给出25个iptables常用规则示例,这些例子为您提供了些基本的模板,您可以根据特定需求对其进行修改调整以达到期望. 格式 iptables [-t 表名] 选项 [链名] [条件] [-j ...

  5. iptables常用命令二之如何删除nat规则

    删除iptables nat 规则 删除FORWARD 规则: iptables -nL FORWARD --line-number iptables -D FORWARD 1 删除一条nat 规则 ...

  6. Production环境中iptables常用参数配置

    production环境中iptables常用参数配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我相信在实际生产环境中有很多运维的兄弟跟我一样,很少用到iptables的这个 ...

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

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

  8. Iptables防火墙规则使用梳理

    iptables是组成Linux平台下的包过滤防火墙,与大多数的Linux软件一样,这个包过滤防火墙是免费的,它可以代替昂贵的商业防火墙解决方案,完成封包过滤.封包重定向和网络地址转换(NAT)等功能 ...

  9. Iptables防火墙规则使用

    iptables是组成Linux平台下的包过滤防火墙,与大多数的Linux软件一样,这个包过滤防火墙是免费的,它可以代替昂贵的商业防火墙解决方案,完成封包过滤.封包重定向和网络地址转换(NAT)等功能 ...

随机推荐

  1. shell if,case,for,while语法

    #shell if的语法 if [空格 xxx 空格] then echo xxxxx exit 1/2/3/4/.... 0表示正确. elif [空格 xxx 空格] then echo xxxx ...

  2. ios crash log

    1.IOS策略 1.1 低内存闪退 前面提到大多数crash日志都包含着执行线程的栈调用信息,但是低内存闪退日志除外,这里就先看看低内存闪退日志是什么样的.我们使用Xcode 5和iOS 7的设备模拟 ...

  3. Linux下各种解压命令

    本文介绍了linux下的压缩程式tar.gzip.gunzip.bzip2.bunzip2.compress .uncompress. zip. unzip.rar.unrar等程式,以及如何使用它们 ...

  4. 100. Same Tree同样的树

    [抄题]: Given two binary trees, write a function to check if they are the same or not. Two binary tree ...

  5. Runnable和Thread实现多线程的区别(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17161237 Java中实现多线程有两种方法:继承Thread类.实现Runnable接口 ...

  6. Mysql(Navicat for Mysql)怎么添加数据库

    1.首先打开Navicat for Mysql: 2.打开后界面如下图所示,双击连接localhost_3306: 3.连接后localhost_3306变成绿色,如下图所示: 4.选中下面任意数据库 ...

  7. IE6,7,8在boostrap中兼容h5和css3

    IE6.7.8版本(IE9以下版本)浏览器兼容html5新增的标签,引入下面代码文件即可: <script src="https://oss.maxcdn.com/libs/html5 ...

  8. .NET分布式事务处理(转)

    出处:http://www.cnblogs.com/youring2/archive/2011/06/12/MSDTC.html 在进行数据持久化的时候,我们会经常用到事务处理.一般情况下,ADO.N ...

  9. libxml2

    http://www.xmlsoft.org/downloads.html   建议直接用openscenegraph下载的3rdparty:http://www.openscenegraph.org ...

  10. c#范型

    泛型介绍:范型类和范型方法同事具备可重用性.类型安全和效率,这是非范型类和非范型方法无法具备的. 所谓范型,即通过参数化类型实现同一份代码上操作多种数据类型,范型编程是一种编程范式,它利用“参数化类型 ...