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. 写一个简易web服务器、ASP.NET核心知识(4)--转载

    第一次尝试(V1.0) 1.理论支持 这里主要要说的关于Socket方面的.主要是一个例子,关于Socket如何建立服务端程序的简单的代码. static void Main(string[] arg ...

  2. SQLserver 连接+开窗函数+视图+事务

    今天学习SQLserver 连接以及开窗函数..加油! 1.复习:查询(检索)->筛选列->筛选行:distinct top where 运算符与关键字:比较运算符,逻辑运算符,betwe ...

  3. 利用MetaWeblog API 自制博客发布小工具

    博客园提供了诸多数据接口, 利用这些接口可以很容易的实现博客的发布,修改,删除等 1.需要引用一个DLL:为CookComputing.XmlRpcV2 2.新建一个类,在其中是一些要实现的东西,如: ...

  4. ios属性和成员变量写在.h文件和.m文件中 区别?

    1  其实是一样的.在.m文件上只能.m文件内部的才能访问的这个变量,如果在.h文件中,其他的文件也可以访问到这个变量. 2  写.h文件里边可以和其他的类进行交互,写.m里边只是在本类中使用! 3 ...

  5. js-String

    1.一个字符串可以使用单引号或双引号 2.查找 字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置 如果没找到对应的字符函数返回-1 lastIndexOf() 方法在字符串 ...

  6. 总结前端JQ常用的一些操作手法(慢慢完善)

    1.实例化Js一个object对象,把它当做类来用,事例是操作url的参数 function GetRequestCondition() { var url = window.location.hre ...

  7. main()和_tmain()有什么区别

    用过C的人都知道每一个C的程序都会有一个main(),但有时看别人写的程序发现主函数不是int main(),而是int _tmain(),而且头文件也不是<iostream.h>而是&l ...

  8. zongjie

    $msg = $_GET['msg'];$startDate = $_POST['startDate'];$endDate = $_POST['endDate'];$quickdate = $_POS ...

  9. python:利用urllib查找计算机二级准考证号

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaYAAAEACAIAAAB3VkWnAAAgAElEQVR4nOydZ3gUR9bv+WhExhHnDH

  10. 利用cookies获取登录后的网页

    众所周知,HTTP连接是无状态的,那么问题来了,怎么记录用户的登录信息呢?通常的做法是用户第一次发送HTTP请求时,在HTTP Server端生成一个SessionID,SessionID会对应每个会 ...