條件
- 需要內網服務器能訪問公網
下載
- 在公網服務器和內網機器上都要下載frp安裝包並解壓:
$ wget https://github.com/fatedier/frp/releases/download/v0.21.0/frp_0.21.0_linux_amd64.tar.gz
$ tar -xzvf frp_0.21.0_linux_amd64.tar.gz
配置
- 公網服務器上修改服務端frps.ini
vim frps.ini
[common]
bind_port = 7000 #frp服務端端口(必須)
vhost_http_port = 8888 #web應用服務端口(部署web應用才必須)
- 內網目標主機修改客戶端frpc.ini
vim frpc.ini
[common]
server_addr = xxx.xxx.xxx.xxx #frp服務端地址(公網服務器地址),必須是公網ip或者域名,這裏假設爲xxx.xxx.xxx.xxx
server_port = 7000 #frp服務端端口,即填寫服務端配置中的 bind_port
[ssh]
type = tcp #連接類型,填tcp或udp
local_ip = 127.0.0.1 #填127.0.0.1或內網ip都可以
local_port = 22 #需要轉發到的端口,ssh端口是22
remote_port = 6000 #frp服務端的遠程監聽端口,即你訪問服務端的remote_port就相當於訪問客戶端的(即ssh登錄時的端口)
local_port,如果填0則會隨機分配一個端口
[web]
type = http #連接類型
local_ip = 127.0.0.1 #填127.0.0.1或內網ip都可以
local_port = 8080 #需要轉發到的端口,web項目的端口
custom_domains = test.com #訪問時域名加服務端設置的端口即可訪問內網web 域名需解析在公網服務器上
運行
- 在公網上運行服務端並且查看查看運行狀態
$ nohup ./frps -c frps.ini &
$ tail -f nohup.out # 顯示success即成功
- 在內網目標主機上運行客戶端並且查看查看運行狀態
$ nohup ./frpc -c frpc.ini &
$ tail -f nohup.out
停止
找到並殺死進程
$ ps -aux|grep frp| grep -v grep
root 19764 0.0 0.5 22524 10888 pts/0 Sl Jan07 0:09 ./frps -c frps.ini
$ kill -9 19764