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. Afianl加载网络图片(延续)

    上一页"已经谈到了如何使用Afianl网络负载的图片和下载文件,本文将继续介绍使用Afinal使用网络负载图片,主绑定listview采用: 看效果图: listview在滑动过程中没用明显 ...

  2. BOOST中如何实现线程安全代码

    1 需要include <boost/thread.hpp> 2 背景知识请参考<boost程序库完全开发指南>第12章 3 编绎:g++ -o mthread mthread ...

  3. [跟我学spring][Bean的作用域]

    Bean的作用域 什么是作用域呢?即“scope”,在面向对象程序设计中一般指对象或变量之间的可见范围.而在Spring容器中是指其创建的Bean对象相对于其他Bean对象的请求可见范围. Sprin ...

  4. C#.NET 各种连接字符串

    C#.NET 各种连接字符串 近期连接数据库时,经常忘记连接字符串是如何的格式,现在此备注 此文章引用http://www.cnblogs.com/zhiqiang-imagine/archive/2 ...

  5. 【转载】iOS 设置Launch Image 启动图片(适用iOS9)

    Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以 ...

  6. uva 230 Borrowers(摘)<vector>"结构体“ 膜拜!

    I mean your borrowers of books--those mutilators of collections, spoilers of the symmetry of shelves ...

  7. codeforces 335A Banana(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud    Banana Piegirl is buying stickers for ...

  8. (原)VS2013在Release情况下使用vector有时候会崩溃的一个可能原因

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5016352.html 参考网址: http://www.cnblogs.com/BryZ/archiv ...

  9. j2ee中request.getQueryString()

    比如发送http://localhost/test.do?a=b&c=d&e=f得到的是a=b&c=d&e=f

  10. 用Dockerfile构建docker image

    dockerfile是为快速构建docker image而设计的,当你使用docker build 命令的时候,docker 会读取当前目录下的命名为Dockerfile(首字母大写)的纯文本文件并执 ...