【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (2025)

本帖最后由 ryoma1836 于 2022-12-28 10:57 编辑 4. 项目实施4.1. 初始化 UDR

插上电源,将电脑直连 UDR 的 LAN 口,在浏览器输入 unifi 即可进入初始化界面

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (1)

单击 Setup UDR

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (2)

Console Name 输入 UDR Hostname

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (3)

Select a setup type 选择 Personal

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (4)

登录 Unifi 账号

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (5)

更新频率根据自己需要设置

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (6)

设置 WiFi SSID 的名字、密码,后面要详细设置,这里可以随便设置进行测试即可

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (7)

Send Diagnostics & Performance Information 不启用

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (8)

系统会自动进行一次 ISP 测速

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (9)

确认各项信息,设置加上截图,总共耗时 4:31,确实是“让 IT 更简单”的速度,不过文章可不是到这就结束了

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (10)

这里就是 Unifi OS 的界面了

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (11)

Unifi OS 可以选择除了 Network 以外安装哪个 App,我这边安装了 Protect,上面有提示 The UDR can run up to two applications simultaneously,即 UDR 仅能同时使用 2 个 App,如果你有更多的 App 需求,请选择 UDM-Pro 或者 UDM-SE。

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (12)

这个界面可以发现相比我下面使用 Docker 安装的 Unifi Network,缺少了 Legacy Interface 的选项,意味着现在的 Unifi OS 设备(最新版本)已经完全无法切换到旧版界面了。虽然新版本界面更简单更方便,但是很大的一个问题是 Ubiquiti 官网的一些文档仍然使用旧版界面撰写,同时很多网友的教程帖子也是基于旧版进行设置,无形之中对新入手的朋友造成很大困难,而且新版界面不像旧版界面可以切换为中文显示,即便提供了中文选项,也无法显示中文。

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (13)【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (14)4.2. 设置 Internet

由于之前初始化的时候,是在我家的 MikroTik 主路由下做二级路由上网,现在更换到朋友家接上光猫,需要重新将 Internet 设置为 PPPoE 拨号模式

  • DNS Server 勾选 Auto
  • UPnP 根据需求进行设置,有需要使用 BT/PT 下载的用户可以关注下这里,这边可以在下面设置完 Networks 后再回来调整
  • Dynamic DNS 即 DDNS,由于 Unifi 自带可用的 DDNS 对国内用户极其不友好,所以后面我会单独用一个章节介绍使用 Dnspod 搭配自购域名做 DDNS 的办法
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (15)
  • IPv4 Connection 选择 PPPoE(如果你家光猫不是桥接模式,而是路由模式,请跳过此步骤)
  • Username、Password 输入 PPPoE User、Password
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (16)4.3. 设置 Networks

Global Networks Settings

  • Multicast DNS 全部网络启用
  • IGMP Snooping 全部网络不启用

Global Switch Settings

  • 全部保持默认
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (17)4.3.1. Default Network
  • Gateway IP/Subnet 这边若想要该网段使用全部 IP 地址,勾选 Auto-Scale Network,若想手动设置 DHCP 地址池范围,取消勾选
  • Host Address 输入 Gateway
  • Netmask 选择 Subnet Prefix,大部分家庭使用选择 24 即可,相当于 255.255.255.0

Advanced 选择 Manual

  • DHCP Mode 选择 DHCP Server
  • DHCP Range 输入起始 IP 和结束 IP
  • DHCP Guarding 不勾选 Enable
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (18)4.3.2. IoT Network

设置 Proxy 和 IoT 网络时,只有一个地方设置与 Default 网络有区别,即多设置一个 VLAN ID,VLAN ID 我一般对应 IP 地址中间某一段或者某两段,比如我这边 IoT 网络时 172.16.203.0/24,所以我取第 3 段作为 VLAN ID,其他设置与 Default 网络一样

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (19)4.3.3. Guest Network

