CentOS防火墙配置

1. 使用setup命令

[1] 打开一个终端窗口,输入setup命令

[root@localhost ~]# setup

[2] 选择Firewall configuration, 选择Run Tool,进入防火墙配置界面

image

[3] 勾选Enabled开启防火墙,不勾选则不开启,此处开启,并选择Customize进行自定义配置

image

[4] 选择要开放的服务端口,此例选择FTP,WWW(HTTP)。默认SSH服务端口是开启的,用于SSH远程登陆,如果是远程配置Linux服务器,则一定要保持SSH服务端口打开,不要自断后路。

image

[5] 配置好后一路Forward到最后保存即可,若还有其它的端口要开放,中间也有相应的自定义页面。最后到这个页面时选择Yes,覆盖原设置保存。

image

 

 

2. 命令行方式

[1] 编辑防火墙配置,21端口和80端口是增加的FTP服务与80服务端口

[root@localhost ~]# 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 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

[2] 关闭防火墙服务(暂时关闭防火墙服务,重启后服务会自动开启)

[root@localhost ~]# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]

[3] 配置防火墙服务默认开机不启动 (如果服务器不需要防火墙)

[root@localhost ~]# chkconfig iptables off
posted @ 2012-10-03 16:59  lightnear  阅读(2747)  评论(0编辑  收藏  举报