iptables 配置文件存放位置:

 [root@Demon yum.repos.d]# vim /etc/rc.d/init.d/iptables
 

一、只给 Centos 6.5 打开 22 和 80 端口,并且重启后有效:

1、查看所有 iptables 配置:

[root@Demon yum.repos.d]# iptables -L -n   (当前防火墙是关闭的)
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

2、只允许 80 和 22 端口通过防火墙

# 清除所有规则

[root@Demon opt]# iptables -F
# 只允许 发送的包从 22 端口进入和返回, -A 的意思是添加一条 INPUT 规则, -p 指定为什么协议,--dport 为目标端口
[root@Demon opt]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 允许本机访问本机

[root@Demon opt]# iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

# 允许所有 IP 访问 80 端口

[root@Demon opt]# iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
[root@Demon opt]# iptables -P INPUT DROP
[root@Demon opt]# iptables -P OUTPUT DROP
[root@Demon opt]# iptables -P FORWARD DROP

# 保存配置

[root@Demon opt]# iptables-save > /etc/sysconfig/iptables
[root@Demon opt]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
ACCEPT     all  --  localhost            localhost           
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http 
Chain FORWARD (policy DROP)
target     prot opt source               destination         
Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:ssh state ESTABLISHED 
ACCEPT     all  --  localhost            localhost           
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http state ESTABLISHED

# 重启电脑后, ping  一下百度:

[root@Demon opt]# ping www.baidu.com
ping: unknown host www.baidu.com 

二、关闭 iptables

# 打开防火墙,重启生效

# chkconfig iptables on

# 关闭防火墙,重启生效

# chkconfig iptables off
 

# 打开防火墙,立即生效,重启后不生效

# chkconfig start

# 关闭防火墙,立即生效,重启后不生效

# chkconfig stop

9. iptables 配置的更多相关文章

  1. tony_iptables_01_linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  2. linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  3. linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看.开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况[ ~]# iptables -L -nChain I ...

  4. linux下IPTABLES配置

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  5. [转载] iptables配置实践

    原文: http://wsgzao.github.io/post/iptables/ iptables配置实践 By wsgzao 发表于 2015-07-24 文章目录 1. 前言 2. 更新历史 ...

  6. linux下IPTABLES配置详解

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  7. (转载)Linux下IPTABLES配置详解

    (转载)http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html 如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 ...

  8. Android Linux自带iptables配置IP访问规则

    利用Linux自带iptables配置IP访问规则,即可做到防火墙效果

  9. [转]linux下IPTABLES配置详解

    如果你的IPTABLES基础知识还不了解,建议先去看看.开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况[root@tp ~]# iptables -L -n ...

随机推荐

  1. 解决Xcode6.4安装插件后插件不能使用的问题

    下面是上网查的方法,综合了一下,亲测 原因: 苹果要求加入UUID证书从而保证插件的稳定性. 解决方法: 一.查看Xcode的UUID 在终端执行 defaults read /Application ...

  2. overflow:hidden

    原来以为overflow:hidden能隐藏所有溢出的子元素,但今天发现我错了. 对于overflow:hidden的最大误解时:当一个具有高度和宽度中至少一项的容器应用了overflow:hidde ...

  3. JavaScript-------寄生组合式继承

    组合继承在前面有说过,也是JavaScript中最常用的一个继承模式:不过,它也有自己的不足.组合继承最大的问题就是无论什么情况,都会调用两次构造函数: 那我们来回顾下组合式继承基本模式: funct ...

  4. js获取url参数的方法

    js获取url参数的方法有很多. 1.正则分析 function getQueryString(name) { var reg = new RegExp("(^|&)" + ...

  5. .net下载

    1,Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下: Content-Disposition: attachment;filename=filename.ext ...

  6. sql 模糊查询带下划线的字段 _

    1.SELECT * FROM dbo.tb_Test 2.SELECT * FROM dbo.tb_Test WHERE name LIKE '%c_%' 3.SELECT * FROM dbo.t ...

  7. 2.Perl基础系列之入门

    官网提供的入门链接:http://perldoc.perl.org/perlintro.html 语法概述 Perl的安装步骤省略,直接去官网下载并按照提示安装即可. 如果Perl安装没问题,那么运行 ...

  8. python 在linux下通过top,和dh命令获得cpu,内存,以及硬盘信息

    主要是通过os.popen读取命令输出实现的,os.popen启动新的进程,且将外部命令的输出作为文件类型对象返回.不能获得外部命令的返回值.既然是文件对象就可以直接用for in 来读取,代码如下: ...

  9. Histats申请Counter网站计数器 - Blog透视镜

    为了计算网页被浏览的次数,访客人数等统计数据,作为未来分析之用,可以向Histats申请免费的Counter网站计数器,它的功能相当齐全,同时也会保留一段时间的资料,当作统计比较的资料,更可以进一步付 ...

  10. Java 遍历Map

    Set<Map.Entry<String, String>> aSet = map.entrySet(); Iterator<Map.Entry<String, S ...