美文网首页
阿里云 ECS CentOS 7 打开端口的方法

阿里云 ECS CentOS 7 打开端口的方法

作者: Buckler | 来源:发表于2017-11-27 16:35 被阅读90次

关闭防火墙(网上的大部分资料都是用iptables防火墙的,但是阿里云的centos 7默认防火墙是firewall。最为简单的方法其实就是关闭我们的防火墙)
查看下防火墙的状态:

systemctl status firewalld

关闭防火墙:

systemctl stop firewalld

安装iptables(由于没有防火墙会造成不安全,所以给服务器安装一应用更广的防火墙iptables,首先要禁用firewall,通过yum安装iptables):

systemctil disable firewalld
yum install -y iptables-services

启动iptables:

systemctl start iptables

启动后可以通过如下命令查看状态。

systemctl status iptables

更改iptables规则:
将iptables文件备份下:

cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.bak

设置 INPUT 方向所有的请求都拒绝

iptables -P INPUT DROP

放开所需端口

iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
iptables -I INPUT -p tcp --dport 3000 -m state --state NEW -j ACCEPT

保存规则

iptables-save > /etc/sysconfig/iptables

设置为开机启动并且重启

systemctl enable iptables.service
systemctl reboot

相关文章

网友评论

      本文标题:阿里云 ECS CentOS 7 打开端口的方法

      本文链接:https://www.haomeiwen.com/subject/viydbxtx.html