设置 Guest Network 时,除了需要设置 VLAN ID,还需要为 Network Type 选择 Guest Network

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (20)4.4. 设置 WiFi4.4.1. Default WiFi
  • Name 输入 SSID Name
  • Password 输入 WiFi Password
  • Network 选择上个章节设置的 Default 网络
  • Broadcasting APs 选择全部 AP

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (21)

Security

  • Security Protocol 选择 WPA2

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (22)

WiFi Scheduler

若需要对某个 WiFi 设置启用停用时间,可以启用 WiFi Scheduler,我这边不需要此功能,仅做截图说明

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (23)4.4.2. IoT WiFi
  • Name 输入 SSID Name
  • Password 输入 WiFi Password
  • Network 选择上个章节设置的 IoT 网络
  • Broadcasting APs 选择全部 AP

Advanced

WiFi Band 只勾选 2.4GHz,由于智能家居设备的网卡基本上只支持 2.4GHz,所以并不需要开启 5GHz

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (24)4.4.3. Guest WiFi

到 Profiles 下设置 Bandwidth Profiles

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (25)
  • Name 输入 Guest
  • Limit download bandwidth 我设置 30Mbps
  • Limit upload bandwidth 我设置 5Mbps

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (26)

回到 WiFi 设置

  • Name 输入 SSID Name
  • Network 选择上个章节设置的 Guest 网络
  • Broadcasting APs 选择全部 AP

Advanced
  • WiFi Band 只勾选 5GHz,由于访客来家中需要联网的主要是手机和笔记本电脑,基本上现在的移动设备都支持 5GHz,所以并不需要开启 2.4GHz
  • WiFi Type 选择 Guest Hotspot
  • Bandwidth Profile 选择 Guest
  • Client Device Isolation 会被自动启用,不用手动设置

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (27)

Security

Security Protocol 选择 Open

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (28)

到 Profiles 下设置 Guest Hotspot

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (29)
  • Authentication Type 我选择最简单的 Password,还可以使用微信登录,但是据我了解这个功能是需要有公众号才能使用,对于家庭使用来说,太过繁琐,我就不在朋友家折腾了
  • Password 设置一个稍微简单的与其他 WiFi 不同的密码

Guest Landing Page 选择 ON

  • Background Image 选择 Use Unsplash gallery
  • Library Image 从下来菜单中选择一个喜欢的图片即可

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (30)
  • Title 输入 Title Name,我这边保持默认
  • Terms of Service 勾选 Enable,内容如下,自带英文版本,我同时翻译了一份中文版本在下方

Terms of Use (English)

By accessing the wireless network, you acknowledge that you're of legal age, you have read and understood and agree to be bound this agreement.
You agree not to use the wireless network for any purpose that is unlawful and take full responsibility of your acts.
The wireless network is provided "as is" without warranties of any kind, either expressed or implied.

使用条款(简体中文)

通过访问本无线网络,您需承认您已达到法定年龄,您已阅读理并同意接受本协议的约束。
您同意不将无线网络用于任何非法目的,并对您的行为承担全部责任。
无线网络按“其现状”提供,不会提供任何明示或暗示的保证。


【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (31)
  • Default Expiration 保持默认 8 Hours
  • Language(s) 选择 English、Chinese
  • Landing Page 选择 Redirect to the original URL
  • Redirection 勾选 HTTPS Redirection 和 Encrypted redirect URL

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (32)4.5. 设置 Firewall

由于本次项目设置了 4 个网络,所以 Firewall 的设置就尤为关键,否则划分 VLAN 就失去了最重要的作用。

不过 Ubiquiti 家的 Firewall 设置确实跟一般传统的网络厂家设备不怎么一样,所以有些问题或者说算 Bug 需要一些特殊的方式处理,下面会提到。

本人的防火墙设置借鉴了一位用户 KIMOCHI 的设置方法:UniFi Firewall Rules 防火牆規則

需要我们人为设置的的 Firewall 设置都集中在 LAN 区域,其他区域的策略会根据你的其他网络设置而自动添加。4.5.1. 设置思路

我们在 Firewall 设置上面,主要是要对 IoT 和 Guest 网络进行限制,不允许属于这两个网络的客户端对内网其他网络进行访问,但是同时需要我们的其他网络能访问 IoT 和 Guest 网络客户端。当然,我这边后面还设置了 VXN 远程访问网络,所以我增加了一条 VXN 的策略,此处不展开细说,因为配置方式与 Default、Proxy 一样。

  • Default 网络可以访问 Proxy、IoT 和 Guest
  • Proxy 网络可以访问 Default、IoT 和 Guest
  • IoT 网络无法访问 Default、Proxy 和 Guest
  • Guest 网络无法访问 Default、Proxy 和 IoT

这样子设置就会变得非常复杂,所以在禁止不同网络互访这件事情上面,我们直接做一条 Block Inter-VLANs Routing 策略即可,中文意思即禁止 VLAN 间路由,然后在这条策略的上方设置放行策略即可。

但是这样设置之后,我们还是会发现另一个问题,就是 IoT 和 Guest 网络的客户端居然可以访问其他网络的 Gateway,即 Default、Proxy 网络的网关可以被这两个网络访问,国外网友也有提到这个问题,所以这边用曲线救国的方式对这个问题进行封堵。同时,对于 HTTP、HTTPS 和 SSH 到路由器本身的操作,也是不被 IoT 和 Guest 客户端所允许的,所以要单独做策略进行封堵。

4.5.2. 设置 Profile

这边我们需要先设置一些 Profile。

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (33)

RFC1918

这边关于 RFC1918 的介绍请看:专用网络

  • Profile Name 输入 RFC1918
  • Type 选择 IPv4 Address/Subnet
  • Address 输入 192.168.0.0/16、172.16.0.0/12 和 10.0.0.0/8

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (34)

其他 Profile 我就不一一截图了,以免让朋友们看混淆了,下面我只提供对应的设置内容

Block IoT to Firewall interface

  • Profile Name 输入 Block IoT to Firewall interface
  • Type 选择 IPv4 Address/Subnet
  • Address 输入 IoT Gateway IP

Block Guest to Firewall interface

  • Profile Name 输入 Block Guest to Firewall interface
  • Type 选择 IPv4 Address/Subnet
  • Address 输入 Guest Gateway IP

Block IoT to Gateways

  • Profile Name 输入 Block IoT to Gateways
  • Type 选择 IPv4 Address/Subnet
  • Address 输入 Default、Proxy 和 Guest Gateway IP

Block Guest to Gateways

  • Profile Name 输入 Block Guest to Gateways
  • Type 选择 IPv4 Address/Subnet
  • Address 输入 Default、Proxy 和 IoT Gateway IP

HTTP, HTTPs, SSH

  • Profile Name 输入 HTTP, HTTPs, SSH
  • Type 选择 Port Group
  • Port 输入 80、443、22
4.5.3. 设置 Firewall 策略

Block Inter-VLANs Routing(阻止 VLAN 间路由)

  • Type 选择 LAN In
  • Description 输入 Block Inter-VLANs Routing
  • Action 选择 Drop

Source

Source Type 选择 Port/IP Group
IPv4 Address Group 选择 RFC1918

Destination

Source Type 选择 Port/IP Group
IPv4 Address Group 选择 RFC1918

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (35)

Allow established/related sessions(放行 established/related 会话)

  • Type 选择 LAN In
  • Description 输入 Allow established/related sessions
  • Action 选择 Accept

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (36)

Advanced

  • States 勾选 Match State Established 和 Match State Related

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (37)

Allow Default to all Local(放行 Default 网络到所有本地网络)

  • Type 选择 LAN In
  • Description 输入 Allow Default to all Local
  • Action 选择 Accept

Source
  • Source Type 选择 Network
  • Network 选择 Default

