ghostunnel/ghostunnelGhostunnel是一个轻量级TLS代理工具,支持双向认证,用于保护非TLS后端应用。它提供客户端和服务器两种运行模式,可替代stunnel,实现安全的网络通信代理。
支持平台:Linux(x86-64推荐)、Darwin(macOS)、FreeBSD、OpenBSD、NetBSD及Windows(功能受限)。
bash# 查看帮助 ghostunnel --help ghostunnel server --help ghostunnel client --help
需准备以下证书文件(可通过certstrap或OpenSSL生成):
cacert.pem)监听TLS连接,解密后转发至后端服务。
| 参数 | 说明 |
|---|---|
--listen | 监听TLS连接的地址(格式:host:port或UNIX域套接字路径) |
--target | 后端服务地址(格式:host:port或UNIX域套接字路径) |
--keystore | 服务器证书密钥库(PKCS#12或PEM格式,自动检测) |
--cert/--key | 分离的证书链和私钥文件(PEM格式,替代--keystore) |
--cacert | 信任的CA证书文件(PEM格式) |
--allow-all | 允许所有有效证书的客户端连接 |
--allow-cn | 允许指定CN的客户端证书(可多次指定) |
--allow-ou | 允许指定OU的客户端证书(可多次指定) |
--allow-dns | 允许指定DNS SAN的客户端证书(可多次指定) |
--allow-uri | 允许指定URI SAN的客户端证书(可多次指定) |
--status | 状态监控端口(格式:host:port或UNIX域套接字路径) |
--timed-reload | 证书定时重载间隔(如300s) |
--quiet | 抑制指定类型日志(conns/conn-errs/handshake-errs/all) |
启动后端服务(如netcat):
bashnc -l localhost 8080
启动Ghostunnel服务器模式:
bashghostunnel server \ --listen localhost:8443 \ --target localhost:8080 \ --keystore server-keystore.p12 \ --cacert cacert.pem \ --allow-cn client \ --status localhost:8081 \ --timed-reload 300s
客户端连接测试:
bashopenssl s_client \ -connect localhost:8443 \ -cert client-combined.pem \ -key client-combined.pem \ -CAfile cacert.pem
监听不安全连接,加密后转发至TLS服务。
| 参数 | 说明 |
|---|---|
--listen | 监听本地连接的地址(格式:host:port或UNIX域套接字路径) |
--target | 远程TLS服务地址(格式:host:port) |
--keystore | 客户端证书密钥库(PKCS#12或PEM格式,自动检测) |
--cert/--key | 分离的证书链和私钥文件(PEM格式,替代--keystore) |
--cacert | 信任的CA证书文件(PEM格式) |
--server-cn | 验证服务器证书的CN(可选) |
--status | 状态监控端口(格式:host:port或UNIX域套接字路径) |
--timed-reload | 证书定时重载间隔(如300s) |
启动TLS后端服务:
bashopenssl s_server \ -accept 8443 \ -cert server-combined.pem \ -key server-combined.pem \ -CAfile cacert.pem
启动Ghostunnel客户端模式:
bashghostunnel client \ --listen localhost:8080 \ --target localhost:8443 \ --keystore client-keystore.p12 \ --cacert cacert.pem \ --status localhost:8081
测试连接:
bashnc -v localhost 8080
组合客户端和服务器模式,实现端到端加密隧道。
启动最终后端服务:
bashnc -l localhost 8001
启动服务器端Ghostunnel:
bashghostunnel server \ --listen localhost:8002 \ --target localhost:8001 \ --keystore server-combined.pem \ --cacert cacert.pem \ --allow-cn client
启动客户端Ghostunnel:
bashghostunnel client \ --listen localhost:8003 \ --target localhost:8002 \ --keystore client-keystore.p12 \ --cacert cacert.pem
测试端到端连接:
bashnc -v localhost 8003
ghostunnel/ghostunnelbashdocker run -d \ --name ghostunnel-server \ -p 8443:8443 \ -p 8081:8081 \ -v $(pwd)/test-keys:/etc/ghostunnel/keys \ ghostunnel/ghostunnel \ server \ --listen 0.0.0.0:8443 \ --target backend-service:8080 \ --keystore /etc/ghostunnel/keys/server-keystore.p12 \ --cacert /etc/ghostunnel/keys/cacert.pem \ --allow-cn client \ --status 0.0.0.0:8081 \ --timed-reload 300s
bashdocker run -d \ --name ghostunnel-client \ -p 8080:8080 \ -v $(pwd)/test-keys:/etc/ghostunnel/keys \ ghostunnel/ghostunnel \ client \ --listen 0.0.0.0:8080 \ --target tls-service.example.com:443 \ --keystore /etc/ghostunnel/keys/client-keystore.p12 \ --cacert /etc/ghostunnel/keys/cacert.pem \ --server-cn tls-service.example.com
yamlversion: '3' services: ghostunnel-server: image: ghostunnel/ghostunnel ports: - "8443:8443" - "8081:8081" volumes: - ./test-keys:/etc/ghostunnel/keys command: > server --listen 0.0.0.0:8443 --target backend:8080 --keystore /etc/ghostunnel/keys/server-keystore.p12 --cacert /etc/ghostunnel/keys/cacert.pem --allow-cn client --status 0.0.0.0:8081 --timed-reload 300s depends_on: - backend backend: image: alpine command: nc -l -p 8080 ghostunnel-client: image: ghostunnel/ghostunnel ports: - "8080:8080" volumes: - ./test-keys:/etc/ghostunnel/keys command: > client --listen 0.0.0.0:8080 --target ghostunnel-server:8443 --keystore /etc/ghostunnel/keys/client-keystore.p12 --cacert /etc/ghostunnel/keys/cacert.pem
SIGUSR1信号至进程触发证书重载
bashkill -USR1 <ghostunnel-pid>
--timed-reload <interval>设置自动重载间隔(如--timed-reload 5m)--status <host:port>启用指标端点,支持以下路径:
/metrics:Prometheus格式指标/health:健康检查端点/debug/pprof:性能分析接口(需--enable-pprof)支持多种证书验证规则(逻辑OR关系,满足其一即可):
--allow-all:允许所有有效证书--allow-cn <cn>:验证客户端证书CN--allow-ou <ou>:验证客户端证书OU--allow-dns <dns>:验证客户端证书DNS SAN--allow-uri <uri>:验证客户端证书URI SAN(支持SPIFFE SVID)通过--quiet参数抑制特定类型日志:
--quiet=conns:抑制连接建立/关闭日志--quiet=conn-errs:抑制连接错误日志(握手后)--quiet=handshake-errs:抑制握手错误日志(适用于K8s健康检查场景)--quiet=all:抑制所有日志通过PKCS#11接口使用硬件安全模块保护私钥,需指定PKCS#11模块路径和槽信息:
bashghostunnel server \ --listen :8443 \ --target :8080 \ --pkcs11-module /usr/lib/pkcs11.so \ --pkcs11-token-label "MyToken" \ --pkcs11-pin "1234" \ --cacert cacert.pem \ --allow-cn client
支持从SPIFFE Workload API获取动态证书和CA:
bashghostunnel server \ --listen :8443 \ --target :8080 \ --spiffe-svid-path /run/spire/sockets/agent.sock \ --spiffe-allow-uri spiffe://example.org/service \ --cacert /run/spire/bundle/bundle.pem
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像服务
在 Docker Desktop 配置镜像
Docker Compose 项目配置
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
MacOS OrbStack 容器配置
在宝塔面板一键配置镜像
Synology 群晖 NAS 配置
飞牛 fnOS 系统配置镜像
极空间 NAS 系统配置服务
爱快 iKuai 路由系统配置
绿联 NAS 系统配置镜像
QNAP 威联通 NAS 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
免费版仅支持 Docker Hub 访问,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等;免费版仅支持 docker.io。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
来自真实用户的反馈,见证轩辕镜像的优质服务