0
点赞
收藏
分享

微信扫一扫

探索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”,更加直观,这就是技术演进。


举报

相关推荐

0 条评论