Destination

  • Source Type 选择 Port/IP Group
  • IPv4 Address Group 选择 RFC1918

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (38)

同理设置其他允许访问 RFC1918 地址的网络(比如本文中的 Proxy 和 WxxxGxxxd 网络),此处不再赘述

下面设置上面提到的最后的关于 IoT 和 Guest 网络的问题进行设置

Block IoT to Firewall interface(阻止 IoT 网络到 IoT Gateway 的 HTTP, HTTPs, SSH 端口)

  • Type 选择 LAN Local
  • Description 输入 Block IoT to Firewall interface
  • Action 选择 Drop

Source

  • Source Type 选择 Network
  • Network 选择 IoT

Destination

  • Source Type 选择 Port/IP Group
  • IPv4 Address Group 选择 Block IoT to Firewall Interface
  • Port Gourp 选择 HTTP, HTTPs, SSH

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (39)

同理设置 Block Guest to Firewall interface

Block Guest to Firewall interface(阻止 Guest 网络到 Guest Gateway 的 HTTP, HTTPs, SSH 端口)

  • Type 选择 LAN Local
  • Description 输入 Block Guest to Firewall interface
  • Action 选择 Drop

Source

  • Source Type 选择 Network
  • Network 选择 Guest

Destination

  • Source Type 选择 Port/IP Group
  • IPv4 Address Group 选择 Block Guest to Firewall Interface
  • Port Gourp 选择 HTTP, HTTPs, SSH

Block IoT to Gateways(阻止 IoT 网络到 Default, Proxy, Guest 网络的 Gateway)

  • Type 选择 LAN Local
  • Description 输入 Block IoT to Gateways
  • Action 选择 Drop

Source

  • Source Type 选择 Network
  • Network 选择 IoT

Destination

  • Source Type 选择 Port/IP Group
  • IPv4 Address Group 选择 Block IoT to Gateways

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (40)

同理设置 Block Guest to Gateways

Block Guest to Gateways(阻止 Guest网络到 Default, Proxy, IoT 网络的 Gateway)

  • Type 选择 LAN Local
  • Description 输入 Block Guest to Gateways
  • Action 选择 Drop

Source

  • Source Type 选择 Network
  • Network 选择 Guest


Destination
  • Source Type 选择 Port/IP Group
  • IPv4 Address Group 选择 Block Guest to Gateways

最终防火墙策略排序如下图,记得设置好 Firewall 策略顺序,上方的 LAN In 策略排序一定不能错,最上面是 Allow established/related sessions,最下面是 Block Inter-VLANs Routing,中间是允许放行的 Allow Default to all Local 等等,LAN Local 的策略就无所谓先后顺序了,都是封堵策略。

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (41)4.6. 设置 DDNS & Port Forwarding (无公网 IP 用户请跳过)4.6.1. DDNS

上面在设置 Internet 的时候,提到了 Ubiquiti 家的 DDNS 针对中国用户并不那么友好,这边就不深究原因了。我们还是使用曲线救国的方式来实现 DDNS 功能,由于 Unifi 的系统本质上是一个修改版的 Debian9,所以有些功能是可以使用 Linux 的处理方式来解决的。这边需要开启 UDR 的 SSH 功能,需要回到 Unifi OS 管理界面的 Console Settings。

Advanced

  • 勾选 SSH,单击 Change Password 设置 SSH Password,用户名是 root

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (42)

然后我们需要准备一个域名,比如 xyz 结尾的域名,不管新购还是续费都很便宜。把域名的 Name Servers 设置为 Dnspod 提供的 evangeline.dnspod.net, contain.dnspod.net,并在 Dnspod 上创建并保存 DNSPod Token 信息。

具体设置方法参考这篇文章的步骤 1-5:群晖NAS借助DDNS配置自有顶级域名实现公网访问

