把 Shiny 搬到能用的地方:一次校园网里的失败尝试 Getting Shiny Somewhere Usable: A Failed Attempt on Campus Wi-Fi
结论先行:校园网是一个只能出、不能进的网络。想让它对外提供任何服务,都得绕开它。
一、它到底长什么样
我在宿舍的 Wi-Fi 上把网络参数挨个看了一遍:
| 项目 | 看到的值 | 含义 |
|---|---|---|
| 本机 IPv4 | 10.17.4.153/20 | 私有地址,不是公网 |
| 默认网关 | 10.17.0.1 | 同样是私有,NAT 在校园网侧 |
| 公网 IPv4 | 没有 | 出口是全校共用的地址池 |
| 公网 IPv6 | 没有,只有 fe80:: | 连最后一条直连的路也堵死了 |
| ICMP | 全部超时 | 出口直接丢弃 ping |
二、三个判断
- 没有公网 IPv4。 你拿到的是私有地址,外网的路由表里根本不存在你,开端口也没有用——NAT 不会替你转发。
- 没有公网 IPv6。 很多高校的教育网会给每个终端一个可全球路由的
/64,那本来是最省事的入口。这里没有。 - 规则上也不允许。 校园网一般明确禁止私设服务器和对外提供服务,出口有审计。这条比技术限制更硬。
三、试过的三条路
1. Cloudflare Tunnel
它能通。原理是从内网主动发一条长连接到 Cloudflare,不需要公网 IP,也不用在路由器上开端口:
# 在宿舍电脑上起一条临时隧道,把本地的 Shiny 暴露出去
cloudflared tunnel --url http://localhost:3838
但它有三个代价:电脑关机或断网,站点立刻消失;服务物理上仍然在境内,备案问题没有解决;而且校园网能看到这条长期连接。
2. shinyapps.io
免费额度每月 25 个活跃小时,对课题组内部演示完全够用。缺点也明显:冷启动要等十几秒,第一次打开的人会以为坏了。
3. 云服务器 + 备案
唯一能长期稳定对外的办法。但流程要走完:实名、备案、等审核,顺利的话二十天左右。适合已经确定要长期做下去的站点。
四、最后怎么选的
拆成三块,各放各的地方:
- 静态页面(主页、说明、图表截图)→ Cloudflare Pages,不需要备案。
- 真的要交互的部分(模型参数可调的 Shiny)→ shinyapps.io 免费版。
- 域名用子域指过去,
shiny与www分开。
整件事最后落成两条 DNS 记录:
| 类型 | 主机记录 | 记录值 |
|---|---|---|
| CNAME | www | 你的 Pages 项目地址 |
| CNAME | shiny | 你的 shinyapps.io 应用地址 |
五、留下的教训
先搞清楚脚下的网络能做什么,再决定要做什么。反过来的顺序,会浪费一整个周末。
另外一件小事:这次探测让我顺手确认了注册邮箱和账号的验证状态。域名安全里最容易被忽略的一环从来不是技术,是账号。
Short version: campus Wi-Fi only lets traffic out. It never lets anything in. Every service you want to expose has to go around it.
What the network actually looks like
| Item | Observed | Meaning |
|---|---|---|
| Local IPv4 | 10.17.4.153/20 | Private, not public |
| Default gateway | 10.17.0.1 | Also private; NAT happens upstream |
| Public IPv4 | None | A shared address pool for the whole campus |
| Public IPv6 | None, only fe80:: | The last direct route is closed too |
| ICMP | All timeouts | Ping is dropped at the egress |
Three conclusions
- No public IPv4. You get a private address that exists in no external routing table. Opening a port achieves nothing, because NAT will not forward it for you.
- No public IPv6. Many university networks hand every machine a globally routable
/64, which would have been the easiest way in. Not here. - The rules forbid it anyway. Campus networks generally prohibit running servers, and egress is audited. That constraint is firmer than the technical one.
Three things I tried
1. Cloudflare Tunnel
It works. The machine opens an outbound long-lived connection to Cloudflare, so no public IP and no port forwarding are needed:
# Temporary tunnel from the dorm machine to local Shiny
cloudflared tunnel --url http://localhost:3838
Three costs: the site dies when the laptop sleeps; the service is still physically inside the mainland, so the filing question is unresolved; and a permanent connection is visible on the campus network.
2. shinyapps.io
The free tier gives 25 active hours a month — plenty for showing something to your own group. The catch is cold starts: fifteen seconds of nothing, and the visitor assumes it is broken.
3. A cloud server plus ICP filing
The only way to stay reliably public. It also means identity verification, filing, and waiting for review — roughly twenty days if it goes smoothly.
What I settled on
Split into three pieces, each somewhere sensible:
- Static pages (home, notes, figures) → Cloudflare Pages. No filing needed.
- The genuinely interactive part (a Shiny app with tunable model parameters) → the free tier of shinyapps.io.
- Point subdomains at them, keeping
shinyandwwwseparate.
In the end it came down to two DNS records:
| Type | Host | Value |
|---|---|---|
| CNAME | www | your Pages project |
| CNAME | shiny | your shinyapps.io app |
The lesson
Work out what the network under your feet can do before deciding what to build. The other order costs you a weekend.
One small side effect: the same probe confirmed the state of my registration mailbox and account. The weakest link in domain security is never technical — it is the account.