frp 教程
出这个文章的前提是bruce最近买了一个阿里云主机,但是呢云主机的配置比较拉。刚好家里有一台闲置的主机,就想着搞一搞内网穿透。
工具用的是 frp
tcp 模式
这种方式安全性比较差,端口容易被扫,log里看到好多陌生ip。
- Modify
frps.tomlon server A by setting thebindPortfor frp clients to connect to:
1 | # frps.toml |
Start
frpson server A:./frps -c ./frps.tomlModify
frpc.tomlon server B and set theserverAddrfield to the public IP address of your frps server:
1 | # frpc.toml |
Note that the localPort (listened on the client) and remotePort (exposed on the server) are used for traffic going in and out of the frp system, while the serverPort is used for communication between frps and frpc.
Start
frpcon server B:./frpc -c ./frpc.tomlTo access server B from another machine through server A via SSH (assuming the username is
test), use the following command:ssh -oPort=6000 test@x.x.x.x
stcp 模式
比上面的要安全些
To mitigate risks associated with exposing certain services directly to the public network, STCP (Secret TCP) mode requires a preshared key to be used for access to the service from other clients.
Configure frps same as above.
- Start
frpcon machine B with the following config. This example is for exposing the SSH service (port 22), and note thesecretKeyfield for the preshared key, and that theremotePortfield is removed here:
1 | # frpc.toml |
- Start another
frpc(typically on another machine C) with the following config to access the SSH service with a security key (secretKeyfield):
1 | # frpc.toml |
On machine C, connect to SSH on machine B, using this command:
ssh -oPort=6000 127.0.0.1
http 模式
可以把内网的http服务通过云服务器暴露出来
Sometimes we need to expose a local web service behind a NAT network to others for testing purposes with our own domain name.
Unfortunately, we cannot resolve a domain name to a local IP. However, we can use frp to expose an HTTP(S) service.
- Modify
frps.tomland set the HTTP port for vhost to 8080:
1 | # frps.toml |
If you want to configure an https proxy, you need to set up the vhostHTTPSPort.
Start
frps:./frps -c ./frps.tomlModify
frpc.tomland setserverAddrto the IP address of the remote frps server. Specify thelocalPortof your web service:
1 | # frpc.toml |
Start
frpc:./frpc -c ./frpc.tomlMap the A record of
www.example.comto either the public IP of the remote frps server or a CNAME record pointing to your original domain.Visit your local web service using url
http://www.example.com:8080.