1 Linux 防火墙 端口号 相关操作
CentOS 7默认使用的是firewall作为防火墙
在虚拟机centos7上安装nginx之后虚拟机内能访问,真机不能访问,修改iptables配置也不起作用,最后上网查找了资料后才发现centos的防火墙改成了firewall,不再叫iptables,开放端口的方法如下:
1
| firewall-cmd --zone=public --add-port=80/tcp --permanent
|
1 2 3 4 5 6 7
| 命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
|
1 重启防火墙:
1 2 3
| systemctl stop firewalld.service systemctl start firewalld.service systemctl restart firewalld.service # 重启防火墙
|
2 添加端口号
1
| firewall-cmd --zone=public --add-port=端口号/tcp --permanent
|
https://filezilla-project.org/download.php?type=client
FileZilla Client

1 2
| 解压zip文件到当前目录 unzip filename.zip
|

上面这个不是Centos7的

上面这个不是Centos7的
3 CentOs7关闭防火墙的命令!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| 下面是red hat/CentOs7关闭防火墙的命令!
1:查看防火状态
systemctl status firewalld
service iptables status
2:暂时关闭防火墙
√
service iptables stop
3:永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
4:重启防火墙
systemctl enable firewalld
service iptables restart
5:永久关闭后重启
//暂时还没有试过
chkconfig iptables on
|
CentOS 7 默认没有使用iptables,所以通过编辑iptables的配置文件来开启80端口是不可以的
CentOS 7 采用了 firewalld 防火墙
如要查询是否开启80端口则:
1
| `[root@joe-pc ~]``# firewall-cmd --query-port=80/tcp``no`
|
显然80端口没有开启
下面我们开启80端口:
1
| `[root@joe-pc ~]``# firewall-cmd --add-port=80/tcp``success`
|
小记
- 通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。

- 通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。

- 再次执行执行firewall-cmd –permanent –zone=public –add-port=3306/tcp,提示success,表示设置成功,这样就可以继续后面的设置了

Nginx
linux如何查看nginx是否启动
ps -ef | grep nginx 就可以看到Nginx进程是否存在了
ps -C nginx -o pid
netstat -anp | grep :80命令来判断Nginx是否启动
lsof -i:80 也可以查到80端口进程是否有进程在运行。
1 2 3 4
| (1)查看对外开放的端口状态 查询已开放的端口 netstat -anp 查询指定端口是否已开 firewall-cmd --query-port=666/tcp 提示 yes,表示开启;no表示未开启。
|
1 2 3
| (3)对外开发端口 查看想开的端口是否已开: firewall-cmd --query-port=6379/tcp
|
1 2 3 4 5 6
| 添加指定需要开放的端口: firewall-cmd --add-port=123/tcp --permanent 重载入添加的端口: firewall-cmd --reload 查询指定端口是否开启成功: firewall-cmd --query-port=123/tcp
|
1 2
| 移除指定端口: firewall-cmd --permanent --remove-port=123/tcp
|
Linux ifconfig

1
| 第一步:进入到/etc/sysconfig/network-scripts/目录下,
|
1 2 3
| 用ls命令查看网卡配置文件名(在CENTOS7中网卡名貌似变成了随机数字,所以每台机器的网卡名并不相同)
ifcfg-eno6777736
|
1 2 3 4 5
| 用vi命令编辑文件 将最后一行的ONBOOT=NO修改为yes,最后输入:wq 保存并退出。
将最后一行的ONBOOT=NO修改为yes,最后输入:wq 保存并退出。
ping www.baidu.com出现下图说明网络通了
|

Linux 文件权限系统 慕课网
Author:
John Doe
Permalink:
http://yoursite.com/2018/12/01/Linux/Linux小结/
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?