操作系统版本 [oracle@strong ~]$ cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) 官网地址 http://www.firewalld.org/ 1、firewalld的基本使用启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 : systemctl enable firewalld 查看开机是否启用 : systemctl is-enabled firewalld 2、配置firewalld-cmd查看版本: firewall-cmd --version 查看帮助: firewall-cmd --help 显示状态: firewall-cmd --state 查看所有打开的端口: firewall-cmd --zone=public --list-ports 更新防火墙规则: firewall-cmd --reload 查看区域信息: firewall-cmd --get-active-zones 查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0 拒绝所有包:firewall-cmd --panic-on 取消拒绝状态: firewall-cmd --panic-off 查看是否拒绝: firewall-cmd --query-panic 禁止1521端口号[root@strongservices]# firewall-cmd --permanent --remove-port=1521/tcp --permanent (永久禁用) success [root@strong services]# firewall-cmd--list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 1521/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@strong services]# firewall-cmd--reload success [root@strong services]# firewall-cmd--list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@strong services]# 验证[oracle@sztech ~]$ sqlplussys/oracle@192.168.0.145:1521/orcl as sysdba SQL*Plus: Release 11.2.0.4.0 Production onWed Nov 25 14:47:56 2020 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-12543: TNS:destination host unreachable Enter user-name: 允许1521端口连接[root@strong services]#firewall-cmd --permanent --add-port=1521/tcp --permanent success [root@strong services]# firewall-cmd --reload success [root@strong services]# firewall-cmd--list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 1521/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: 验证[oracle@sztech ~]$ sqlplussys/oracle@192.168.0.145:1521/orcl as sysdba SQL*Plus: Release 11.2.0.4.0 Production onWed Nov 25 14:51:17 2020 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining andReal Application Testing options SQL> select name from v$database; NAME --------- ORCL SQL> 禁止192.168.0.156访问[root@strongservices]# firewall-cmd --permanent --add-rich-rule="rulefamily="ipv4" source address="192.168.0.156" reject" success [root@strong services]# firewall-cmd --reload 立即生效 success [root@strong services]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 1521/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: rulefamily="ipv4" source address="192.168.0.156" reject [root@strong services]# 验证[oracle@sztech ~]$ ping 192.168.0.145 PING 192.168.0.145 (192.168.0.145) 56(84)bytes of data. From 192.168.0.145 icmp_seq=1 DestinationPort Unreachable From 192.168.0.145 icmp_seq=2 DestinationPort Unreachable From 192.168.0.145 icmp_seq=3 DestinationPort Unreachable From 192.168.0.145 icmp_seq=4 DestinationPort Unreachable [oracle@sztech ~]$sqlplus sys/oracle@192.168.0.145:1521/orcl as sysdba SQL*Plus: Release 11.2.0.4.0 Production onWed Nov 25 14:58:04 2020 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-12541: TNS:no listener Enter user-name: 其他IP连接测试C:\Users\Administrator>sqlplussys/oracle@192.168.0.145:1521/orcl as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期三 11月 25 15:16:242020 Copyright (c) 1982, 2010, Oracle. All rights reserved. 连接到: Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Miningand Real Application Testing options SQL> 恢复192.168.0.156访问[root@strong services]# firewall-cmd--permanent --add-rich-rule="rule family="ipv4" sourceaddress="192.168.0.156" accept" success [root@strong services]# firewall-cmd--reload success [root@strong services]# firewall-cmd--permanent --list-all public target: default icmp-block-inversion: no interfaces: sources: services: dhcpv6-client ssh ports: 1521/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: rulefamily="ipv4" source address="192.168.0.156" reject rule family="ipv4" sourceaddress="192.168.0.156" accept [root@strong services]# 验证[oracle@sztech admin]$ sqlplussys/ORACLE@192.168.0.145:1521 as sysdba SQL*Plus: Release 11.2.0.4.0 Production onWed Nov 25 15:23:21 2020 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-12541: TNS:nolistener Enter user-name: 报错没有监听,是因为富规则的优先级关系 rulefamily="ipv4" source address="192.168.0.156" reject rulefamily="ipv4" source address="192.168.0.156" accept 解决办法:移除禁止IP的规则 [root@strongservices]# firewall-cmd --permanent --remove-rich-rule="rulefamily="ipv4" source address="192.168.0.156" reject" success [root@strongservices]# firewall-cmd --reload success [root@strongservices]# firewall-cmd --permanent--list-all public target: default icmp-block-inversion: no interfaces: sources: services: dhcpv6-client ssh ports: 1521/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: rule family="ipv4" sourceaddress="192.168.0.156" accept [root@strongservices]# [oracle@sztechadmin]$ sqlplus sys/oracle@192.168.0.145:1521/orcl as sysdba SQL*Plus:Release 11.2.0.4.0 Production on Wed Nov 25 15:27:39 2020 Copyright(c) 1982, 2013, Oracle. All rightsreserved. Connectedto: OracleDatabase 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production Withthe Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
|