[原创]使用frp实现远程局域网穿透
一、网络拓扑结构
最终实现的目标,是在终端可以访问无公网ip路由器下的主机,即frpc所在的主机。
具备公网ip路由器上,需要配置端口转发。如7000,9000,7001等端口,都需要映射转发到frps端主机。

二、部署与配置
I. frp部署以及参数,支持ssh和vnc:
1)frps server端配置:
bindAddr = "192.168.1.200"
bindPort = 7000
auth.method = "token"
auth.token="xx"
transport.heartbeatTimeout=600 //心跳超时时间
dashboard config
webServer.addr = "127.0.0.1"
webServer.port = 7001
webServer.user = "admin"
webServer.password = "admin"
log.to = "./frps.log"
2)frpc client端,config配置:
serverAddr = "125.38.26.59"
serverAddr = "www.xxx.cn"
serverPort = 7000
auth.method = "token"
auth token
auth.token = "xx" //验证使用
transport.heartbeatInterval=120 //心跳间隔
transport.heartbeatTimeout=600 //心跳超时时间
loginFailExit = true
[[proxies]]
name = "ssh-connect"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 9000
[[proxies]]
name = "vnc-connect"
type = "tcp"
localIP = "127.0.0.1"
localPort = 5901
remotePort = 9001
3) frpc client配置开机启动,退出自动重启。
因client端使用的是debian jessie版本,支持systemd,配置如下:
1.在/lib/systemd/system目录下,新建frpc.service,具体内容如下:
fa@FriendlyELEC:/lib/systemd/system$
cat frpc.service
[Unit]
Description=Frp client
After=network.target
[Service]
ExecStartPre=/bin/sleep 25
ExecStart=/home/fa/frp/frp_0.61.1_linux_arm_hf/frpc -c /home/fa/frp/frp_0.61.1_linux_arm_hf/frpc_home.toml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Alias=frpc.service
2.ln -s /lib/systemd/system/frpc.servcie /etc/systemd/frpc.service
3.sudo systemctl enable frpc.service
4.systemctl status frpc.service 用来查看服务的运行状态,调试时使用,如果退出,会给出退出的原因。
II. 在终端查看运行情况:
ssh -p port xxx@域名
可以登录成功,表明配置正确。

浙公网安备 33010602011771号