探索Linux 6和7的防火墙

非Oracle Linux下安装Oracle 19c》曾提到了关闭防火墙,

[root@bisal ~]# systemctl stop firewalld.service
[root@bisal ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

但是实际上,这是非常不安全的做法,正确的做法,应该是让防火墙来限制对应用的合理访问。

在监听启动的情况下,应用的客户端得到的错误是ORA12170,基本可以肯定是服务器没有开放1521端口(默认),

ORA-12170:TNS:连接超时

防火墙增加1521端口的配置操作,在Linux 6和7中,有所不同。

Linux 6

如果需要让防火墙允许1521端口访问,用root账号编辑/etc/sysconfig/iptables,增加以下内容,

-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT

重启iptables,生效配置,如果要重启依然有效,执行service iptables save,

[root@bisal ~]# service iptables restart
iptables: Applying firewall rules: [  OK  ]

使用iptable -L -n,可以看到当前生效的策略,

P.S. 或者service iptables status

[root@bisal ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 13 
...
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:1521 

如果需要系统重启后生效,开机自启动,或者自动关闭,

开启:chkconfig iptables on
关闭:chkconfig iptables off

如果需要系统即时生效,系统重启后失效,

开启:service iptables start关闭:service iptables stop

Linux 7

首先执行firewall-cmd,查看当前策略,默认是空的,即不允许其他端口的访问,

[root@bisal]# firewall-cmd --zone=public --list-ports


如果需要让防火墙允许1521端口访问,执行以下操作,表示将1521端口加入public(这个zone是防火墙新特性,他的作用就是定义了网络区域网络连接的可信等级)区域中,permanent参数表示永久生效,即重启的时候不会失效,

[root@bisal]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
success

得重新加载防火墙配置,更新防火墙规则,

[root@bisal]# firewall-cmd --reload
success

此时查看策略,1521端口访问策略已经生效,

[root@bisal]# firewall-cmd --zone=public --list-ports
1521/tcp

如果需要系统重启后生效,开机自启动,或者自动关闭,

开启:systemctl enable firewalld
关闭:systemctl disable firewalld

如果需要系统即时生效,系统重启后失效,

开启:systemctl start firewalld关闭:systemctl stop firewalld

查看开机是否启动防火墙,

systemctl is-enabled firewalld

查看防火墙状态,

systemctl status firewalld

比较来说,Linux 7的防火墙配置要更简单,尤其是显示策略的时候,直接返回“端口/协议类型”,例如“1521/tcp”,更加直观,这就是技术演进。

近期热文:

公众号600篇文章分类和索引

Oracle ACE,一段不可思议的旅程

Oracle 19c之RPM安装

从隐式转换案例,来挖掘开发人员的技能提升

应用执行慢的问题排查路径

ACOUG年会感想

千万级表数据更新的需求

探寻大表删除字段慢的原因

新增字段的一点一滴技巧

对recursive calls的深刻理解

《Oracle Concept》第三章 - 12

一次惊心动魄的问题排查

新型冠状病毒的了解

英超梦幻之行

藤子不二雄博物馆之行

传控Tiki-Taka战术解惑

你不看足球,你就不会懂:这些主场有多美?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值