CentOS 中 iptables 和 firewall 防火墙的相关命令

关于端口开启了然后无法访问无外乎就几种情况。假如是阿里云的服务器,那可能是安全组-入方向没有设置。要么就是防火墙端口未开放。下面我归纳了下关于centos防火墙的相关命令。

iptables防火墙

查看防火墙状态

service iptables status 

停止防火墙

service iptables stop 

启动防火墙

service iptables start   

重启防火墙

service iptables restart   

永久关闭防火墙

chkconfig iptables off     

永久关闭后重启

chkconfig iptables on

开启80端口

vim /etc/sysconfig/iptables
// 加入如下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

保存退出后重启防火墙

service iptables restart

firewall防火墙

查看firewall服务状态

systemctl status firewalld

查看firewall的状态

firewall-cmd --state

开启、重启、关闭、firewalld.service服务

// 开启
service firewalld start
// 重启
service firewalld restart
// 关闭
service firewalld stop

查看防火墙规则

firewall-cmd --list-all

查询、开放、关闭端口

// 查询端口是否开放
firewall-cmd --query-port=8080/tcp
// 开放80端口
firewall-cmd --permanent --add-port=80/tcp
// 移除端口
firewall-cmd --permanent --remove-port=8080/tcp

//重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

查看防火墙规则

1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;

附录

1、netstat -nlp //查看所有端口的监听情况
2、netstat -nlp |grep 80 //查看某个端口的监听情况
3、ps -ef | grep httpd //查看某个服务的运行状况
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!