Files
nexus/wiki/concepts/TCP隧道.md
2026-04-27 16:26:34 +08:00

48 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "TCP隧道"
type: concept
tags: [networking, tunnel, tcp, ssh, frp]
last_updated: 2026-04-03
---
## Aliases
- TCP Tunnel
- TCP 隧道
## Definition
TCP 隧道TCP Tunnel是一种通过已建立的连接传输 TCP 数据包的技术,允许将本地 TCP 端口的流量通过隧道传输到远程位置。常见实现方式包括 SSH 隧道(`ssh -L` / `ssh -R`)和 frp 的 TCP 类型映射。TCP 隧道与 HTTP 代理不同,它传输的是原始 TCP 数据,不解析应用层协议。
## SSH 隧道
```bash
# 本地端口转发Local Port Forwarding将远程端口映射到本地
ssh -L local_port:remote_host:remote_port user@gateway
# 反向端口转发Reverse Port Forwarding将本地端口映射到远程
ssh -R remote_port:local_host:local_port user@gateway
```
### SSH 反向隧道限制
- 需要保持 SSH 连接持续活跃(可用 `autossh` 自动重连)
- 不适合多客户端并发访问
- 无 Web 管理界面
- 不支持 UDP
## frp TCP 隧道
详见 [[frp]]
## 在本 Wiki 中的应用
- [[通过VPS+内网反向代理实现域名访问内网穿透]]
- frp TCP 映射 NAS 端口5000→15000
- frp TCP 映射 Ubuntu 端口5678→15678, 9091→19091, 3000→13000
- frp TCP 映射 SSH22→60022
- SSH 穿透不走 Caddy纯 TCPCaddy 只处理 HTTP/HTTPS
## Related Concepts
- [[内网穿透]]TCP 隧道是内网穿透的底层实现机制
- [[反向代理]]HTTP/HTTPS 流量在 TCP 隧道之上还需要反向代理层Caddy
- [[frp]]frp 支持 TCP/UDP/HTTP/WebSocket 等多种隧道类型
## References
- SSH tunneling: `man ssh`(搜索 "SSH_PORT_FORWARDING" 或 "-L/-R"
- frp TCP 类型: https://github.com/fatedier/frp#configuration