下載說(shuō)明
去github官網(wǎng)下載最新版本,鏈接地址:https://github.com/fatedier/frp/releases/download/
windows對(duì)應(yīng):windows amd版本
linux對(duì)應(yīng):linux amd版本,
本文服務(wù)端使用linux版本采用docker構(gòu)建,無(wú)需下載??蛻?hù)端windows需要下載對(duì)應(yīng)文件。
配置 Windows遠(yuǎn)程訪問(wèn)
服務(wù)器端配置
需要一臺(tái)公網(wǎng)的服務(wù)器,本文服務(wù)器端是centos7
創(chuàng)建frp文件
mkdir -p /home/soft/frp && cd /home/soft/frp
添加服務(wù)端配置文件
創(chuàng)建配置文件
vim frps.ini
添加如下配置
[common]
bind_port = 7000
添加docker啟動(dòng)腳本
創(chuàng)建配置文件
vim docker-start.sh
添加如下配置
#!/bin/bash
docker run -d \
--restart always \
--network host \
--name frps \
-v /home/soft/frp/frps.ini:/etc/frp/frps.ini \
snowdreamtech/frps
啟動(dòng)服務(wù)端
sh docker-start.sh
客戶(hù)端配置
將下載好的文件解壓,修改frpc.ini 文件
[common]
server_addr = 服務(wù)器公網(wǎng)ip
server_port = 7000
# 遠(yuǎn)程控制
[mstsc]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 13389
啟動(dòng)客戶(hù)端
frpc.exe -c frpc.ini
遠(yuǎn)程控制訪問(wèn):公網(wǎng)ip:13389
配置管理頁(yè)
在服務(wù)器 frps.ini 配置如下:
[common]
bind_port = 7000
dashboard_addr = 0.0.0.0
dashboard_port = 7777
dashboard_user = terry
dashboard_pwd = terry123
打開(kāi)瀏覽器 公網(wǎng)ip:7777 即可訪問(wèn)
配置密鑰
frps.ini 配置如下
[common]
bind_port = 7000
auto_token = terry
客戶(hù)端frpc.ini 配置如下,auto_token必須和服務(wù)端的一致否則會(huì)連接不上
[common]
server_addr = 服務(wù)器公網(wǎng)ip
server_port = 7000
auto_token = terry
# 遠(yuǎn)程控制
[mstsc]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 13389
tcp其它常用應(yīng)用場(chǎng)景
tcp不但可以支持使用遠(yuǎn)程訪問(wèn),還支持http、ssh等。
服務(wù)端注意事項(xiàng)
需要開(kāi)放客戶(hù)端訪問(wèn)的端口,如客戶(hù)端如下配置
type = tcp
local_ip = 127.0.0.1
local_port = 8080
remote_port = 8086
local_port 是客戶(hù)端占用的ip
remote_port 則是訪問(wèn)服務(wù)端的ip
http服務(wù)
客戶(hù)端frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[http]
type = tcp
local_ip = 127.0.0.1
local_port = 8080
remote_port = 8086
訪問(wèn):公網(wǎng)ip:8086
ssh遠(yuǎn)程
客戶(hù)端frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 122
訪問(wèn):公網(wǎng)ip:122
mysql穿透
客戶(hù)端frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 13306
訪問(wèn):公網(wǎng)ip:13306
反向代理
frp支持類(lèi)似nginx反向代理,客戶(hù)端frpc.ini 配置,
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql]
type = tcp
local_ip = 192.168.0.3
local_port = 3306
remote_port = 13306
訪問(wèn):公網(wǎng)ip:13306,其代理到內(nèi)網(wǎng)中192.168.0.3服務(wù)器上
http應(yīng)用場(chǎng)景
frp http只能用一個(gè)http端口,一般應(yīng)用于域名映射,http穿透可以用tcp即可。
域名映射
服務(wù)端frps.ini 配置
[common]
bind_port = 7000
vhost_http_port = 81 # 訪問(wèn)服務(wù)器的81端口,映射到內(nèi)網(wǎng)web服務(wù)
服務(wù)端frpc.ini 配置
[common]
server_addr = 公網(wǎng)IP
server_port = 7000
[web01]
type = http
local_port = 8080
custom_domains = web01.terrybg.com
[web02]
type = http
local_port = 8081
custom_domains = web02.terrybg.com
stcp的應(yīng)用
tcp模式每開(kāi)多一個(gè)服務(wù)就會(huì)占用服務(wù)器端口,并且會(huì)將服務(wù)暴露在外面,會(huì)不安全。frp提供了stcp的模式,兩內(nèi)網(wǎng)連接可以通過(guò)密鑰方式連接,并且不會(huì)暴露在公網(wǎng)上,但連接者也需要開(kāi)啟frp客戶(hù)端。
服務(wù)端frps.ini 配置
[common]
bind_port = 7000
客戶(hù)端1 被訪問(wèn)者frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql]
type = stcp
# 密鑰
sk = abcdefg
local_ip = 127.0.0.1
local_port = 3306
客戶(hù)端2 訪問(wèn)者frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql_visitor]
type = stcp
# 密鑰
sk = abcdefg
# 訪問(wèn)者名稱(chēng)
role = visitor
# 被訪問(wèn)的 stcp 的名字
server_name = rdp
bind_addr = 127.0.0.1
bind_port = 3306
xtcp的應(yīng)用
服務(wù)端frps.ini 配置
[common]
bind_port = 7000
bind_udp_port = 7001
客戶(hù)端1 被訪問(wèn)者frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql]
type = xtcp
# 密鑰
sk = abcdefg
local_ip = 127.0.0.1
local_port = 3306
客戶(hù)端2 訪問(wèn)者frpc.ini 配置
[common]
server_addr = 公網(wǎng)ip
server_port = 7000
[mysql_visitor]
type = xtcp
# 密鑰
sk = abcdefg
# 訪問(wèn)者名稱(chēng)
role = visitor
# 被訪問(wèn)的 stcp 的名字
server_name = rdp
bind_addr = 127.0.0.1
bind_port = 3306
|