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. Sql server Lock

    http://www.cnblogs.com/wuyifu/archive/2013/11/28/3447870.html

  2. VB短信猫开发包,支持超长短信

    一.短信猫开发包(长短信/异步调用)说明:   短信猫开发包以OCX控件的形式提供,支持Windows平台下常用的开发工具:如VB.VB.net.VC++.Power Builder.C#.DELPH ...

  3. icon数目

    [UIApplication sharedApplication].applicationIconBadgeNumber = currentBadgeValue.integerValue;

  4. POJ 1723 SOLDIERS (中位数)

    题目大意: 平面上有N(N<=10000)个点,求这些点变成一条水平线的最小移动步数. 算法讨论: 表示自己太弱弱了,打算从今天开始提高一下智商. 我们考虑,既然是要成一条水平线,那么这条直线的 ...

  5. UVa1592 数据库(摘)

    输入一个n行m列的数据库(1<=n<=10000,1<=m<=10),是否存在两个不同行r1,r2和两个不同列c1,c2,使得这两行和这两行相同(即(r1,c1)和(r2,c1 ...

  6. 写一个Windows上的守护进程(5)文件系统重定向

    写一个Windows上的守护进程(5)文件系统重定向 在Windows上经常操作文件或注册表的同学可能知道,有"文件系统/注册表重定向"这么一回事.大致来说就是32位程序在64位的 ...

  7. nopCommerce 3.3正式发布及新增功能改进

    nopCommerce是一套优秀开源且基于Asp.net MVC的开源商城系统,nopCommerce 3.x经历长时间多个版本重构优化改进,目前已经趋于完善与成熟! nopCommerce 3.3正 ...

  8. [C++程序设计]内置函数

    注意: 可以在声明函数和定义函数时同时写 inline,也可以只在其中一处声明inline,效果相同,都能按内置函数处理. 使用内置函数可以节省运行时间,但却增加了目标 程序的长度.因此一般只将规模很 ...

  9. python之安装

    1.python控制软件pyenv 依赖软件:git [root@localhost ~]# curl https://raw.github.com/yyuu/pyenv-installer/mast ...

  10. 在virtualenv中安装libxml2和libxslt

    在使用python的工作中,需要使用到libxml2和libxslt库.原来在实际环境中已经安装完成了,但是在virtualenv中还没有,现在正在整理virtualenv的环境.下面把在virtua ...