服务器开放端口
warning:
这篇文章距离上次修改已过1669天,其中的内容可能已经有所变动。
有的时候服务/软件配置没有问题,就是无法访问,可能是你没有在主机上开放对应的端口。
防火墙设置
Error:注意:出于安全考虑不建议关闭防火墙!
centos命令:
#开放对应tcp端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
#开放对应udp端口
firewall-cmd --zone=public --add-port=80/udp --permanent
#防火墙重载配置
firewall-cmd --reload
#临时关闭防火墙(不推荐)
systemctl disable firewalld
#禁用防火墙(不推荐)
systemctl stop firewalld
通用命令:
Error:注意:出于安全考虑不建议关闭防火墙!
#编辑防火墙规则
sudo vim /etc/sysconfig/iptables
#添加22端口tcp协议规则
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
#添加22端口udp协议规则
iptables -A INPUT -p udp --dport 22 -j ACCEPT
iptables -A OUTPUT -p udp --sport 22 -j ACCEPT
#检查防火墙规则
iptables -L -n
#保存防火墙的设置
serivce iptables save
#重启防火墙
service iptables restart
#永久开启防火墙
chkconfig iptables on
#永久关闭防火墙
chkconfig iptables off
#临时开启防火墙
service iptables start
#临时关闭防火墙
service iptables stop
云服务器控制台
这里以阿里云为例。
1. 首先打开控制台

2. 打开云服务器ECS

3. 打开对应服务器的安全组

4. 添加规则(出方向默认全放行,只管理入方向即可)



5. 查看效果
