openwrt 群晖 jellyfin ubuntu 等本地设备映射公网,超简单!

无流量限制,

速度快

配置简单

任意一个可以使用ssh链接的linux 系统中 ,比如本地搭建的ubuntu ,本次用本地同一电脑搭建的pve 搭建了openwrt 群晖 ubuntu ,其中操作在ubuntu中实现局域网所有应用可公网访问。

前期准备工作

cloudflare账号 :https://dash.cloudflare.com/

域名:https://www.namesilo.com

finalshell:https://www.hostbuf.com/

优质专线机场:https://jdssl.top/index.php/bluebeiyong/

本地ubuntu 或群晖 可以正常科学上网,修改网关 ,链接可以翻墙的软路由

ubuntu 网关修改

在/etc/netplan/文件目录下,修改01-netcfg.yaml文件(没有新建一个)代码如下:

network:
version: 2
ethernets:
ens18:
dhcp4: false # 禁用 DHCP,使用静态 IP
addresses:
- 192.168.xxx.xxx/24 # 设置静态 IP 地址(你linux的ip,根据你的局域网自己设置)
gateway4: 192.168.xxx.3 # 设置新的默认网关(你的软路由)
nameservers:
addresses:
- 192.168.xxx.3 # 设置 DNS 服务器(你的软路由)

应用更改:

sudo netplan apply

已產生圖像

安装cloudflare tunnel
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb

然后登录你的 Cloudflare 帐号,下方会出现一个链接,使用这个链接登录自己的cf账号,授权域名。

cloudflared tunnel login

创建一个tunnel,一般默认在这里/etc/cloudflared/,如果在root目录下,需要对应修改 下方cd 部分内容

cloudflared tunnel create myhome

创建config.yml

进入配置目录:


sudo mkdir -p /etc/cloudflared
sudo nano /etc/cloudflared/config.yml

将id xxx-xxx-xxx.json文件复制移动到etc/cloudflared文件目录下

cp /root/.cloudflared/<修改为你自己的id后的 xxx-xxx-xx.json> /etc/cloudflared/

 

写入以下内容(按你的IP改):


tunnel: <你的Tunnel ID>  # 自动生成的ID
credentials-file: /root/cloudflared/<你的Tunnel ID>.json

ingress:
  - hostname: ubuntu.yourdomain.com
    service: <http://192.168.123.100:5678>  # 访问Ubuntu的web服务,比如n8n等

  - hostname: nas.yourdomain.com
    service: <https://192.168.123.101:5001>
    originRequest:
      noTLSVerify: true  # 群晖自签证书需要跳过验证

  - hostname: openwrt.yourdomain.com
    service: <http://192.168.123.102:80>

  - service: http_status:404

注意替换 yourdomain.com 成你自己的域名,替换 IP 和端口!

保存退出(Ctrl+O 回车,然后 Ctrl+X)。

创建dns解析

让Cloudflare后台帮你自动建子域名:需要替换对应的域名

cloudflared tunnel route dns myhome ubuntu.yourdomain.com
cloudflared tunnel route dns myhome nas.yourdomain.com
cloudflared tunnel route dns myhome openwrt.yourdomain.com

开机自启动设置

执行:


sudo cloudflared --config /etc/cloudflared/config.yml service install

然后启动 Tunnel:


sudo systemctl enable cloudflared
sudo systemctl start cloudflared

查看状态确认:


sudo systemctl status cloudflared

✅ 看到绿色 running 就OK了!

如果安装在root 目录下 需要执行 下方命令

sudo cp /root/.cloudflared/config.yml /etc/cloudflared/config.yml
sudo systemctl restart cloudflared

重启 reboot 看是否生效。一般需要等待 cloudflaer 解析后 一段时间才能正常使用域名访问本地对应的应用。

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

Scroll to Top