当前位置:网站首页 / Linux / 正文

IPTABLES 开启端口的方法

时间:2017年05月20日 | 作者 : liuhui | 分类 : Linux | 浏览: 6731次 | 评论 0

阿里云限量代金券 | 此广告位出租25元/月

关闭 firewall


查看防火墙状态:

systemctl status firewalld

开放指定端口:

firewall-cmd --permanent --zone=public --add-port=8888/tcp #8888是你需要打开的端口

关闭防火墙

systemctl stop firewalld

阿里云默认防火墙是 firewall

安装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

查看端口状态


iptables -L -n


原文转自 乐可开源

原文链接:https://lekee.cc/882.html


推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信