7

CentOS8下开启L2TP后Firewalld失效的解决方法

 2 years ago
source link: https://blog.starryloki.com/2021/04/10/CentOS8%E4%B8%8B%E5%BC%80%E5%90%AFL2TP%E5%90%8EFirewalld%E5%A4%B1%E6%95%88%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Loki's Blog

CentOS8下开启L2TP后Firewalld失效的解决方法

Created2021-04-10|Updated2021-06-02|Notes
Word count:632|Reading time:2min|Post View:6

最近开始上数据库原理与应用,需要用到SQL,而我主要使用macOS进行日常操作。不同于Windows,macOS上搭建SQL Server需要借助docker,而macOS Arm版本的Docker仍属于测试版,有许多不稳定的因素,于是打算在我的服务器上部署ms-sqlserver。但是微软并未对Ubuntu 20.04发布ms-sqlserver对release,docker上的ms-sqlserver也有许多莫名其妙的bug,于是我计划将我的服务器迁移到CentOS 8上(49年入国军),顺便体验和学习CentOS。

迁移总体上很顺利,原来运行在Ubuntu上的Shadowsocks和L2TP服务端以及其他服务和环境都十分顺利的迁移到CentOS上了,ms-sqlserver也安装成功。但是后续的操作却出现了一些exception。

CentOS相比Ubuntu有一个很显著的区别是自带了防火墙,每安装一个服务都需要将对应的端口设为ACCEPT。但是在安装好L2TP服务后,我尝试在防火墙添加端口,却提示 FirewallD is not running

CentOS 8.3.2011 x86_64

既然Firewalld没有在运行,先看看这个服务的状态:

于是使用systemctl unmask firewalld.service

systemctl start firewalld.service

发现服务成功启用,firewall-cmd指令也成功被执行,于是以为问题被解决。

后来发现系统重启之后,从学校内网无法正常使用L2TP服务器:能顺利连接并获得VPN内网IP,但是无法访问VPN IP外的其他地址,初步推测是转发环节出了问题。

我是使用wget https://git.io/vpnsetup-centos -O vpn.sh && sudo sh vpn.sh && sudo bash /opt/src/ikev2.sh --auto这个脚本一键部署l2TP/IPSec服务,出了问题自然首先重新执行一次脚本,重新执行后发现L2TP连接回归正常,但是Firewalld又失效了,于是开始解析脚本。

在脚本中发现了相关操作

不难发现脚本将相关的转发操作部署在nftables里面,然后将firewalld给mask了,而ntfables的操作比firewalld复杂得多,经过短时间的研究,大概了解到可以通过
nft insert rule inet firewalld filter_IN_public_allow {protol} dport {port} accept

nft insert rule inet firewalld filter_INPUT {protol} dport {port} accept

来将端口设置为ACCEPT,并通过

nft list ruleset inet

来查看已经开放的端口。

目前还不知道怎样通过firewalld来实现L2TP的转发,有知道的朋友欢迎在评论区留言。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK