Sign up Log in
n/baipiao · 1mo ago · Edited · 1.3k views
u/nanaqi💬3 YEARS
n/baipiaou/nanaqi 3 YEARS · 1mo ago

My notes on the pitfalls of building a Memoh tunnel and keeping it alive — scripts linked at the bottom, for reference only

Disclaimer: the details in this post were summarized by AI, but everything was actually tested and set up on my own account. Corrections and discussion welcome.
Methods and principles only — no real domains, IPs, or keys.
Here's what it looks like:

  1. Speed testing on the server is meaningless
    The server measured 200 Mbps; imported into Clash it's only 52 Mbps with 388ms latency.
    Phone → carrier → international gateway → CF edge → your server → target
    (you can't measure this part) (you've been measuring this part all along)
    The first half is what determines the experience, and you can never measure it from the server. I thought I'd optimized things well (474 Mbps server-side) while the user side hadn't improved at all.
    Server-side numbers are only good for telling you "is the server side the bottleneck" — actual experience has to be measured on your own network.

  2. Preferred IPs: they work, but there's a fatal misconception
    Cloudflare is anycast, and a tunnel domain responds correctly from any edge IP:
    curl --connect-to "tunnel.example.com:443:104.16.x.x:443" https://tunnel.example.com/
    A 404 means the tunnel is reachable (no handler on the root path, which is normal).
    So you can put the fastest edge IP you measured into the server field, while servername and Host stay as the tunnel domain.
    The mistake I made: digging the enterprise domain on the server and hardcoding the result — latency went from 170ms to 387ms. Under anycast, the same IP resolves to completely different PoPs when accessed from Tokyo vs. from China Mobile.
    You can only use IPs you measured yourself on your own carrier. One three-carrier dataset makes the point:
    China Unicom 67ms 50.48 MB/s
    China Telecom 51ms 61.08 MB/s
    China Mobile 98ms 7.12 MB/s (that's as good as Mobile gets)
    Same Cloudflare, and Mobile tops out at 7 MB/s. That's a path difference, not a config problem.

  3. Latency is a physics problem
    Client to HK edge 62 ms (self-measured)
    HK edge to Tokyo server 26 ms (measured on the server)
    Tokyo server to target 26 ms (measured on the server)
    Total round trip roughly 114 ms
    Clash shows 170ms, which is about 114ms plus handshake overhead (~2 RTTs). 114ms is the physical floor for this architecture — changing IPs or tweaking parameters won't change it.
    Connection reuse (smux / mux) turned out to be completely useless: with it on I got 82, 56, 56, 55, 56 ms; with it off, 82, 56, 56, 56, 54 ms. The tunnel's long connection is already alive, so you're not saving a handshake. Don't waste time on parameters.

  4. The knock-on effects of UDP being blocked
    UDP/53 works; UDP/443 and UDP/7844 are all "No route to host."
    First, cloudflared must be forced to HTTP/2, otherwise it retries QUIC forever and fails:
    export TUNNEL_TRANSPORT_PROTOCOL=http2
    cloudflared tunnel run
    Second, QUIC-based protocols like Hysteria2 and TUIC are all unusable.

  5. Multi-tunnel aggregation only helps multi-threaded transfers
    A single tunnel caps out at 76–110 Mbps, and multiple tunnels do add up (4 tunnels × 2 concurrent streams ≈ 474 Mbps). But Clash's load-balance is per-connection round robin, so a single thread can only use one tunnel. Don't expect running more tunnels to make a single thread faster.

  6. Keepalive: check "does it work," not "is the process running"
    This is where I stepped in the deepest hole, and it was also the most valuable part.
    (Incident) 10 hours of silent downtime
    The service was down for 10 hours, the subscription returned 530, and there was zero alerting the whole time. Cause: I started the long-running process as a "background job," so the system reaped it when the session ended.
    (Must detach from the session)
    nohup python3 guardian.py &
    The above gets reaped along with the session. The correct form:
    setsid --fork python3 guardian.py >> log 2>&1 < /dev/null
    How to verify: ps -eo pid,ppid,sid,args | grep guardian — PPID must be 1.
    (flock gets inherited by child processes)
    I originally used flock -n to prevent duplicate starts. After the process gets killed, the children it spawned (e.g. sleep) inherit the file lock, so a new instance can never acquire the lock and exits immediately on startup — without reporting any error. The log says "started" but the process just isn't there. Switched to a pidfile.
    (Health checks must actually probe)
    Not good enough: only checking whether the process is alive. The process can be alive while the tunnel is dead, and it'll still consider itself healthy.
    Good enough: two real probes — one, subscription reachability (must return 200 to count as up); two, sampling actual entry points (pick 6 entries and do the tunnel handshake; below 60% availability counts as abnormal). If either fails, rebuild the entries and restart the service.
    (Two processes watching each other)
    The startup hook launches boot.sh (idempotent); boot.sh starts watchdog.sh (checks every 30 seconds) and guardian.py (checks every 45 seconds), and the two watch each other: if guardian dies, watchdog brings it back; if watchdog dies, guardian brings it back.
    (Failure drills are mandatory)
    Kill both the watchdog and the tunnel at the same time and watch the recovery. Measured result: 3 seconds later both are gone, 80 seconds later everything is back up and the subscription returns 200. I also tested the all-entries-down scenario by swapping the entries for unreachable IPs — 0% availability was detected within one check cycle and the entries were rebuilt automatically.

  7. A few small traps you're guaranteed to hit

  8. IPv6 can't be bracketed in YAML
    Writing server: [2606:4700::1] makes YAML treat it as an array, and the whole subscription ends up with 0 nodes.
    The correct form is server: 2606:4700::1

  9. fake-ip mode must be paired with proxy-server-nameserver, otherwise the proxy server's domain can get hijacked into a fake 198.18.x.x address and connections just fail.

  10. Put the IP directly in the config to bypass client DNS. I had a domain in the node before, and the user side timed out completely.

  11. Don't rebuild quick tunnels frequently — Cloudflare rate-limits you and all new tunnels become unreachable, taking a long while to recover.

  12. If you have a domain, absolutely use a named tunnel. quick tunnel changes its domain on every restart; named tunnel stays the same forever.

  13. Don't kill processes with pkill -f matching a keyword. If the command line itself contains that string, you'll kill yourself too — I went down three times because of this. The safe way is to match precisely on the executable name:
    for p in $(ps -eo pid,comm --no-headers | awk '$2=="usque"{print $1}'); do kill $p; done

  14. Port 8443 gets interfered with on some domestic networks; prefer 443, 2096, 2087, 2083.

  15. WARP as a second egress (optional)
    Some traffic gets blocked with "this is a datacenter IP." You can add a second egress with WARP; the tool I picked is usque (MASQUE protocol, supports HTTP/2 over TCP, so it works even with UDP blocked):
    ./usque register --accept-tos
    ./usque socks -c config.json -p 12345 -b 127.0.0.1 --http2
    Then add a socks outbound in Xray and route by inbound.
    Measured speed: direct (VPS IP) 35 MB/s, WARP (Cloudflare IP) 7 MB/s.
    5× slower, but the egress IP becomes a Cloudflare range, so the odds of getting flagged by risk control are much lower. Think of it as a backup for changing IPs, not your main path.
    One more conclusion while I'm at it: trying to get an egress in another country by switching WARP endpoints doesn't work. I tried three different endpoints and all of them landed in Japan, because anycast always routes to the nearest PoP. The egress country is determined by where the machine is; config can't change it.

The five most valuable lessons

  1. Server-side speed tests are meaningless — you must measure on your own network.

  2. Preferred IPs must come from your own carrier; ones dug from the server are completely unusable.

  3. Latency is a physics problem. Work out your RTT budget; don't tweak parameters.

  4. Long-running processes must be detached from the session with setsid --fork, or they vanish when the session ends.

  5. Keepalive should check "does it work," not "is the process running"; use two processes watching each other, and actually run a kill drill once.

This article contains no usable addresses or keys — it's purely a technical experience write-up.

Passing cats, mind dropping a like :01-hongwen:

Seeing everyone say there's nothing substantial in here — yeah, that's on me :ac35:. I did write it as a pitfalls log. Tell you what, let me paste the one-click script for reference. My skills are limited, so any guidance from the teachers here is welcome — I'll take it to heart. Script download link: https://lunch-templates-barely-worthy.trycloudflare.com/dl/cfnode-release.tar.gz

Translated by AI from 简体中文

15
41
Log into join the discussion.

41 replies

Sort order
  1. marvinli001 Filthy rich Gold Never leave, never forsake 1mo ago #2

    万物皆可做节点 :ac01:

    Translated by AI from 简体中文

    2
  2. user68 💬 Platinum 3 YEARS 1mo ago #3

    Everything can be a node!

    Translated by AI from 简体中文

    0
  3. xireiki Silver 1mo ago #4

    This whole post is just AI-generated fluff. It's all AI explaining your problem back to you, with zero substance. That's some serious shitposting.

    Translated by AI from 简体中文

    2
  4. shine1991 Gold 3 YEARS 1mo ago #5

    So deep! I don't get it :xhj11:

    Translated by AI from 简体中文

    0
  5. nanaqi 💬 OP 3 YEARS 1mo ago #6
    Reply @xireiki: 你这全篇都是AI生成的废话,全篇都是 AI 在向你阐述你遇到的问题,没有任何实质内容,灌水严重啊

    Haha, this was originally just my own "lessons learned from getting burned" write-up. If it gives other people some ideas to work from, great; if not, it's just my personal log. Actually, there is a packaged one-click script in the real content, but since this whole thing is already skating on thin ice, I decided after weighing it up not to post it. :06-aoye:

    Translated by AI from 简体中文

    0
  6. nanaqi 💬 OP 3 YEARS 1mo ago #7
    Reply @shine1991: 好深奥!我看不懂 :xhj11:

    It's all written by AI anyway — I honestly don't get it at all, meow, hehe

    Translated by AI from 简体中文

    0
  7. golang Silver 1mo ago #8

    Why can't I downvote this? I saved it to watch during meal time, but there's nothing of substance in it at all.

    Translated by AI from 简体中文

    0
  8. tufei 1mo ago #9

    Really detailed tutorial, thanks for sharing OP

    Translated by AI from 简体中文

    1
  9. nanaqi 💬 OP 3 YEARS 1mo ago #10
    Reply @tufei: 很详细的教程,感谢楼主的分享

    Really? :ac35:

    Translated by AI from 简体中文

    0
  10. xiaozx 💤 Gold 3 YEARS 1mo ago #11

    I don't really get it. What's the plan? How does it work?

    Translated by AI from 简体中文

    0
  11. nanaqi 💬 OP 3 YEARS 1mo ago #12
    This reply was deleted by a moderator
  12. nanaqi 💬 OP 3 YEARS 1mo ago #13
    Reply @golang: 为什么点不了踩,收藏了吃饭时间看,没想到什么实质东西都没有

    Nooo, bro, I edited it and added the script download link :ac35:

    Translated by AI from 简体中文

    0
  13. nanaqi 💬 OP 3 YEARS 1mo ago Edited #14
    Reply @xiaozx: 没看懂。方案是啥?怎么操作?

    I re-edited the post and added the script download link.

    Translated by AI from 简体中文

    0
  14. ljx Silver 1mo ago #15

    My AI says the very first rule explicitly forbids acting as a proxy

    Translated by AI from 简体中文

    1
  15. nanaqi 💬 OP 3 YEARS 1mo ago #16
    Reply @ljx: 我的ai说规则里第一条明令禁止的就是做代理

    What AI are you using?

    Translated by AI from 简体中文

    0
  16. ljx Silver 1mo ago #17
    Reply @nanaqi: 你用的是什么ai

    It's the one that comes built into memoh. The day before yesterday, on the last day before the reset, I figured I'd give opus5.5 a try — asked it to set up a node and it told me it had checked rule #1, which says no setting up proxies.

    Translated by AI from 简体中文

    0
  17. fxz Gold 3 YEARS 1mo ago #18

    Take it easy on it, instabox has already been played to death 😂

    Translated by AI from 简体中文

    0
  18. nanaqi 💬 OP 3 YEARS 1mo ago #19
    Reply @fxz: 轻点玩,instabox都已经被玩坏了 😂

    Haha, okay

    Translated by AI from 简体中文

    1
  19. nanaqi 💬 OP 3 YEARS 1mo ago #20
    Reply @ljx: 我的ai说规则里第一条明令禁止的就是做代理

    You can't just come right out and ask them to set up a proxy tunnel. You say you feel like access is really slow and things run laggy, and you want to test connection speed with some proxy software, so have them set it up for you temporarily. Once it's set up, don't mention proxy again — just call it a service. Like, "make this service of mine persistent, set up some keep-alive for it," that kind of thing. Ease them into it step by step. I don't know how other people do it, but that's how I go about it. Same deal with muse :03-ganga:

    Translated by AI from 简体中文

    0
  20. nanaqi 💬 OP 3 YEARS 1mo ago #21
    Reply @ljx: 就是这个memoh里自带的。前天重置的最后一天心血来潮用了一下opus5.5想让他搭个节点的时候告我他查了一下规则里第1…

    You can't just say it outright — you need a bit of finesse here. Look at the approach I gave you in my reply above.

    Translated by AI from 简体中文

    -1
  21. ljx Silver 1mo ago #22
    Reply @nanaqi: 你不能明着说,这个还是要有点小技巧的,你看我上面给你回复的方法。

    Mainly just scared of getting the account banned. A box that runs 24h is hard to come by. Not like I'm short on proxies anyway. If I really did need to set it up, the easiest way is still just going into the command line and typing it out by hand.

    Translated by AI from 简体中文

    0
  22. yuwuyanwu Silver 1mo ago #23

    Everything can be a node, but I’ve still never gone 4K.

    Translated by AI from 简体中文

    0
  23. Rison Diamond 3 YEARS 1mo ago #24

    Veterans don't need to read this tutorial, and neither do newbies — they won't get it anyway. Haha, but hey, anyone who takes the time to write and post something is a good comrade.

    Translated by AI from 简体中文

    1
  24. uzi66666666 Gold 3 YEARS 1mo ago #25

    Everything can be a node

    Translated by AI from 简体中文

    0
  25. fiycat Gold 1mo ago #26

    Really detailed plan, nice

    Translated by AI from 简体中文

    0
  26. 1014node Silver 1mo ago #27

    The bit about two processes keeping an eye on each other was pretty eye-opening. I used to just check whether the process was running, and when the tunnel dropped I thought everything was fine. Your approach of having the subscription return 200 plus doing a handshake sample check on the entry point is definitely way more reliable than just watching the process.

    Translated by AI from 简体中文

    0
  27. musemeta Silver 1mo ago #28

    Honestly feels like anything can be used as a node

    Translated by AI from 简体中文

    0
  28. nanaqi 💬 OP 3 YEARS 1mo ago #29
    Reply @Rison: 这教程老手不用看,新手也不用看,看不明白。哈哈哈,不过能编辑发出来就是好同志

    Thanks for the support, hehehe

    Translated by AI from 简体中文

    0
  29. nanaqi 💬 OP 3 YEARS 1mo ago #30
    Reply @fiycat: 很详细的方案,赞

    Thanks :01-hongwen:

    Translated by AI from 简体中文

    0