Board logo

标题: CentOS8防火墙(firewalld) [打印本页]

作者: admin    时间: 2020-1-30 14:35     标题: CentOS8防火墙(firewalld)

CentOS5/6的防火墙叫netfilter,CentOS7/8的防火墙叫firewalld 查看操作系统的版本: 图片1.png 查看防火墙firewalld的版本: [root@centos8 ~]# firewall-cmd --version 0.8.0 查看区域信息:  (默认zone就是 public ) [root@centos8 ~]# firewall-cmd --get-active-zones public interfaces: ens160 查看指定网卡接口所属区域: [root@centos8 ~]# firewall-cmd --get-zone-of-interface=ens160 public 查看firewalld所有打开的服务: [root@centos8 ~]# firewall-cmd --zone=public --list-services cockpit dhcpv6-client ssh 注释: cockpit、dhcpv6-client、ssh 是默认就有的,这些服务的默认端口是可以被访问。 查看firewalld所有打开的端口: firewall-cmd --zone=public --list-ports 图片1.png 查看firewalld的当前配置信息:(firewalld的初始状态) firewall-cmd --list-all 图片2.png 查看firewalld的配置文件:(firewalld的初始状态) [root@centos8 ~]# cat /etc/firewalld/zones/public.xml Public For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. 打开一个TCP端口:(TCP 25) firewall-cmd --zone=public --add-port=25/tcp --permanent 注释: --permanent 永久生效,没有此参数服务器重启后失效 重新加载firewalld的配置: firewall-cmd --reload 图片4.png 查看firewalld所有打开的端口: firewall-cmd --zone=public --list-ports 图片5.png 一次性打开两个TCP端口:(TCP 110、143) [root@centos8 ~]# firewall-cmd --zone=public --add-port={110/tcp,143/tcp} --permanent success [root@centos8 ~]# firewall-cmd --reload success 查看firewalld所有打开的端口: firewall-cmd --zone=public --list-ports 图片6.png 查看单个TCP端口是否开启: [root@centos8 ~]# firewall-cmd --zone=public --query-port=25/tcp yes [root@centos8 ~]# firewall-cmd --zone=public --query-port=80/tcp no 删除一个TCP端口: [root@centos8 ~]# firewall-cmd --zone=public --remove-port=25/tcp --permanent success [root@centos8 ~]# firewall-cmd --reload success 查看防火墙所有打开的端口: firewall-cmd --zone=public --list-ports 图片7.png 打开连续的UDP端口、TCP端口: firewall-cmd --zone=public --add-port=800-880/udp --permanent firewall-cmd --zone=public --add-port=900-990/tcp --permanent firewall-cmd --reload 查看防火墙所有打开的端口: [root@centos8 ~]# firewall-cmd --zone=public --list-ports 110/tcp 143/tcp 800-880/udp 900-990/tcp 删除连续的UDP端口、TCP端口: firewall-cmd --zone=public --remove-port=800-880/udp --permanent firewall-cmd --zone=public --remove-port=900-990/tcp --permanent firewall-cmd --reload 查看firewalld所有打开的端口: [root@centos8 ~]# firewall-cmd --zone=public --list-ports 110/tcp 143/tcp firewalld打开服务(HTTP):(相当于打开TCP 80端口) [root@centos8 ~]# firewall-cmd --zone=public --add-service=http --permanent success [root@centos8 ~]# firewall-cmd --reload success 查看firewalld所有打开的服务: [root@centos8 ~]# firewall-cmd --zone=public --list-services cockpit dhcpv6-client http ssh 笺注:假如HTTP的端口不是默认的TCP 80,客户端则不能访问了;需要另外在firewalld打开与HTTP对应的TCP端口。 此时直接检测TCP 80端口是否开启的话,会如下显示,但不会影响客户端访问HTTP: [root@centos8 ~]# firewall-cmd --zone=public --query-port=80/tcp no 删除一个服务: [root@centos8 ~]# firewall-cmd --zone=public --remove-service=cockpit --permanent success [root@centos8 ~]# firewall-cmd --reload success 查看firewalld所有打开的服务: [root@centos8 ~]# firewall-cmd --zone=public --list-services dhcpv6-client http ssh 查看firewalld的配置文件: [root@centos8 ~]# cat /etc/firewalld/zones/public.xml Public For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. 可以在配置文件里修改,然后重新加载firewalld的配置: [root@centos8 ~]# firewall-cmd --reload success 相关文章: CentOS8_NFS共享存储服务 CentOS8使用Cockpit管理服务器 CentOS8_安装与配置邮件服务器(Postfix+dovecot) 使用Navicat远程管理MySQL8.0 CentOS8_vsftpd匿名用户 CentOS8_PureFTPd虚拟用户验证 CentOS8_lnmp1.7_单独安装数据库(MariaDB) CentOS8防火墙(netfilter) CentOS8基本命令 最小化安装CentOS8 Zabbix使用SNMP监控CentOS8/Redhat8 CentOS8_firewalld+Nginx CentOS7.8_firewalld+SSH

图片附件: 图片1.png (2020-9-16 16:18, 8.12 KB) / 下载次数 150
http://blog.zhuohua.store/attachment.php?aid=11451&k=7c332a02a1a358d845f27c4c03c8cd85&t=1714437092&sid=C9jm9C



图片附件: 图片1.png (2021-2-1 10:26, 12.91 KB) / 下载次数 131
http://blog.zhuohua.store/attachment.php?aid=15294&k=b9e8c6926a5741ac62707cbd7358627b&t=1714437092&sid=C9jm9C



图片附件: 图片2.png (2021-2-1 10:26, 16.86 KB) / 下载次数 117
http://blog.zhuohua.store/attachment.php?aid=15295&k=bcbdbd372ab0dcb00579b983f26cc9cb&t=1714437092&sid=C9jm9C



图片附件: 图片4.png (2021-2-1 10:28, 14.19 KB) / 下载次数 114
http://blog.zhuohua.store/attachment.php?aid=15296&k=312275897d0fe09aa1c2dafb2702fbb9&t=1714437092&sid=C9jm9C



图片附件: 图片5.png (2021-2-1 10:29, 15.91 KB) / 下载次数 129
http://blog.zhuohua.store/attachment.php?aid=15297&k=d8caca2e72b29d7e45c3596cc8b77eb2&t=1714437092&sid=C9jm9C



图片附件: 图片6.png (2021-2-1 10:29, 13.42 KB) / 下载次数 128
http://blog.zhuohua.store/attachment.php?aid=15298&k=598710249004ec625f0aa60439736ddd&t=1714437092&sid=C9jm9C



图片附件: 图片7.png (2021-2-1 10:31, 12.13 KB) / 下载次数 117
http://blog.zhuohua.store/attachment.php?aid=15299&k=ab8ad0834fb73dc0668157dc1e766577&t=1714437092&sid=C9jm9C






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2