在服务器上端口的开放是有限的,为了更好的避免服务器被攻击,在服务器上必须限制开发的端口。
一般我在用虚拟机的时候,都会直接将防火墙关闭。
一、查看防火墙的配置。
vi /etc/sysconfig/iptables
二、配置防火墙的端口,开放80,22,3306。
将下面的代码直接复制进配置中
# 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 #http -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #mysql -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -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
三、重启防火墙,设置随系统启动。
service iptables restart 或者 /etc/init.d/iptables restart 启动 chkconfig iptables on
四、关闭防火墙。
chkconfig iptables off
友情提示:垃圾评论一律封号...