开启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. 在Ajax请求中什么时候用GET方式什么时候用POST方式?

    当我们有大量数据要传送时最好的办法是一次发出多个只传递少量信息的Ajax调用时.如果你正用一个Ajax调用发送大量数据,那么最好是结束这种做法,因为这样做并不能节约时间. 因此,需要传送大量数据能成为 ...

  2. c# winform 解决PictureBox 无法打印全部图片的问题

    一.   问题描述 在页面使用PictureBox 加载资料图片后,点击“打印”,只能打印图片首页,较大图片则无法全部打印. 二.   原因分析 PictureBox中打印图片时没有设置继续打印相关属 ...

  3. rman恢复增加ADG(级联ADG)

    当前已经有一套ADG库,分别是prod1和prod1s计划从pord的ADG备库(prod1s)拷贝一个0级rman全备到新的服务器,恢复后,搭建成新增的ADG,SID叫prod2s,后面激活当做测试 ...

  4. RotbotFrameWork接口测试

    一.添加接口测试Library 二.参数说明 三.关键字使用说明 Set Varibae: 参数化接口地址 Connect To Databse Using Custom Param: 连接数据库(需 ...

  5. spring与mybatis五种整合方法

    1.采用数据映射器(MapperFactoryBean)的方式 不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数.  (1)Spring配置文件: <!-- 引入jdbc ...

  6. python学习——查找计算机中文件位置

    有时想查找某个文件时,却忘记了文件在计算机中存放的位置,这是一个经常遇到的问题. 当然如果你使用windows 7的话,可以直接用右上角的搜索框来搜索. 最近在学习python,正好拿这个来练练手,写 ...

  7. JMeter下载及安装配置完整版

    特别需要注意的时,jdk版本和jmeter版本匹配问题. Jdk1.8对应apache-jmeter-3.3 Jmeter下载及安装配置 本文是在win7环境下安装使用jmeter,jmeter可以运 ...

  8. 基于weui的一个小插件

    移动端项目当中大量的使用了weui,为了减少工作量,方便修改,自己写了个小插件,暂时只有toast和dialog部分,可能会更新actionSheet等其他部分 更新一个手机端预览的二维码,就直接放项 ...

  9. easyui 获取当前页签选中的名称

    parent.parent.$("#tabs").tabs('getSelected').panel('options').title == "收藏夹管理"

  10. 以二进制的形式查看文件 Linux之od命令详解

    od命令 以二进制的形式查看文件 od -t x1 /usr/local/FT/config/hsm_create.utf8.sql ef bb bf 4c 5f 0d 0a 5f 4e 4e 4f ...