接下来,我们使用下面这个 Github 项目, SSH 工具访问 UDR(此处需要特别感谢我一位朋友海滨,还是他之前先在网上找到了这个项目并用在了他自己的 UDM-SE 上,使用成功才推荐我使用的)
Github 项目:kkkgo/dnspod-ddns-with-bashshell: The Dnspod DDNS with BashShell(详细用法请查看 Github README.md)

创建 /ddns 目录
  1. mkdir /ddns

复制代码

创建 dnspod_ddns.sh 脚本,复制项目全部内容 dnspod-ddns-with-bashshell/dnspod_ddns.sh,修改 API_ID、API_Token、domain、host 四行为 DNSPod 提供的相关信息,其他保持不变

  1. vim /ddns/dnspod_ddns.sh

复制代码


  1. #Dnspod DDNS with BashShell
  2. #Github:https://github.com/kkkgo/dnspod-ddns-with-bashshell
  3. #More: https://03k.org/dnspod-ddns-with-bashshell.html
  4. #CONF START
  5. API_ID=12345
  6. API_Token=abcdefghijklmnopq2333333
  7. domain=example.com
  8. host=home
  9. CHECKURL="http://ip.03k.org"
  10. #OUT="pppoe"
  11. #CONF END
  12. . /etc/profile
  13. date
  14. if (echo $CHECKURL |grep -q "://");then
  15. IPREX='([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
  16. URLIP=$(curl -4 -k $(if [ -n "$OUT" ]; then echo "--interface $OUT"; fi) -s $CHECKURL|grep -Eo "$IPREX"|tail -n1)
  17. if (echo $URLIP |grep -qEvo "$IPREX");then
  18. URLIP="Get $DOMAIN URLIP Failed."
  19. fi
  20. echo "[URL IP]:$URLIP"
  21. dnscmd="nslookup";type nslookup >/dev/null 2>&1||dnscmd="ping -c1"
  22. DNSTEST=$($dnscmd $host.$domain)
  23. if [ "$?" != 0 ]&&[ "$dnscmd" == "nslookup" ]||(echo $DNSTEST |grep -qEvo "$IPREX");then
  24. DNSIP="Get $host.$domain DNS Failed."
  25. else DNSIP=$(echo $DNSTEST|grep -Eo "$IPREX"|tail -n1)
  26. fi
  27. echo "[DNS IP]:$DNSIP"
  28. if [ "$DNSIP" == "$URLIP" ];then
  29. echo "IP SAME IN DNS,SKIP UPDATE."
  30. exit
  31. fi
  32. fi
  33. token="login_token=${API_ID},${API_Token}&format=json&lang=en&error_on_empty=yes&domain=${domain}&sub_domain=${host}"
  34. Record="$(curl -4 -k $(if [ -n "$OUT" ]; then echo "--interface $OUT"; fi) -s -X POST https://dnsapi.cn/Record.List -d "${token}")"
  35. iferr="$(echo ${Record#*code}|cut -d'"' -f3)"
  36. if [ "$iferr" == "1" ];then
  37. record_ip=$(echo ${Record#*value}|cut -d'"' -f3)
  38. echo "[API IP]:$record_ip"
  39. if [ "$record_ip" == "$URLIP" ];then
  40. echo "IP SAME IN API,SKIP UPDATE."
  41. exit
  42. fi
  43. record_id=$(echo ${Record#*"records"\:\[\{"id"}|cut -d'"' -f2)
  44. record_line_id=$(echo ${Record#*line_id}|cut -d'"' -f3)
  45. echo Start DDNS update...
  46. ddns="$(curl -4 -k $(if [ -n "$OUT" ]; then echo "--interface $OUT"; fi) -s -X POST https://dnsapi.cn/Record.Ddns -d "${token}&record_id=${record_id}&record_line_id=${record_line_id}")"
  47. ddns_result="$(echo ${ddns#*message"}|cut -d'"' -f2)"
  48. echo -n "DDNS upadte result:$ddns_result "
  49. echo $ddns|grep -Eo "$IPREX"|tail -n1
  50. else echo -n Get $host.$domain error :
  51. echo $(echo ${Record#*message"})|cut -d'"' -f2
  52. fi

复制代码

修改 dnspod_ddns.sh 的可执行权限

  1. chmod +x /ddns/dnspod_ddns.sh

复制代码

修改计划任务,最下方加入以下内容

  1. # ddns
  2. */10 * * * * bash /ddns/dnspod_ddns.sh >> /ddns/log
  3. */10 * * * * echo "----------------------------------------" >> /ddns/log
  4. 0 */12 * * * bash /ddns/dnspod_ddns.sh > /ddns/log

复制代码

重启计划任务服务

  1. systemctl restart cron

复制代码

确认计划任务服务是否运行正常

  1. systemctl status cron

复制代码

确认计划任务生效

  1. crontab -l

复制代码

10 分钟后查看 log 文件,查看当前的公网 IP

  1. tail /ddns/log

复制代码

这样我们的 DDNS 就设置完成了,然后就可以设置 Port Forwarding 了。这边我只举一个例子,因为设置方法都是一样的,而且这个功能我相信大部分用户在其他路由器上面都设置过,同时,Ubiquiti 家路由器不需要像 MikroTik 家路由器那样需要设置 Hairpin NAT(即网友们所说的回流),所以问题不大。

4.6.2. Port Forwarding(端口转发)

单击 Create New Forwarding Rules 创建 Rule

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (43)

这边我以 Proxmox VE 虚拟化的 HTTPS 转发为例说明

  • Name 输入 Proxmox VE HTTPS
  • Forward Rule 勾选 Enable
  • Port 输入任意高位端口,这边我以 30113 为例
  • Forward IP 输入 Proxmox VE Mgmt IP
  • Forward Port 输入 8006
  • Protocol 选择 TCP
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (44)

从公网访问效果如下

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (45)4.7. 设置 WxxxGxxxd

12 月初,Unifi OS 终于在 VXN 功能上面实现了进步,这个事情在英文官方论坛已经被外国用户吐槽爆了,特别是长期以来,Ubiquiti 都只支持 LxxP,然而 Android12 起,已经不允许添加 LxxP 了,除非你在 Android11 的时候添加了 LxxP,并且 OTA 到 Android12 才能使用。所以可以预见这个怨念有多深。

我之前有搜索过,有人使用命令行的方式在 Unifi 路由器内安装 OpenVXN,但是我始终觉得这个东西有一定的稳定性风险,甚至可能重启后或者更新后失效。我本以为 Ubiquiti 会出这个功能,没想到直接跳过,而使用了 WxxxGxxxd。

下面简单介绍下使用方式,不多进行文字说明了。

关于 WireGuard 的配置视频:Unifi WxxxGxxxd VXN setup

其实 WxxxGxxxd 无服务端和客户端之分,不过 Ubiquiti 可能为了通俗易懂,所以还是在命名上做了这样的区分。

单击 Create VXN Server 创建服务端

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (46)

Network Name 输入 WxxxGxxxd Name
Server Address Port 输入 51820
Advanced 可以选择 Auto 或者单独设置一个网络

最后在 Clients Authentication 单击 Add a New Client

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (47)
  • Name 输入 Client Name

单击 Download Profile,然后单击 Create User

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (48)

客户端我以 Windows 系统为例,其他客户端同理设置即可。

单击从文件导入隧道,选择上一步下载的 Profile 文件,文件扩展名为 conf

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (49)

导入后建议编辑隧道,将 Endpoint 从当前 UDR 的公网 IP 更改为 DDNS 域名,避免公网 IP 变化后导致隧道失效

【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) - Chiphell (50)
【让 IT 更简单】使用 Ubiquiti 全家桶对朋友家进行网络改造 - 原创分享(新) -  Chiphell (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Delena Feil

Last Updated:

Views: 6180

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.