> CentOS > CentOS入门 >

CentOS防火墙iptables安装及配置

安装
yum install iptables

配置
vim /etc/sysconfig/iptables

例如:
*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

# web
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# ftp
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

# ssh
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT


查看端口状态
/etc/init.d/iptables status

启动/停止/重启
service iptables start/stop/restart



(责任编辑:IT)