召隆企博汇论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 870|回复: 0

Centos 7 firewall防火墙打开端口

[复制链接]

24

主题

5

回帖

199

积分

公司现有员工

积分
199
发表于 2020-1-9 08:41:07 | 显示全部楼层 |阅读模式
本帖最后由 myskya 于 2020-3-8 22:36 编辑 3 l. X* S+ b9 v+ B1 u( l: c
0 g* c% U: X6 ^- q4 A
一、启动服务, K" I1 X* n4 E6 S
如果没有安装,可以使用yum install firewall
7 b" ~; u# E: [, x  e3 a系统默认是已经安装了,但是没有启动
5 W" n# i) w" H1、开机自启动
6 s' C. f0 O0 S7 R: }2 wsystemctl enable firewalld& P) c" K( C9 T+ r  p+ W
2、启动服务
$ O9 n6 Z* y$ m( P2 G/ a" \( Ksystemctl start firewalld- s$ r' h: ], O* v: m3 J3 G
二、向防火墙添加可以外部访问的端口
, J  c& E# l6 b) gfirewall-cmd --zone=public --add-port=80/tcp --permanent & ?. k' F" x7 l' M2 {& ~
以下是常用的端口
; }  e6 b* x! r6 w+ `* Ffirewall-cmd --zone=public --add-port=443/tcp --permanent' e: r' A( ^$ C0 G
firewall-cmd --zone=public --add-port=22/tcp --permanent
9 o2 G. g4 e: ?5 e, ]! ?6 A1、如果需要添加一段端口的话,使用以下命令/ |. ~( f# m7 q
firewall-cmd --zone=public --add-port=8000-8100/tcp --permanent
1 J# ~' c  ?; m* _/ y这儿是指添加101个端口
( F! p. z8 o/ H1 n8 P, ]三、向防火墙添加相应的服务firewall-cmd --zone=public --add-service=dns --permanent: K) v" H) U! g
具体的服务名称在以下路径里有一个文件就是一个service 名称
8 N; V* P  o6 J% q' G% W& j" t0 C
/usr/lib/firewalld/services
9 X1 V: ^7 ?- A% t3 I( s7 Y" j7 K  \& H7 d. s+ q. u. O0 R) [  g
四、添加完端口之后需要让防火墙生效- o9 f' f5 T. x$ n6 J- w$ U/ q
1、重新加载8 ^* {6 {) c$ n! {+ u( c3 Z
firewall-cmd --reload' z8 ?, t) s9 U; n) F
2、查看当前已经开放的端口3 |, F* R/ h  ~+ }- Z% H8 Y
firewall-cmd --list-ports5 ~9 R3 E0 a; Q- Y5 a) D' }" X/ s
firewall-cmd --list-all# `' D2 T1 V+ C* S! f2 w
3、删除某个不用的端口
" V+ l1 x0 s% @  Y. ~firewall-cmd --zone=public --remove-port=8084/tcp --permanent
2 X6 ]+ z+ X+ v注意,这儿删除只是删除一条规则,我上面加的8000-8100,其实还是可以访问8084这个端口的# B: ]; n1 j1 d8 {. f! b  n: T

* d4 y! V+ m  H+ T  f' v* ~$ D( C9 A$ A1 C7 o: q
4 M/ p  B- f; X; E! l7 J5 s* v
其他常用命令% D+ a/ F1 H2 _# G1 R( }6 K
9 ~$ ~. R1 q1 ]% S
% H. x. ]$ r! f8 B6 E' C
  1. firewall-cmd --list-all-zones    #查看所有的zone信息
    7 p9 [2 m7 b% M* [2 ^' w& N
  2. firewall-cmd --get-default-zone     #查看默认zone是哪一个
    ! G' a2 {9 \- B) ]: V* _
  3. firewall-cmd --zone=internal --change-zone=p3p1  #临时修改接口p3p1所属的zone为internal6 ~2 ^' f$ E2 P% u; j
  4. firewall-cmd --add-service=http    #暂时开放http
    * I3 S! m6 S- h2 D# l
  5. firewall-cmd --permanent --add-service=http  #永久开放http
    ) ]- B/ W4 F7 H% D
  6. firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久开放80端口
    2 N3 n* z. S5 H3 m4 Y
  7. firewall-cmd --permanent --zone=public --remove-service=ssh   #从public zone中移除服务- L4 v, Z6 X7 U, z
  8. firewall-cmd --reload   #重新加载配置
    9 h% C+ [0 w3 ?; v# y. U) w
  9. systemctl restart firewalld    #重启firewalld服务,使配置生效/可查
复制代码
- E( p/ @; b( S% k- E
% _. I! c. z/ Y9 a
( z# n6 j  \6 q3 X8 Y2 `4 y: w+ Q

$ ^. _/ s! K0 w( u3 P* H8 r
1 _$ a5 L3 T$ J0 }$ ]$ z

, ?4 K4 D2 r. J2 Y( W2 _0 M

# ?4 t! _4 G- P1 |2 k; y/ B) T' Y3 P5 g) \
2 w+ g) f9 `1 g2 _# m  F3 b- q) N
/ J  _7 n) P" q! O- E

# S8 j5 _% R8 r2 f; s& b& j( j4 n% _- Y5 L3 k! a/ S$ K  o' @. P
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|召隆企博汇 ( 粤ICP备14061395号 )

GMT+8, 2025-4-2 13:45 , Processed in 0.078238 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表