浅谈简单使用CentOS7防火墙及开放端口

2019-10-09 16:45:36王振洲

概述(官方有更为详细的说明哦)

Firewalld提供动态管理的防火墙,支持网络/防火墙区域,用于定义网络连接或接口的信任级别。它支持IPv4,IPv6防火墙设置,以太网桥和IP集。运行时和永久配置选项分开。它还为服务或应用程序提供了直接添加防火墙规则的接口。

既然是简单使用, 那必须教会你怎么查看防火墙状态, 以及防火墙的关闭和开启之类的, 我们都知道那既然防火墙都开启了, 那么它必定是有一些端口的限制, 不能说你想通过哪些端口就通过哪些端口, 就能访问到我们的主机(也就是服务器了), 换句说话, 我开放了哪些端口, 你才可以通过我开放的这些端口对我的主机进行访问, 要不然我们还要防火墙干嘛, 谁想进来就进来(还是通过任意端口), 防火墙不就成了摆设不成, 说到防火墙要还要多说一句, 防火墙有软件层面的和物理设置层面的(网络内的一台专业物理设备), 那我们这里是所说的是软件层面的防火墙也就是Firewalld, CentOS7以下版本普遍使用的软件防火墙是Firewalld, 为什么说是CentOS7以下版本普遍使用的呢? 这是因为之前的CentOS版本都是使用的iptables防火墙, 那要往深处说, 这就要追溯到CentOS7的发展历程及RedHad之间的关系啦, 扯远了哈, 我们使用防火墙的主要目的是对我们的主机进行安全管理, 其中主要的一部分就是端口管理了!

查询防火墙状态

shell

# systemctl status firewalld

execute

[warnerwu@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)

启动防火墙

注意:防火墙只有管理员或管理员用户组有权限进行管理操作, 普通用户则不可以

shell

# systemctl start firewalld

execute

[root@localhost~]# systemctl start firewalld
[root@localhost~]#

你会发现什么也没有, 玩 linux 或 osx 系统的小伙伴都知道, 没有提示那就是最好的提示, 说明已经成功啦, 有提示时则一会有问题哦

再次查看防火墙状态

shell

# systemctl status firewalld

execute

[root@localhost ~]# sudo 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 五 2018-09-07 00:04:55 CST; 5min ago
   Docs: man:firewalld(1)
 Main PID: 11339 (firewalld)
  CGroup: /system.slice/firewalld.service
      └─11339 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z systemd[1]: Starting firewalld - dynamic firewall daemon...
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z systemd[1]: Started firewalld - dynamic firewall daemon.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignorin...-time.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignori...-time.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
9月 07 00:04:55 izj6c3bcx7adgva5dda2e0z firewalld[11339]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignorin...-time.
Hint: Some lines were ellipsized, use -l to show in full.