http nat 穿透反向代理和 ssh nat 穿透代理例子
实现功能:
- 允许通过子域名(subDomainHost)访问内网 http 服务
- 通过 16000 端口代理内网 ssh 服务
frps.toml
1
2
3
4
5
6
7
8
9
10
11
| bindPort = 17000
vhostHTTPPort = 18080
vhostHTTPSPort = 10443
subDomainHost = "frp.mydomain.com" # 注意:需要创建一个 *.frp.mydomain.com 指向 frp server 所在机器的DNS记录
serverPort = 7000
# #鉴权使用的 token 值,需要和内网客户端端设置一样的值才能鉴权通过
[auth]
method = "token"
token = "mytoken1133"
|
frpc.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| serverAddr = "host-server.com"
serverPort = 17000
# 可选,是否使用 kcp 协议(底层使用UDP)
transport.protocol = "kcp"
[auth]
method = "token"
token = "mytoken1133"
# http 服务,域名映射
[[proxies]]
name = "web"
type = "http"
# 本地服务地址,localIP 设置可选(默认127.0.0.1)
localIP = "127.0.0.1"
localPort = 80
#customDomains = ["file.otherCustomDomain.site"]
subdomain = "file" # 相当于:file.mydomain.com:18080
# 登录验证,可选配置
httpUser = "the-user"
httpPassword = "the-password"
# ssh, tcp 端口映射
[[proxies]]
name = "wsl-ssh"
type = "tcp"
localPort = 22
RemotePort = 16000 # 相当于:ssh user@host-server.com -p 1600
|
stcp 类型 ,安全的 tcp 穿透代理
作用:
- 只有暴露端(proxies) 和 调用端(visitors) 声明了相同的 secret_key, 才能连接
- 验证连接
隐私安全
- 避免共用 frp 服务器时,出现大家都能访问分享的代理的 tcp 服务,例如 ssh 22 tcp 端口
- 可以通过 name 和 secret_key 验证授权访问的人
暴露端(proxies)frpc.toml
要点:
- type -> stcp
- secretKey: 验证密钥
1
2
3
4
5
6
7
8
9
10
| serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "secret_ssh"
type = "stcp"
# 只有与此处设置的 secretKey 一致的用户才能访问此服务
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
|
调用端(visitors) frpc.toml
要点:
- type -> stcp
- secretKey: 验证密钥,注意和服务暴露端设置一样
- serverName: 连接到的服务名称
1
2
3
4
5
6
7
8
9
10
11
12
| serverAddr = "x.x.x.x"
serverPort = 7000
[[visitors]]
name = "secret_ssh_visitor"
type = "stcp"
# 要访问的 stcp 代理的名字
serverName = "secret_ssh"
secretKey = "abcdefg"
# 绑定本地端口以访问 SSH 服务
bindAddr = "127.0.0.1"
bindPort = 6000
|
xtcp 类型, p2p 快速 tcp 穿透代理
特点:
- 不需要经过 frp 服务器中转流量
- 直接 p2p 点对点传输数据
- 类似
stcp 代理类型,只是把 type 改成 xtcp 就可以
缺点:
文章作者
上次更新
2024-01-05
(b2a2a64)