防火墙设置开放端口
Posted 健康平安的活着
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了防火墙设置开放端口相关的知识,希望对你有一定的参考价值。
一 访问linux的nginx
1.1 描述
在windows的系统中访问linux的nginx,默认是不能访问的,原因在于防火墙。解决办法
1.关闭防火墙;
2.开启防火墙,在防火墙中设置指定对外访问的端口。
查看端口:firewall-cmd --list-all
设置开放端口:
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
重启防火墙:
firewall-cmd --reload
二 查看防火墙端口
2.1 查看防火墙状态
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@localhost ~]# pwd
2.2 开启防火墙
[root@localhost sbin]# systemctl start firewalld
[root@localhost sbin]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2021-05-06 19:00:49 CST; 35min ago
Docs: man:firewalld(1)
Main PID: 2904 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─2904 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
May 06 19:00:49 localhost.localdomain systemd[1]: Starting firewalld - dyna...
May 06 19:00:49 localhost.localdomain systemd[1]: Started firewalld - dynam...
Hint: Some lines were ellipsized, use -l to show in full.
2.3 查看端口
[root@localhost sbin]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
2.4 开启制定端口
[root@localhost sbin]# firewall-cmd --add-service=http --permanent
success
[root@localhost sbin]# firewall-cmd --add-port=80/tcp --permanent
success
1.5 重启防火墙
[root@localhost sbin]# firewall-cmd --reload
success
[root@localhost sbin]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client http
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
以上是关于防火墙设置开放端口的主要内容,如果未能解决你的问题,请参考以下文章