Centos6.5配置防火墙

1、查看防火墙状态

# /etc/init.d/iptables status

2、启动/关闭防火墙

  • 开启防火墙
# service iptables start
  • 关闭防火墙
# service iptables stop
  • 开机自启
开启: chkconfig iptables on
关闭: chkconfig iptables off

3、开放指定端口

  • 比如我要开放3306三个端口,可以在/etc/sysconfig/iptables文件中添加三行信息,如下:
vi /etc/sysconfig/iptables

内容修改成如下:
# Firewall configuration written by system-config-firewall 
# Manual customization of this file is not recommended. 
*filter 
:INPUT ACCEPT [0:0] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [0:0] 
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT 

-A INPUT -j REJECT –reject-with icmp-host-prohibited 
-A FORWARD -j REJECT –reject-with icmp-host-prohibited 
COMMIT
  • 修改后重启防火墙
service iptables restart
posted @ 2021-11-17 17:39  猪脚踏浪  阅读(332)  评论(0编辑  收藏  举报