ip更改后如何重新连接cloudflare隧道

Posted

技术标签:

【中文标题】ip更改后如何重新连接cloudflare隧道【英文标题】:How to reconnect cloudflare tunnel after ip change 【发布时间】:2021-12-29 13:04:04 【问题描述】:

我在 Docker 映像中使用 cloudflare 隧道。 docker compose 配置

tunnel:
    image: cloudflare/cloudflared:2021.11.0
    command: tunnel --config /etc/cloudflared/config.yml --no-autoupdate run

和 cloudflared 配置

url: http://host.docker.internal:8000
tunnel: ***
credentials-file: /etc/cloudflared/***.json

当我切换主机wifi网络时,主机ip发生变化,隧道断开。

cloudflared tunnel info <NAME>
...
This tunnel has no active connectors.

是否有参数可以周期性地重新连接cloudflared客户端?

【问题讨论】:

【参考方案1】:

似乎您的 docker 容器无法识别任何更新或 ip4 更改,因为您在虚拟 docker 交换机上运行它。

如果您使用这些设置在您的机器上尝试 nativ,这应该可以工作:

# run command
$ cloudflared tunnel --no-chunked-encoding run <<your_tunnel_name>>
# config.yml in your default cloudflared folder (~/.cloudflared/):

tunnel: 0000001
credentials-file: .cloudflared/0000001.json
originRequest: # Root-level configuration
  connectTimeout: 10s
loglevel: debug
transport-loglevel: debug

ingress:
  - hostname: example.com
    service: http://localhost:4300
    originRequest:
      connectTimeout: 10s
      tcpKeepAlive: 12s
  - service: http_status:404

这里是重新创建新连接后日志的 sn-p:

2021-11-18T16:39:27Z DBG rpcconnect: tx (abort = (reason = "rpc: shutdown", type = failed, obsoleteIsCallersFault = false, obsoleteDurability = 0))
2021-11-18T16:39:27Z ERR Unable to establish connection. error="already connected to this server, trying another address" connIndex=2
2021-11-18T16:39:27Z ERR Connection terminated error="already connected to this server, trying another address" connIndex=2
2021-11-18T16:39:27Z DBG rpcconnect: rx (return = (answerId = 1, releaseParamCaps = false, results = (content = <opaque pointer>, capTable = [])))
2021-11-18T16:39:27Z INF Connection 90277bf3-1708-490b-803e-fbdabbbb1f75 registered connIndex=3 location=FRA
2021-11-18T16:39:27Z DBG rpcconnect: tx (finish = (questionId = 1, releaseResultCaps = false))

【讨论】:

似乎 docker 容器中的重新连接过程需要很长时间(最多 30 分钟),但它可以工作

以上是关于ip更改后如何重新连接cloudflare隧道的主要内容,如果未能解决你的问题,请参考以下文章

Python:远程服务器关闭后自动重新连接 ssh 隧道

反向ssh隧道

网络重启后Openswan隧道不工作

Discourse 的用户信息中的 IP 地址显示的是 CloudFlare 的 IP 地址

使用 CloudFlare、Heroku 和 RoR 时如何设置真实 IP 地址?

如何在CloudFlare下Nginx实现访客真实IP网站日志?