CentOS下配置iptables防火墙

系统 Linux
CentOS(Community ENTerprise Operating System)是Linux发行版之一,当我们使用CentOS时,我建议大家配置一个iptables,iptables 是与最新的 2.6.x 版本Linux 内核集成的 IP 信息包过滤系统.非常好用。下面我教大家在CentOS下配置iptables防火墙。

CentOS下配置iptables防火墙,是非常必要的。来我们学习如何配置!

  在Linux中设置防火墙,以CentOS为例,打开iptables的配置文件:

 

  1.   vi /etc/sysconfig/iptables  
  2.  

 

  通过/etc/init.d/iptables status命令查询是否有打开80端口,如果没有可通过两种方式处理:

  1.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口

 

  1.   -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  
  2.  

 

  2.关闭/开启/重启防火墙

 

  1.   /etc/init.d/iptables stop  
  2.  
  3.   #start 开启  
  4.  
  5.   #restart 重启  
  6.  

 

  3.***性关闭防火墙

 

  1.   chkconfig --level 35 iptables off  
  2.  
  3.   /etc/init.d/iptables stop  
  4.  
  5.   iptables -P INPUT DROP  
  6.  

 

  4.打开主动模式21端口

 

  1.   iptables -A INPUT -p tcp --dport 21 -j ACCEPT  
  2.  

 

  5.打开被动模式49152~65534之间的端口

 

  1.   iptables -A INPUT -p tcp --dport 49152:65534 -j ACCEPT  
  2.  
  3.   iptables -A INPUT -i lo -j ACCEPT  
  4.  
  5.   iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT  
  6.  

 

  注意:

  一定要给自己留好后路,留VNC一个管理端口和SSh的管理端口

  需要注意的是,你必须根据自己服务器的情况来修改这个文件。

  全部修改完之后重启iptables:

  service iptables restart

  你可以验证一下是否规则都已经生效:

  iptables -L

通过文章的介绍,我们清楚的知道了CentOS下配置iptables防火墙的过程,希望大家都能掌握它!

【编辑推荐】

  1. Centos5下安装iptables以及layer7协议
  2. Centos 5.3 环境下编译iptables
  3. CentOS+iptables+squid透明代理+防火墙设置
  4. centos IPTables 配置方法
  5. 创建iptables NAT 规则
  6. Ubuntu iptables 初始化的实现
  7. Ubuntu iptables 内网端口映射
责任编辑:赵鹏 来源: 互联网
相关推荐

2011-03-15 15:47:15

Iptables防火墙

2011-03-15 15:47:26

LinuxIptables防火墙

2014-08-05 09:50:40

CentOS防火墙

2011-03-15 16:35:27

2011-03-15 17:12:11

2010-03-29 13:08:24

CentOS防火墙

2011-03-17 16:00:57

2010-03-24 14:23:11

CentOS防火墙

2011-03-15 17:18:45

2011-03-15 17:38:24

2011-03-15 09:10:43

iptables防火墙

2011-03-17 10:58:55

Linux防火墙Iptables入门

2018-07-02 09:18:11

Linuxiptables防火墙

2011-03-16 11:20:26

2012-07-10 10:39:48

Linux防火墙

2010-01-07 14:12:11

Linux防火墙

2011-03-15 10:48:47

2011-03-16 10:17:06

2011-03-16 10:12:32

2011-02-15 10:44:27

点赞
收藏

51CTO技术栈公众号