狗頭發卡網

FRP內網穿着透配置教程及配置分享 前言...

FRP內網穿着透配置教程及配置分享

前言

隨著全球IPv4地址耗盡,网穿新裝電信寬帶一般也隻給分配內網IP,着透置分不開放外網IP了,配置但是教程及配隨時智能設備的越來越普及,像電腦  、网穿NAS 、着透置分华为王云鹤宣布离职樹莓派 、配置攝像頭等網絡設備需要遠程控製時較為麻煩 ,教程及配幸好有大佬開發了這款FRP軟件,网穿簡易易用開源 。着透置分
因為你需要在外網訪問這些應用,配置你就需要一款內網穿著透工具來讓外網與你家內網建立起接合,教程及配實現無公網 IP 的网穿遠程訪問了 。「Frp」是着透置分一款流行的跨平台開源免費內網穿著透工具,擁穿著 Windows 、配置macOS 與 Linux。你隻需一台快速穩定的 VPS 服務器即可愉悅地鋪開內網穿著透 ,實現家中設備公網直接訪問了。

Frp基本信息

frp全名Fast Reverse Proxy,是用於提供內網穿著透服務的工具,主要用於解決一些內網服務沒有公網ip但是卻需要提供外網訪問的尷尬。使用frp你可以將內網中的TCP 、UDP、HTTP 、HTTPS等協議類型的服務發布到公網,並且擁穿著Web服務根據域名鋪開路由轉發。

Frp使用要求

如上圖的frp架構圖所示 :

  1. (必須)想要使用frp服務 ,將內網中的服務發布到公網  。
    你需要先擁有一台擁有公網ip的網絡設置搭建frp服務端 ,再在內網需要穿著透的設置中搭建frp客戶端服務才能鋪開穿著透;
  2. (非必需)你需要擁有一個域名解析到公網的ip地址 ,才能夠實現web服務的通過域名鋪開路由轉發的功能 。

Frp服務的搭建

搭建frp很簡易 ,關鍵的步驟隻有三步 :

  • 第一步 :得到frp文件;
  • 第二步 :設置frp配置文件;
  • 第三步 :打開frp服務。

注意 :frp搭建的的這三步是分為客戶端和服務端的,但是操作基本是一致的 。本教程frp服務的搭建主要介紹frp搭建的主要三步  ,以及frp服務端和客戶端配置文件內容的解釋會談明 ,以及如何將frp在linux係統中創建systemd服務,鋪開服務管理。

第一步:得到frp文件

FRP 使用 Go 語言開發,可以擁穿著 Windows、Linux 、macOS 、ARM 等多平台部署 。FRP 安裝非常輕易,隻需下載對應係統平台的軟件包並解壓就可用了。
frp擁穿著linux平台和windows平台 。參照你的設置的運行平台下載linux版本的文件或者是windows的 。
下載地址:https://github.com/fatedier/frp/releases
一般linux平台下載的版本為 :frp_版本號_linux_amd64.tar.gz
windows平台下載的版本為 :frp_版本號_windows_amd64.zip

FRP軟件下載
frp_0.33.0_linux_amd64.tar.gz
frp_0.33.0_windows_amd64.zip

截止本文發布時間最新版為v0.33.0,請盡量使用最新版本 。网易狼人游戏透视辅助

一 、Linux係統 :

<span class="hljs-built_in">export</span> FRP_VERSION=0.33.0
mkdir -p /etc/frp
<span class="hljs-built_in">cd</span> /etc/frp
wget <span class="hljs-string">"https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz"</span>
tar xzvf frp_<span class="hljs-variable">${FRP_VERSION}</span>_linux_amd64.tar.gz
mv frp_<span class="hljs-variable">${FRP_VERSION}</span>_linux_amd64/* /etc/frp
export FRP_VERSION=0.33.0mkdir -p /etc/frpcd /etc/frpwget "https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz"tar xzvf frp_${FRP_VERSION}_linux_amd64.tar.gzmv frp_${FRP_VERSION}_linux_amd64/* /etc/frp
export FRP_VERSION=0.33.0mkdir -p /etc/frpcd /etc/frpwget "https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz"tar xzvf frp_${FRP_VERSION}_linux_amd64.tar.gzmv frp_${FRP_VERSION}_linux_amd64/* /etc/frp
  • 其中,第一行等號後麵的0.33.0是 frp 的版本號 (截稿為止最新版本) 。你安裝的時候可以到官網查校驗下有沒更新的版本 ,隻需將新版本的號碼替換掉0.33.0即可。
  • FRP 默認提供了2個服務端配置文件 ,一個是簡化版的frps.ini,另一個是完整版的frps_full.ini。初科學家隻需用簡版配置即可 ,在簡版frps.ini配置文件裏 ,默認設置了監細聽端口為7000,你可以按需修改它 。

二、windows係統

文件直接右鍵解壓即可。

文件解壓後  ,一般都含有frps(frp服務端運行文件) 、frpc(frp客戶端運行文件) 、frps.ini(frp服務端配置文件)、frpc.ini(frp客戶端配置文件),以及frp_full.ini(frp全部配置文件解釋會談明和參考。)

防火牆和安全組開放指定的端口:

請一定要記借宿,你需要將服務器的係統防火牆,以及阿裏雲、騰訊雲後台裏找到“安全組計劃”的相關配置,設置7000或你修改過的對應端口的「允許入站和出站」,否則會一直接合不上的哦 ! ! !這個切記!!

第二步 :frp配置文件設置

frp配置文件分為服務端和客戶端 ,想要正常隻用frp工具 ,我們需要對服務端和客戶端的配置文件分別鋪開設置 。
官方中文文檔 :https://github.com/fatedier/frp/blob/master/README_zh.md

frps.ini(服務端)配置文件解釋會談明 :

<span class="hljs-comment"># [common] is integral section
<span class="hljs-section">[common]</span>
<span class="hljs-comment"># A literal address or host name for IPv6 must be enclosed
<span class="hljs-comment"># in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-comment"># udp port to help make udp hole to penetrate nat
<span class="hljs-attr">bind_udp_port</span> = <span class="hljs-number">7001</span>
<span class="hljs-comment"># udp port used for kcp protocol, it can be same with bind_port
<span class="hljs-comment"># if not set, kcp is disabled in frps
<span class="hljs-attr">kcp_bind_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-comment"># specify which address proxy will listen for, default value is same with bind_addr
<span class="hljs-comment"># proxy_bind_addr = 127.0.0.1
<span class="hljs-comment"># if you want to support virtual host, you must set the http port for listening (optional)
<span class="hljs-comment"># Note: http port and https port can be same with bind_port
<span class="hljs-attr">vhost_http_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">vhost_https_port</span> = <span class="hljs-number">443</span>
<span class="hljs-comment"># response header timeout(seconds) for vhost http server, default is 60s
<span class="hljs-comment"># vhost_http_timeout = 60
<span class="hljs-comment"># set dashboard_addr and dashboard_port to view dashboard of frps
<span class="hljs-comment"># dashboard_addrs default value is same with bind_addr
<span class="hljs-comment"># dashboard is available only if dashboard_port is set
<span class="hljs-attr">dashboard_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span>
<span class="hljs-attr">dashboard_port</span> = <span class="hljs-number">7500</span>
<span class="hljs-comment"># dashboard user and passwd for basic auth protect, if not set, both default value is admin
<span class="hljs-attr">dashboard_user</span> = admin
<span class="hljs-attr">dashboard_pwd</span> = admin
<span class="hljs-comment"># dashboard assets directory(only for debug mode)
<span class="hljs-comment"># assets_dir = ./static
<span class="hljs-comment"># console or real logFile path like ./frps.log
<span class="hljs-attr">log_file</span> = ./frps.log
<span class="hljs-comment"># trace, debug, info, warn, error
<span class="hljs-attr">log_level</span> = info
<span class="hljs-attr">log_max_days</span> = <span class="hljs-number">3</span>
<span class="hljs-comment"># auth token
<span class="hljs-attr">token</span> = <span class="hljs-number">12345678</span>
<span class="hljs-comment"># heartbeat configure, its not recommended to modify the default value
<span class="hljs-comment"># the default value of heartbeat_timeout is 90
<span class="hljs-comment"># heartbeat_timeout = 90
<span class="hljs-comment"># only allow frpc to bind ports you list, if you set nothing, there wont be any limit
<span class="hljs-attr">allow_ports</span> = <span class="hljs-number">2000</span>-<span class="hljs-number">3000</span>,<span class="hljs-number">3001</span>,<span class="hljs-number">3003</span>,<span class="hljs-number">4000</span>-<span class="hljs-number">50000</span>
<span class="hljs-comment"># pool_count in each proxy will change to max_pool_count if they exceed the maximum value
<span class="hljs-attr">max_pool_count</span> = <span class="hljs-number">5</span>
<span class="hljs-comment"># max ports can be used for each client, default value is 0 means no limit
<span class="hljs-attr">max_ports_per_client</span> = <span class="hljs-number">0</span>
<span class="hljs-comment"># authentication_timeout means the timeout interval (seconds) when the frpc connects frps
<span class="hljs-comment"># if authentication_timeout is zero, the time is not verified, default is 900s
<span class="hljs-attr">authentication_timeout</span> = <span class="hljs-number">900</span>
<span class="hljs-comment"># if subdomain_host is not empty, you can set subdomain when type is http or https in frpcs configure file
<span class="hljs-comment"># when subdomain is test, the host used by routing is test.frps.com
<span class="hljs-attr">subdomain_host</span> = frps.com
<span class="hljs-comment"># if tcp stream multiplexing is used, default is true
<span class="hljs-attr">tcp_mux</span> = <span class="hljs-literal">true</span> //TCP多路複用 ,默認啟用
# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"bind_addr = 0.0.0.0bind_port = 7000# udp port to help make udp hole to penetrate natbind_udp_port = 7001# udp port used for kcp protocol, it can be same with bind_port# if not set, kcp is disabled in frpskcp_bind_port = 7000# specify which address proxy will listen for, default value is same with bind_addr# proxy_bind_addr = 127.0.0.1# if you want to support virtual host, you must set the http port for listening (optional)# Note: http port and https port can be same with bind_portvhost_http_port = 80vhost_https_port = 443# response header timeout(seconds) for vhost http server, default is 60s# vhost_http_timeout = 60# set dashboard_addr and dashboard_port to view dashboard of frps# dashboard_addrs default value is same with bind_addr# dashboard is available only if dashboard_port is setdashboard_addr = 0.0.0.0dashboard_port = 7500# dashboard user and passwd for basic auth protect, if not set, both default value is admindashboard_user = admindashboard_pwd = admin# dashboard assets directory(only for debug mode)# assets_dir = ./static# console or real logFile path like ./frps.loglog_file = ./frps.log# trace, debug, info, warn, errorlog_level = infolog_max_days = 3# auth tokentoken = 12345678# heartbeat configure, its not recommended to modify the default value# the default value of heartbeat_timeout is 90# heartbeat_timeout = 90# only allow frpc to bind ports you list, if you set nothing, there wont be any limitallow_ports = 2000-3000,3001,3003,4000-50000# pool_count in each proxy will change to max_pool_count if they exceed the maximum valuemax_pool_count = 5# max ports can be used for each client, default value is 0 means no limitmax_ports_per_client = 0# authentication_timeout means the timeout interval (seconds) when the frpc connects frps# if authentication_timeout is zero, the time is not verified, default is 900sauthentication_timeout = 900# if subdomain_host is not empty, you can set subdomain when type is http or https in frpcs configure file# when subdomain is test, the host used by routing is test.frps.comsubdomain_host = frps.com# if tcp stream multiplexing is used, default is truetcp_mux = true       //TCP多路複用
	,默認啟用
# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"bind_addr = 0.0.0.0bind_port = 7000# udp port to help make udp hole to penetrate natbind_udp_port = 7001# udp port used for kcp protocol, it can be same with bind_port# if not set, kcp is disabled in frpskcp_bind_port = 7000# specify which address proxy will listen for, default value is same with bind_addr# proxy_bind_addr = 127.0.0.1# if you want to support virtual host, you must set the http port for listening (optional)# Note: http port and https port can be same with bind_portvhost_http_port = 80vhost_https_port = 443# response header timeout(seconds) for vhost http server, default is 60s# vhost_http_timeout = 60# set dashboard_addr and dashboard_port to view dashboard of frps# dashboard_addrs default value is same with bind_addr# dashboard is available only if dashboard_port is setdashboard_addr = 0.0.0.0dashboard_port = 7500# dashboard user and passwd for basic auth protect, if not set, both default value is admindashboard_user = admindashboard_pwd = admin# dashboard assets directory(only for debug mode)# assets_dir = ./static# console or real logFile path like ./frps.loglog_file = ./frps.log# trace, debug, info, warn, errorlog_level = infolog_max_days = 3# auth tokentoken = 12345678# heartbeat configure, its not recommended to modify the default value# the default value of heartbeat_timeout is 90# heartbeat_timeout = 90# only allow frpc to bind ports you list, if you set nothing, there wont be any limitallow_ports = 2000-3000,3001,3003,4000-50000# pool_count in each proxy will change to max_pool_count if they exceed the maximum valuemax_pool_count = 5# max ports can be used for each client, default value is 0 means no limitmax_ports_per_client = 0# authentication_timeout means the timeout interval (seconds) when the frpc connects frps# if authentication_timeout is zero, the time is not verified, default is 900sauthentication_timeout = 900# if subdomain_host is not empty, you can set subdomain when type is http or https in frpcs configure file# when subdomain is test, the host used by routing is test.frps.comsubdomain_host = frps.com# if tcp stream multiplexing is used, default is truetcp_mux = true //TCP多路複用,默認啟用

frpc.ini(客戶端)配置文件解釋會談明 :

<span class="hljs-comment"># [common] is integral section
<span class="hljs-section">[common]</span>
<span class="hljs-comment"># A literal address or host name for IPv6 must be enclosed
<span class="hljs-comment"># in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
<span class="hljs-attr">server_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span>
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-comment"># if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables
<span class="hljs-comment"># it only works when protocol is tcp
<span class="hljs-comment"># http_proxy = http://user:passwd@192.168.1.128:8080
<span class="hljs-comment"># http_proxy = socks5://user:passwd@192.168.1.128:1080
<span class="hljs-comment"># console or real logFile path like ./frpc.log
<span class="hljs-attr">log_file</span> = ./frpc.log
<span class="hljs-comment"># trace, debug, info, warn, error
<span class="hljs-attr">log_level</span> = info
<span class="hljs-attr">log_max_days</span> = <span class="hljs-number">3</span>
<span class="hljs-comment"># for authentication
<span class="hljs-attr">token</span> = <span class="hljs-number">12345678</span>
<span class="hljs-comment"># set admin address for control frpcs action by http api such as reload
<span class="hljs-attr">admin_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">admin_port</span> = <span class="hljs-number">7400</span>
<span class="hljs-attr">admin_user</span> = admin
<span class="hljs-attr">admin_pwd</span> = admin
<span class="hljs-comment"># connections will be established in advance, default value is zero
<span class="hljs-attr">pool_count</span> = <span class="hljs-number">5</span>
<span class="hljs-comment"># if tcp stream multiplexing is used, default is true, it must be same with frps
<span class="hljs-attr">tcp_mux</span> = <span class="hljs-literal">true</span>
<span class="hljs-comment"># your proxy name will be changed to {user}.{proxy}
<span class="hljs-attr">user</span> = your_name
<span class="hljs-comment"># decide if exit program when first login failed, otherwise continuous relogin to frps
<span class="hljs-comment"># default is true
<span class="hljs-attr">login_fail_exit</span> = <span class="hljs-literal">true</span>
<span class="hljs-comment"># communication protocol used to connect to server
<span class="hljs-comment"># now it supports tcp and kcp and websocket, default is tcp
<span class="hljs-attr">protocol</span> = tcp
<span class="hljs-comment"># specify a dns server, so frpc will use this instead of default one
<span class="hljs-comment"># dns_server = 8.8.8.8
<span class="hljs-comment"># proxy names you want to start divided by ,
<span class="hljs-comment"># default is empty, means all proxies
<span class="hljs-comment"># start = ssh,dns
<span class="hljs-comment"># heartbeat configure, its not recommended to modify the default value
<span class="hljs-comment"># the default value of heartbeat_interval is 10 and heartbeat_timeout is 90
<span class="hljs-comment"># heartbeat_interval = 30
<span class="hljs-comment"># heartbeat_timeout = 90
<span class="hljs-comment"># ssh is the unique proxy name
<span class="hljs-comment"># if user in [common] section is not empty, it will be changed to {user}.{proxy} such as your_name.ssh
<span class="hljs-section">[ssh]</span>
<span class="hljs-comment"># tcp | udp | http | https | stcp | xtcp, default is tcp
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-comment"># true or false, if true, messages between frps and frpc will be encrypted, default is false
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-comment"># if true, message will be compressed
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-comment"># remote port listen by frps
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6001</span>
<span class="hljs-comment"># frps will load balancing connections for proxies in same group
<span class="hljs-attr">group</span> = test_group
<span class="hljs-comment"># group should have same group key
<span class="hljs-attr">group_key</span> = <span class="hljs-number">123456</span>
<span class="hljs-comment"># enable health check for the backend service, it support tcp and http now
<span class="hljs-comment"># frpc will connect local services port to detect its healthy status
<span class="hljs-attr">health_check_type</span> = tcp
<span class="hljs-attr">health_check_interval_s</span> = <span class="hljs-number">10</span>
<span class="hljs-attr">health_check_max_failed</span> = <span class="hljs-number">1</span>
<span class="hljs-attr">health_check_timeout_s</span> = <span class="hljs-number">3</span>
<span class="hljs-section">
[ssh_random]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-comment"># if remote_port is 0, frps will assign a random port for you
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">0</span>
<span class="hljs-comment"># if you want to expose multiple ports, add range: prefix to the section name
<span class="hljs-comment"># frpc will generate multiple proxies such as tcp_port_6010, tcp_port_6011 and so on.
<span class="hljs-section">[range:tcp_port]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">6010</span>-<span class="hljs-number">6020</span>,<span class="hljs-number">6022</span>,<span class="hljs-number">6024</span>-<span class="hljs-number">6028</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6010</span>-<span class="hljs-number">6020</span>,<span class="hljs-number">6022</span>,<span class="hljs-number">6024</span>-<span class="hljs-number">6028</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-section">
[dns]</span>
<span class="hljs-attr">type</span> = udp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">114.114</span>.<span class="hljs-number">114.114</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">53</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6002</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-section">
[range:udp_port]</span>
<span class="hljs-attr">type</span> = udp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">6010</span>-<span class="hljs-number">6020</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6010</span>-<span class="hljs-number">6020</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-comment"># Resolve your domain names to [server_addr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02
<span class="hljs-section">[web01]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">true</span>
<span class="hljs-comment"># http username and password are safety certification for http protocol
<span class="hljs-comment"># if not set, you can access this custom_domains without certification
<span class="hljs-attr">http_user</span> = admin
<span class="hljs-attr">http_pwd</span> = admin
<span class="hljs-comment"># if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.com
<span class="hljs-attr">subdomain</span> = web01
<span class="hljs-attr">custom_domains</span> = web02.yourdomain.com
<span class="hljs-comment"># locations is only available for http type
<span class="hljs-attr">locations</span> = /,/pic
<span class="hljs-attr">host_header_rewrite</span> = example.com
<span class="hljs-comment"># params with prefix "header_" will be used to update http request headers
<span class="hljs-attr">header_X-From-Where</span> = frp
<span class="hljs-attr">health_check_type</span> = http
<span class="hljs-comment"># frpc will send a GET http request /status to local http service
<span class="hljs-comment"># http service is alive when it return 2xx http response code
<span class="hljs-attr">health_check_url</span> = /status
<span class="hljs-attr">health_check_interval_s</span> = <span class="hljs-number">10</span>
<span class="hljs-section">
[web02]</span>
<span class="hljs-attr">type</span> = https
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">8000</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">subdomain</span> = web01
<span class="hljs-attr">custom_domains</span> = web02.yourdomain.com
<span class="hljs-section">
[plugin_unix_domain_socket]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6003</span>
<span class="hljs-comment"># if plugin is defined, local_ip and local_port is useless
<span class="hljs-comment"># plugin will handle connections got from frps
<span class="hljs-attr">plugin</span> = unix_domain_socket
<span class="hljs-comment"># params with prefix "plugin_" that plugin needed
<span class="hljs-attr">plugin_unix_path</span> = /var/run/docker.sock
<span class="hljs-section">
[plugin_http_proxy]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6004</span>
<span class="hljs-attr">plugin</span> = http_proxy
<span class="hljs-attr">plugin_http_user</span> = abc
<span class="hljs-attr">plugin_http_passwd</span> = abc
<span class="hljs-section">
[plugin_socks5]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6005</span>
<span class="hljs-attr">plugin</span> = socks5
<span class="hljs-attr">plugin_user</span> = abc
<span class="hljs-attr">plugin_passwd</span> = abc
<span class="hljs-section">
[plugin_static_file]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6006</span>
<span class="hljs-attr">plugin</span> = static_file
<span class="hljs-attr">plugin_local_path</span> = /var/www/blog
<span class="hljs-attr">plugin_strip_prefix</span> = static
<span class="hljs-attr">plugin_http_user</span> = abc
<span class="hljs-attr">plugin_http_passwd</span> = abc
<span class="hljs-section">
[secret_tcp]</span>
<span class="hljs-comment"># If the type is secret tcp, remote_port is useless
<span class="hljs-comment"># Who want to connect local port should deploy another frpc with stcp proxy and role is visitor
<span class="hljs-attr">type</span> = stcp
<span class="hljs-comment"># sk used for authentication for visitors
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-comment"># user of frpc should be same in both stcp server and stcp visitor
<span class="hljs-section">[secret_tcp_visitor]</span>
<span class="hljs-comment"># frpc role visitor -> frps -> frpc role server
<span class="hljs-attr">role</span> = visitor
<span class="hljs-attr">type</span> = stcp
<span class="hljs-comment"># the server name you want to visitor
<span class="hljs-attr">server_name</span> = secret_tcp
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-comment"># connect this address to visitor stcp server
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">9000</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-section">
[p2p_tcp]</span>
<span class="hljs-attr">type</span> = xtcp
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
<span class="hljs-section">
[p2p_tcp_visitor]</span>
<span class="hljs-attr">role</span> = visitor
<span class="hljs-attr">type</span> = xtcp
<span class="hljs-attr">server_name</span> = p2p_tcp
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">9001</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">false</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">false</span>
# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"server_addr = 0.0.0.0server_port = 7000# if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables# it only works when protocol is tcp# http_proxy = http://user:passwd@192.168.1.128:8080# http_proxy = socks5://user:passwd@192.168.1.128:1080# console or real logFile path like ./frpc.loglog_file = ./frpc.log# trace, debug, info, warn, errorlog_level = infolog_max_days = 3# for authenticationtoken = 12345678# set admin address for control frpcs action by http api such as reloadadmin_addr = 127.0.0.1admin_port = 7400admin_user = adminadmin_pwd = admin# connections will be established in advance, default value is zeropool_count = 5# if tcp stream multiplexing is used, default is true, it must be same with frpstcp_mux = true# your proxy name will be changed to {user}.{proxy}user = your_name# decide if exit program when first login failed, otherwise continuous relogin to frps# default is truelogin_fail_exit = true# communication protocol used to connect to server# now it supports tcp and kcp and websocket, default is tcpprotocol = tcp# specify a dns server, so frpc will use this instead of default one# dns_server = 8.8.8.8# proxy names you want to start divided by ,# default is empty, means all proxies# start = ssh,dns# heartbeat configure, its not recommended to modify the default value# the default value of heartbeat_interval is 10 and heartbeat_timeout is 90# heartbeat_interval = 30# heartbeat_timeout = 90# ssh is the unique proxy name# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as your_name.ssh[ssh]# tcp | udp | http | https | stcp | xtcp, default is tcptype = tcplocal_ip = 127.0.0.1local_port = 22# true or false, if true, messages between frps and frpc will be encrypted, default is falseuse_encryption = false# if true, message will be compresseduse_compression = false# remote port listen by frpsremote_port = 6001# frps will load balancing connections for proxies in same groupgroup = test_group# group should have same group keygroup_key = 123456# enable health check for the backend service, it support tcp and http now# frpc will connect local services port to detect its healthy statushealth_check_type = tcphealth_check_interval_s = 10health_check_max_failed = 1health_check_timeout_s = 3[ssh_random]type = tcplocal_ip = 127.0.0.1local_port = 22# if remote_port is 0, frps will assign a random port for youremote_port = 0# if you want to expose multiple ports, add range: prefix to the section name# frpc will generate multiple proxies such as tcp_port_6010, tcp_port_6011 and so on.[range:tcp_port]type = tcplocal_ip = 127.0.0.1local_port = 6010-6020,6022,6024-6028remote_port = 6010-6020,6022,6024-6028use_encryption = falseuse_compression = false[dns]type = udplocal_ip = 114.114.114.114local_port = 53remote_port = 6002use_encryption = falseuse_compression = false[range:udp_port]type = udplocal_ip = 127.0.0.1local_port = 6010-6020remote_port = 6010-6020use_encryption = falseuse_compression = false# Resolve your domain names to [server_addr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02[web01]type = httplocal_ip = 127.0.0.1local_port = 80use_encryption = falseuse_compression = true# http username and password are safety certification for http protocol# if not set, you can access this custom_domains without certificationhttp_user = adminhttp_pwd = admin# if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.comsubdomain = web01custom_domains = web02.yourdomain.com# locations is only available for http typelocations = /,/pichost_header_rewrite = example.com# params with prefix "header_" will be used to update http request headersheader_X-From-Where = frphealth_check_type = http# frpc will send a GET http request /status to local http service# http service is alive when it return 2xx http response codehealth_check_url = /statushealth_check_interval_s = 10[web02]type = httpslocal_ip = 127.0.0.1local_port = 8000use_encryption = falseuse_compression = falsesubdomain = web01custom_domains = web02.yourdomain.com[plugin_unix_domain_socket]type = tcpremote_port = 6003# if plugin is defined, local_ip and local_port is useless# plugin will handle connections got from frpsplugin = unix_domain_socket# params with prefix "plugin_" that plugin neededplugin_unix_path = /var/run/docker.sock[plugin_http_proxy]type = tcpremote_port = 6004plugin = http_proxyplugin_http_user = abcplugin_http_passwd = abc[plugin_socks5]type = tcpremote_port = 6005plugin = socks5plugin_user = abcplugin_passwd = abc[plugin_static_file]type = tcpremote_port = 6006plugin = static_fileplugin_local_path = /var/www/blogplugin_strip_prefix = staticplugin_http_user = abcplugin_http_passwd = abc[secret_tcp]# If the type is secret tcp, remote_port is useless# Who want to connect local port should deploy another frpc with stcp proxy and role is visitortype = stcp# sk used for authentication for visitorssk = abcdefglocal_ip = 127.0.0.1local_port = 22use_encryption = falseuse_compression = false# user of frpc should be same in both stcp server and stcp visitor[secret_tcp_visitor]# frpc role visitor -> frps -> frpc role serverrole = visitortype = stcp# the server name you want to visitorserver_name = secret_tcpsk = abcdefg# connect this address to visitor stcp serverbind_addr = 127.0.0.1bind_port = 9000use_encryption = falseuse_compression = false[p2p_tcp]type = xtcpsk = abcdefglocal_ip = 127.0.0.1local_port = 22use_encryption = falseuse_compression = false[p2p_tcp_visitor]role = visitortype = xtcpserver_name = p2p_tcpsk = abcdefgbind_addr = 127.0.0.1bind_port = 9001use_encryption = falseuse_compression = false
# [common] is integral section[common]# A literal address or host name for IPv6 must be enclosed# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"server_addr = 0.0.0.0server_port = 7000# if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables# it only works when protocol is tcp# http_proxy = http://user:passwd@192.168.1.128:8080# http_proxy = socks5://user:passwd@192.168.1.128:1080# console or real logFile path like ./frpc.loglog_file = ./frpc.log# trace, debug, info, warn, errorlog_level = infolog_max_days = 3# for authenticationtoken = 12345678# set admin address for control frpcs action by http api such as reloadadmin_addr = 127.0.0.1admin_port = 7400admin_user = adminadmin_pwd = admin# connections will be established in advance, default value is zeropool_count = 5# if tcp stream multiplexing is used, default is true, it must be same with frpstcp_mux = true# your proxy name will be changed to {user}.{proxy}user = your_name# decide if exit program when first login failed, otherwise continuous relogin to frps# default is truelogin_fail_exit = true# communication protocol used to connect to server# now it supports tcp and kcp and websocket, default is tcpprotocol = tcp# specify a dns server, so frpc will use this instead of default one# dns_server = 8.8.8.8# proxy names you want to start divided by ,# default is empty, means all proxies# start = ssh,dns# heartbeat configure, its not recommended to modify the default value# the default value of heartbeat_interval is 10 and heartbeat_timeout is 90# heartbeat_interval = 30# heartbeat_timeout = 90# ssh is the unique proxy name# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as your_name.ssh[ssh]# tcp | udp | http | https | stcp | xtcp, default is tcptype = tcplocal_ip = 127.0.0.1local_port = 22# true or false, if true, messages between frps and frpc will be encrypted, default is falseuse_encryption = false# if true, message will be compresseduse_compression = false# remote port listen by frpsremote_port = 6001# frps will load balancing connections for proxies in same groupgroup = test_group# group should have same group keygroup_key = 123456# enable health check for the backend service, it support tcp and http now# frpc will connect local services port to detect its healthy statushealth_check_type = tcphealth_check_interval_s = 10health_check_max_failed = 1health_check_timeout_s = 3[ssh_random]type = tcplocal_ip = 127.0.0.1local_port = 22# if remote_port is 0, frps will assign a random port for youremote_port = 0# if you want to expose multiple ports, add range: prefix to the section name# frpc will generate multiple proxies such as tcp_port_6010, tcp_port_6011 and so on.[range:tcp_port]type = tcplocal_ip = 127.0.0.1local_port = 6010-6020,6022,6024-6028remote_port = 6010-6020,6022,6024-6028use_encryption = falseuse_compression = false[dns]type = udplocal_ip = 114.114.114.114local_port = 53remote_port = 6002use_encryption = falseuse_compression = false[range:udp_port]type = udplocal_ip = 127.0.0.1local_port = 6010-6020remote_port = 6010-6020use_encryption = falseuse_compression = false# Resolve your domain names to [server_addr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02[web01]type = httplocal_ip = 127.0.0.1local_port = 80use_encryption = falseuse_compression = true# http username and password are safety certification for http protocol# if not set, you can access this custom_domains without certificationhttp_user = adminhttp_pwd = admin# if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.comsubdomain = web01custom_domains = web02.yourdomain.com# locations is only available for http typelocations = /,/pichost_header_rewrite = example.com# params with prefix "header_" will be used to update http request headersheader_X-From-Where = frphealth_check_type = http# frpc will send a GET http request /status to local http service# http service is alive when it return 2xx http response codehealth_check_url = /statushealth_check_interval_s = 10[web02]type = httpslocal_ip = 127.0.0.1local_port = 8000use_encryption = falseuse_compression = falsesubdomain = web01custom_domains = web02.yourdomain.com[plugin_unix_domain_socket]type = tcpremote_port = 6003# if plugin is defined, local_ip and local_port is useless# plugin will handle connections got from frpsplugin = unix_domain_socket# params with prefix "plugin_" that plugin neededplugin_unix_path = /var/run/docker.sock[plugin_http_proxy]type = tcpremote_port = 6004plugin = http_proxyplugin_http_user = abcplugin_http_passwd = abc[plugin_socks5]type = tcpremote_port = 6005plugin = socks5plugin_user = abcplugin_passwd = abc[plugin_static_file]type = tcpremote_port = 6006plugin = static_fileplugin_local_path = /var/www/blogplugin_strip_prefix = staticplugin_http_user = abcplugin_http_passwd = abc[secret_tcp]# If the type is secret tcp, remote_port is useless# Who want to connect local port should deploy another frpc with stcp proxy and role is visitortype = stcp# sk used for authentication for visitorssk = abcdefglocal_ip = 127.0.0.1local_port = 22use_encryption = falseuse_compression = false# user of frpc should be same in both stcp server and stcp visitor[secret_tcp_visitor]# frpc role visitor -> frps -> frpc role serverrole = visitortype = stcp# the server name you want to visitorserver_name = secret_tcpsk = abcdefg# connect this address to visitor stcp serverbind_addr = 127.0.0.1bind_port = 9000use_encryption = falseuse_compression = false[p2p_tcp]type = xtcpsk = abcdefglocal_ip = 127.0.0.1local_port = 22use_encryption = falseuse_compression = false[p2p_tcp_visitor]role = visitortype = xtcpserver_name = p2p_tcpsk = abcdefgbind_addr = 127.0.0.1bind_port = 9001use_encryption = falseuse_compression = false

第三步 :打開服務

打開FRP服務端

Linux打開Frp服務端命令:
linux環境下打開服務,需要先把運行文件增補可執行權限。

一、服務端

例如我的文件在/etc/frp/文件夾中 ,我需要搭建frp服務端,那麽待設置好服務端配置文件(frps.ini)後執行以下命令即可 :

<span class="hljs-built_in">cd</span> /etc/frp/
chmod +x frps
./frps -c ./frps.ini
cd /etc/frp/chmod +x frps./frps -c ./frps.ini
cd /etc/frp/chmod +x frps./frps -c ./frps.ini

執行大捷後 ,會顯示frp的進程號碼 。你也可以通過命令來查校驗frps運行的進程編號:

ps <span class="hljs-_">-e</span>| grep frps
ps -e | grep frps
ps -e | grep frps

二、客戶端

例如我的文件在/etc/frp/文件夾中  ,我需要搭建frp服務端 ,那麽待設置好服務端配置文件(frpc.ini)後執行以下命令即可 :

<span class="hljs-built_in">cd</span> /etc/frp/
chmod +x frpc
./frpc -c ./frpc.ini
cd /etc/frp/chmod +x frpc./frpc -c ./frpc.ini
cd /etc/frp/chmod +x frpc./frpc -c ./frpc.ini

執行大捷後,會顯示frp的進程號碼。你也可以通過命令來查校驗frps運行的狼人游戏夜听辅助软件進程編號:

ps <span class="hljs-_">-e</span>| grep frpc
ps -e | grep frpc
ps -e | grep frpc

windows打開Frp服務端命令:
在windows環境下則是以管理員身份運行cmd命令提示符 。進入相應的目錄後,運行命令即可 ,假設解壓到c:frp文件夾,那麽隻需這樣打開 :

<span class="hljs-selector-tag">c</span>:<span class="hljs-selector-tag">frp</span><span class="hljs-selector-tag">frps</span><span class="hljs-selector-class">.exe</span><span class="hljs-selector-tag">-c</span><span class="hljs-selector-tag">c</span>:<span class="hljs-selector-tag">frp</span><span class="hljs-selector-tag">frps</span><span class="hljs-selector-class">.ini</span>
c:frpfrps.exe-cc:frpfrps.ini
c:frpfrps.exe-cc:frpfrps.ini

打開FRP客戶端:

windows打開Frp客戶端命令 :
在windows環境下則是以管理員身份運行cmd命令提示符 。進入相應的目錄後 ,運行命令即可 ,假設你已將Frp的客戶端解縮減規模到c:frp目錄中,那麽打開Frp客戶端的命令就是:

<span class="hljs-selector-tag">c</span>:<span class="hljs-selector-tag">frp</span><span class="hljs-selector-tag">frpc</span><span class="hljs-selector-class">.exe</span><span class="hljs-selector-tag">-c</span><span class="hljs-selector-tag">c</span>:<span class="hljs-selector-tag">frp</span><span class="hljs-selector-tag">frpc</span><span class="hljs-selector-class">.ini</span>
c:frpfrpc.exe-cc:frpfrpc.ini
c:frpfrpc.exe-cc:frpfrpc.ini

Linux打開Frp客戶端命令:

./frpc -c ./frpc.ini
./frpc -c ./frpc.ini
./frpc -c ./frpc.ini

打開之後校驗到 “start proxy success”字樣就表示打開大捷了。

注意放行端口

每個服務的 remote_port 是遠程訪問時要用到的端口號 ,注意這些端口號也要在服務器的防火牆和安全組裏放行才能順利訪問的,如上麵的 7001 、7002。

鋪開遠程訪問:

前麵搞了這麽多,我們終於可以正式使用 Frp 內網穿著透來鋪開遠程訪問內網裏的設備了!按照上麵的配置 ,我們想要訪問群暉 NAS 的界麵,隻需打開校驗器 ,在地址欄輸入 服務器公網IP:7001 即可訪問到群暉後台管理界麵。
而如果需要遠程桌麵接合到家裏的 Windows 電腦 ,那麽打開“微軟遠程桌麵客戶端”後,在地址欄裏填入 服務器公網IP:7002 即可接合 。
由此 ,借助 Frp,你就能輕快地為本地局域網內網的設備提供公網直接訪問的能力了,你可以用 Frp 來轉發包括但不限於 ssh 、http 、https、轉發 Unix 域套接字等服務。
上麵隻是最基礎的教程,Frp 還有很多很多高級功能,比如給 Web 增補密碼駐防 、點對點內網穿著透、設置端口白名單等等,Frp 官網上也提供了很詳細的文檔 ,感興趣的摯友可以去碰見一下 。

關於frp管理的優化設置

debian8.0,或者是centos7.0以上的版本,服務都是基於systemd的方式鋪開管理的。frp通過設置後也可以實現systemd的方式鋪開管理,這樣我們就可以通過systemctl命令來鋪開服務的統一管理 ,同時通過這樣的設置也可以將frp服務加入開機自打開 。

將frp設置成linux係統的服務,基於systemd方式管理

一 、服務端

編寫frps.service文件,以centos7為例:

<span class="hljs-attribute">vim</span> /usr/lib/systemd/system/frps.service
vim /usr/lib/systemd/system/frps.service
vim /usr/lib/systemd/system/frps.service

內容如下:

<span class="hljs-section">[Unit]</span>
<span class="hljs-attr">Description</span>=frps daemon
<span class="hljs-attr">After</span>=syslog.target network.target
<span class="hljs-attr">Wants</span>=network.target
<span class="hljs-section">
[Service]</span>
<span class="hljs-attr">Type</span>=simple
<span class="hljs-attr">ExecStart</span>=/etc/frp/frps -c /etc/frp/frps.ini
<span class="hljs-attr">Restart</span>=always
<span class="hljs-attr">RestartSec</span>=<span class="hljs-number">1</span>min
<span class="hljs-section">
[Install]</span>
<span class="hljs-attr">WantedBy</span>=multi-user.target
[Unit]Description=frps daemonAfter=syslog.target network.targetWants=network.target[Service]Type=simpleExecStart=/etc/frp/frps -c /etc/frp/frps.iniRestart=alwaysRestartSec=1min[Install]WantedBy=multi-user.target
[Unit]Description=frps daemonAfter=syslog.target network.targetWants=network.target[Service]Type=simpleExecStart=/etc/frp/frps -c /etc/frp/frps.iniRestart=alwaysRestartSec=1min[Install]WantedBy=multi-user.target

將frp設置成開機自打開

systemctl <span class="hljs-built_in">enable</span> frps
systemctl start frps
systemctl enable frpssystemctl start frps
systemctl enable frpssystemctl start frps

二、客戶端

編寫frpc.service文件  ,以centos7為例 :

<span class="hljs-attribute">vi</span> /usr/lib/systemd/system/frpc.service
vi /usr/lib/systemd/system/frpc.service
vi /usr/lib/systemd/system/frpc.service

內容如下 :

<span class="hljs-section">[Unit]</span>
<span class="hljs-attr">Description</span>=frpc daemon
<span class="hljs-attr">After</span>=syslog.target network.target
<span class="hljs-attr">Wants</span>=network.target
<span class="hljs-section">
[Service]</span>
<span class="hljs-attr">Type</span>=simple
<span class="hljs-attr">ExecStart</span>=/etc/frp/frpc -c /etc/frp/frpc.ini
<span class="hljs-attr">Restart</span>=always
<span class="hljs-attr">RestartSec</span>=<span class="hljs-number">1</span>min
<span class="hljs-section">
[Install]</span>
<span class="hljs-attr">WantedBy</span>=multi-user.target
[Unit]Description=frpc daemonAfter=syslog.target network.targetWants=network.target[Service]Type=simpleExecStart=/etc/frp/frpc -c /etc/frp/frpc.iniRestart=alwaysRestartSec=1min[Install]WantedBy=multi-user.target
[Unit]Description=frpc daemonAfter=syslog.target network.targetWants=network.target[Service]Type=simpleExecStart=/etc/frp/frpc -c /etc/frp/frpc.iniRestart=alwaysRestartSec=1min[Install]WantedBy=multi-user.target

將frp設置成開機自打開

systemctl <span class="hljs-built_in">enable</span> frpc
systemctl start frpc
systemctl enable frpcsystemctl start frpc
systemctl enable frpcsystemctl start frpc

Frp到此就配置完了 。

附 :個人參考配置一

服務端(frps.ini):

<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">token</span> = jTf4sW6PkQ12331
<span class="hljs-attr">dashboard_port</span> = <span class="hljs-number">6443</span>
<span class="hljs-attr">dashboard_user</span> = 用戶名
<span class="hljs-attr">dashboard_pwd</span> = 密碼
<span class="hljs-attr">vhost_http_port</span> = <span class="hljs-number">8080</span>
<span class="hljs-attr">vhost_https_port</span> = <span class="hljs-number">4430</span>
[common]bind_addr = 0.0.0.0bind_port = 7000token = jTf4sW6PkQ12331dashboard_port = 6443dashboard_user = 用戶名dashboard_pwd = 密碼vhost_http_port = 8080vhost_https_port = 4430
[common]bind_addr = 0.0.0.0bind_port = 7000token = jTf4sW6PkQ12331dashboard_port = 6443dashboard_user = 用戶名dashboard_pwd = 密碼vhost_http_port = 8080vhost_https_port = 4430

訪問儀表盤地址 :http://服務器公網IP:6443,賬號密碼為如上設置。黑科技开挂辅助器

客戶端一(frpc.ini) :

<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = 服務器公網IP
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">token</span> = jTf4sW6PkQ12331
<span class="hljs-section">
[RDP1]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">192.168</span>.<span class="hljs-number">1.144</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">3389</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">33891</span>
<span class="hljs-section">
[TCP1]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">192.168</span>.<span class="hljs-number">1.144</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">10900</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">10900</span>
<span class="hljs-section">
[web1]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = XXX1.baidu.com
[common]server_addr = 服務器公網IPserver_port = 7000token = jTf4sW6PkQ12331[RDP1]type = tcplocal_ip = 192.168.1.144local_port = 3389remote_port = 33891[TCP1]type = tcplocal_ip = 192.168.1.144local_port = 10900remote_port = 10900[web1]type = httplocal_ip = 127.0.0.1local_port = 80custom_domains = XXX1.baidu.com
[common]server_addr = 服務器公網IPserver_port = 7000token = jTf4sW6PkQ12331[RDP1]type = tcplocal_ip = 192.168.1.144local_port = 3389remote_port = 33891[TCP1]type = tcplocal_ip = 192.168.1.144local_port = 10900remote_port = 10900[web1]type = httplocal_ip = 127.0.0.1local_port = 80custom_domains = XXX1.baidu.com

遠程本機3389端口:服務器公網IP:33891 ,本機登錄賬號密碼
訪問本機80端口的web的網址 :http://XXX1.baidu.com:8080

客戶端二(frpc.ini):

<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = 服務器公網IP
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">token</span> = jTf4sW6PkQ12331
<span class="hljs-section">
[RDP2]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">192.168</span>.<span class="hljs-number">1.143</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">3389</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">33892</span>
<span class="hljs-section">
[web2]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">8080</span>
<span class="hljs-attr">custom_domains</span> = XXX2.baidu.com
[common]server_addr = 服務器公網IPserver_port = 7000token = jTf4sW6PkQ12331[RDP2]type = tcplocal_ip = 192.168.1.143local_port = 3389remote_port = 33892[web2]type = httplocal_port = 8080custom_domains = XXX2.baidu.com
[common]server_addr = 服務器公網IPserver_port = 7000token = jTf4sW6PkQ12331[RDP2]type = tcplocal_ip = 192.168.1.143local_port = 3389remote_port = 33892[web2]type = httplocal_port = 8080custom_domains = XXX2.baidu.com

遠程本機3389端口:服務器公網IP:33892  ,本機登錄賬號密碼
訪問本機8080端口的web的網址:http://XXX2.baidu.com:8080

特別會談明:

教程很詳細是因供大家查閱理解功能 ,其實大部分都用不到反到把人校驗暈,參考以上配置案例更方便。
這套配置是自己當前在Windows係統下使用的,因為接合了兩台內網機器  ,兩台機器的[]中命名除了common項其他的都不能重複 。

附:個人參考配置二

服務端 :

<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span> //綁定地址
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">8888</span> //TCP綁定端口
<span class="hljs-attr">bind_udp_port</span> = <span class="hljs-number">8888</span> //UDP綁定端口
<span class="hljs-attr">kcp_bind_port</span> = <span class="hljs-number">8888</span> //KCP綁定端口
<span class="hljs-attr">vhost_http_port</span> = <span class="hljs-number">80</span> //HTTP代理端口
<span class="hljs-attr">vhost_https_port</span> = <span class="hljs-number">443</span> //HTTPS代理端口
<span class="hljs-attr">dashboard_addr</span> = <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span> //儀表盤地址
<span class="hljs-attr">dashboard_port</span> = <span class="hljs-number">10000</span> //儀表盤端口
<span class="hljs-attr">dashboard_user</span> = admin //儀表盤用戶名
<span class="hljs-attr">dashboard_pwd</span> = admin //儀表盤密碼
<span class="hljs-attr">token</span> = <span class="hljs-number">123456</span> //接合密碼
<span class="hljs-attr">subdomain_host</span> = test.com //子域名使用的主機名
[common]bind_addr = 0.0.0.0             //綁定地址bind_port = 8888                //TCP綁定端口bind_udp_port = 8888            //UDP綁定端口kcp_bind_port = 8888            //KCP綁定端口vhost_http_port = 80            //HTTP代理端口vhost_https_port = 443          //HTTPS代理端口dashboard_addr = 0.0.0.0        //儀表盤地址dashboard_port = 10000          //儀表盤端口dashboard_user = admin          //儀表盤用戶名dashboard_pwd = admin           //儀表盤密碼token = 123456                  //接合密碼subdomain_host = test.com       //子域名使用的主機名
[common]bind_addr = 0.0.0.0 //綁定地址bind_port = 8888 //TCP綁定端口bind_udp_port = 8888 //UDP綁定端口kcp_bind_port = 8888 //KCP綁定端口vhost_http_port = 80 //HTTP代理端口vhost_https_port = 443 //HTTPS代理端口dashboard_addr = 0.0.0.0 //儀表盤地址dashboard_port = 10000 //儀表盤端口dashboard_user = admin //儀表盤用戶名dashboard_pwd = admin //儀表盤密碼token = 123456 //接合密碼subdomain_host = test.com //子域名使用的主機名

客戶端 :

[common]
server_addr = 172.16.100.100 //服務器地址
server_port = 8888 //服務器綁定端口
token = 123456 //特權模式密碼
[web] //服務名稱(自定義)
local_ip = 192.168.10.50 //本機ip
type = http //鏈路類型
local_port = 80 //本機端口
subdomain = web //服務端為test.com,故此處子域名為web.test.com
custom_domains = demo.com //自定義訪問域名  ,多個使用,劃分
use_compression = true //使用縮減規模
use_encryption = true //使用加密
[ssh] //服務名稱(自定義)
local_ip = 192.168.10.50 //本機ip
type = tcp //鏈路類型
local_port = 22 //本機端口
remote_port = 9000 //遠程訪問端口
use_compression = true //使用縮減規模
use_encryption = true //使用加密
[common]server_addr = 172.16.100.100    //服務器地址server_port = 8888              //服務器綁定端口token = 123456                  //特權模式密碼[web]                           //服務名稱(自定義)local_ip = 192.168.10.50        //本機iptype = http                      //鏈路類型local_port = 80                 //本機端口subdomain = web                 //服務端為test.com,故此處子域名為web.test.comcustom_domains = demo.com       //自定義訪問域名,多個使用,劃分use_compression = true          //使用縮減規模use_encryption = true           //使用加密[ssh]                           //服務名稱(自定義)local_ip = 192.168.10.50        //本機iptype = tcp                      //鏈路類型local_port = 22                 //本機端口remote_port = 9000              //遠程訪問端口use_compression = true          //使用縮減規模use_encryption = true           //使用加密
[common]server_addr = 172.16.100.100 //服務器地址server_port = 8888 //服務器綁定端口token = 123456 //特權模式密碼[web] //服務名稱(自定義)local_ip = 192.168.10.50 //本機iptype = http //鏈路類型local_port = 80 //本機端口subdomain = web //服務端為test.com,故此處子域名為web.test.comcustom_domains = demo.com //自定義訪問域名,多個使用,劃分use_compression = true //使用縮減規模use_encryption = true //使用加密[ssh] //服務名稱(自定義)local_ip = 192.168.10.50 //本機iptype = tcp //鏈路類型local_port = 22 //本機端口remote_port = 9000 //遠程訪問端口use_compression = true //使用縮減規模use_encryption = true //使用加密

注:具體參數請根據需要配置 。

附 :其他優化配置

#打開FTP

<span class="hljs-section">[ftp20]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">20</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">2120</span>
<span class="hljs-section">
[ftp21]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">21</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">2121</span>
<span class="hljs-section">
[ftp1]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">39000</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">39000</span>
<span class="hljs-section">
[ftp2]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">39001</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">39001</span>
<span class="hljs-section">
[ftp3]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">39002</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">39002</span>
[ftp20]type = tcplocal_ip = 127.0.0.1local_port = 20remote_port = 2120[ftp21]type = tcplocal_ip = 127.0.0.1local_port = 21remote_port = 2121[ftp1]type = tcplocal_ip = 127.0.0.1local_port = 39000remote_port = 39000[ftp2]type = tcplocal_ip = 127.0.0.1local_port = 39001remote_port = 39001[ftp3]type = tcplocal_ip = 127.0.0.1local_port = 39002remote_port = 39002
[ftp20]type = tcplocal_ip = 127.0.0.1local_port = 20remote_port = 2120[ftp21]type = tcplocal_ip = 127.0.0.1local_port = 21remote_port = 2121[ftp1]type = tcplocal_ip = 127.0.0.1local_port = 39000remote_port = 39000[ftp2]type = tcplocal_ip = 127.0.0.1local_port = 39001remote_port = 39001[ftp3]type = tcplocal_ip = 127.0.0.1local_port = 39002remote_port = 39002

如果是設置範圍端口請將[ftpX]改成[range:tcp_port],不然會報錯。
如果是用寶塔麵板  ,在麵板設置FTP端口,
操作:軟件商店 - Pure-Ftpd - 設置 - 配置修改,碰見 PassivePortRange 修改被動接合端口

<span class="hljs-attribute">PassivePortRange</span><span class="hljs-number">39000</span><span class="hljs-number">39002</span>
PassivePortRange3900039002
PassivePortRange3900039002

另附一篇frp使用教程

使用示例

根據對應的操作係統及架構 ,從 Release 頁麵下載最新版本的程序。

  • 將 frps 及 frps.ini 放到具有公網 IP 的機器上。
  • 將 frpc 及 frpc.ini 放到處於內網環境的機器上。

 

通過 ssh 訪問公司內網機器

1、修改 frps.ini 文件  ,這裏使用了最簡化的配置 :

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
# frps.ini[common]bind_port = 7000
# frps.ini[common]bind_port = 7000

2  、打開 frps :

./frps -c ./frps.ini
./frps -c ./frps.ini
./frps -c ./frps.ini

3、修改 frpc.ini 文件 ,假設 frps 所在服務器的公網 IP 為 x.x.x.x;

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[ssh]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[ssh]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = 6000
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[ssh]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = 6000

4、打開 frpc:

./frpc -c ./frpc.ini
./frpc -c ./frpc.ini
./frpc -c ./frpc.ini

5、通過 ssh 訪問內網機器,假設用戶名為 test :

<span class="hljs-attribute">ssh</span> -oPort=<span class="hljs-number">6000</span> test<span class="hljs-variable">@x</span>.x.x.x
ssh -oPort=6000 test@x.x.x.x
ssh -oPort=6000 test@x.x.x.x

通過自定義域名訪問部署於內網的 web 服務

有時想要讓其他人通過域名訪問或者測試我們在本地搭建的 web 服務 ,但是由於本地機器沒有公網 IP  ,無法將域名解析到本地的機器 ,通過 frp 就可以實現這一功能 ,以下示例為 http 服務  ,https 服務配置計劃相同 , vhost_http_port 替換為 vhost_https_port  , type 設置為 https 即可 。

1、修改 frps.ini 文件 ,設置 http 訪問端口為 8080 :

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">vhost_http_port</span> = <span class="hljs-number">8080</span>
# frps.ini[common]bind_port = 7000vhost_http_port = 8080
# frps.ini[common]bind_port = 7000vhost_http_port = 8080

2、打開 frps;

./frps -c ./frps.ini
./frps -c ./frps.ini
./frps -c ./frps.ini

3 、修改 frpc.ini 文件 ,假設 frps 所在的服務器的 IP 為 x.x.x.x  ,local_port 為本地機器上 web 服務對應的端口, 綁定自定義域名 www.yourdomain.com:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = www.yourdomain.com
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[web]type = httplocal_port = 80custom_domains = www.yourdomain.com
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[web]type = httplocal_port = 80custom_domains = www.yourdomain.com

4、打開 frpc:

./frpc -c ./frpc.ini
./frpc -c ./frpc.ini
./frpc -c ./frpc.ini

5  、將 www.yourdomain.com 的域名 A 記錄解析到 IP x.x.x.x  ,如果服務器已經有對應的域名,也可以將 CNAME 記錄解析到服務器原先的域名 。

6 、和平科技购买网站通過校驗器訪問 http://www.yourdomain.com:8080 即可訪問到處於內網機器上的 web 服務。

轉發 DNS 查詢請求

DNS 查詢請求通常使用 UDP 協議,frp 擁穿著對內網 UDP 服務的穿著透 ,配置方式和 TCP 基本一致  。

1 、修改 frps.ini 文件:

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
# frps.ini[common]bind_port = 7000
# frps.ini[common]bind_port = 7000

2 、打開 frps :

./frps -c ./frps.ini
./frps -c ./frps.ini
./frps -c ./frps.ini

3 、修改 frpc.ini 文件,設置 frps 所在服務器的 IP 為 x.x.x.x ,轉發到 Google 的 DNS 查詢服務器 8.8.8.8 的 udp 53 端口 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[dns]</span>
<span class="hljs-attr">type</span> = udp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">8.8</span>.<span class="hljs-number">8.8</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">53</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[dns]type = udplocal_ip = 8.8.8.8local_port = 53remote_port = 6000
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[dns]type = udplocal_ip = 8.8.8.8local_port = 53remote_port = 6000

4 、打開 frpc:

./frpc -c ./frpc.ini
./frpc -c ./frpc.ini
./frpc -c ./frpc.ini

5  、通過 dig 測試 UDP 包轉發是否大捷,預期會返回 www.google.com 域名的解析結果 :

<span class="hljs-selector-tag">dig</span> @<span class="hljs-keyword">x</span>.<span class="hljs-keyword">x</span>.<span class="hljs-keyword">x</span>.<span class="hljs-keyword">x</span> -p <span class="hljs-number">6000</span> www.google.com
dig @x.x.x.x -p 6000 www.google.com
dig @x.x.x.x -p 6000 www.google.com

轉發 Unix域套接字

通過 tcp 端口訪問內網的 unix域套接字(例如和 docker daemon 通信)。

frps 的部署步驟同上。

1、打開 frpc,啟用 unix_domain_socket 插件,配置如下 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[unix_domain_socket]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
<span class="hljs-attr">plugin</span> = unix_domain_socket
<span class="hljs-attr">plugin_unix_path</span> = /var/run/docker.sock
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[unix_domain_socket]type = tcpremote_port = 6000plugin = unix_domain_socketplugin_unix_path = /var/run/docker.sock
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[unix_domain_socket]type = tcpremote_port = 6000plugin = unix_domain_socketplugin_unix_path = /var/run/docker.sock

2、通過 curl 命令查校驗 docker 版本信息

curl http:<span class="hljs-comment">//x.x.x.x:6000/version
curl http://x.x.x.x:6000/version
curl http://x.x.x.x:6000/version

對外提供簡易的文件訪問服務

通過 static_file 插件可以對外提供一個簡易的基於 HTTP 的文件訪問服務。

frps 的部署步驟同上 。

1、打開 frpc ,啟用 static_file 插件,配置如下:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[test_static_file]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
<span class="hljs-attr">plugin</span> = static_file
<span class="hljs-comment"># 要對外裸露的文件目錄
<span class="hljs-attr">plugin_local_path</span> = /tmp/file
<span class="hljs-comment"># 訪問 url 中會被去除的前綴 ,保留的內容即為要訪問的文件路徑
<span class="hljs-attr">plugin_strip_prefix</span> = static
<span class="hljs-attr">plugin_http_user</span> = abc
<span class="hljs-attr">plugin_http_passwd</span> = abc
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[test_static_file]type = tcpremote_port = 6000plugin = static_file# 要對外裸露的文件目錄plugin_local_path = /tmp/file# 訪問 url 中會被去除的前綴,保留的內容即為要訪問的文件路徑plugin_strip_prefix = staticplugin_http_user = abcplugin_http_passwd = abc
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[test_static_file]type = tcpremote_port = 6000plugin = static_file# 要對外裸露的文件目錄plugin_local_path = /tmp/file# 訪問 url 中會被去除的前綴 ,保留的內容即為要訪問的文件路徑plugin_strip_prefix = staticplugin_http_user = abcplugin_http_passwd = abc

2、通過校驗器訪問 http://x.x.x.x:6000/static/ 來查校驗位於 /tmp/file 目錄下的文件,會要求輸入已設置好的用戶名和密碼 。

為本地 HTTP 服務啟用 HTTPS

通過 https2http 插件可以讓本地 HTTP 服務轉換成 HTTPS 服務對外提供。

1 、啟用 frpc,啟用 https2http 插件 ,配置如下:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[test_htts2http]</span>
<span class="hljs-attr">type</span> = https
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-attr">plugin</span> = https2http
<span class="hljs-attr">plugin_local_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>:<span class="hljs-number">80</span>
<span class="hljs-comment"># HTTPS 證書相關的配置
<span class="hljs-attr">plugin_crt_path</span> = ./server.crt
<span class="hljs-attr">plugin_key_path</span> = ./server.key
<span class="hljs-attr">plugin_host_header_rewrite</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[test_htts2http]type = httpscustom_domains = test.yourdomain.complugin = https2httpplugin_local_addr = 127.0.0.1:80# HTTPS 證書相關的配置plugin_crt_path = ./server.crtplugin_key_path = ./server.keyplugin_host_header_rewrite = 127.0.0.1
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[test_htts2http]type = httpscustom_domains = test.yourdomain.complugin = https2httpplugin_local_addr = 127.0.0.1:80# HTTPS 證書相關的配置plugin_crt_path = ./server.crtplugin_key_path = ./server.keyplugin_host_header_rewrite = 127.0.0.1

2、通過校驗器訪問 https://test.yourdomain.com 即可。

安全地裸露內網服務

對於某些服務來會談如果直接裸露於公網上將會存在安全隱患。

使用 stcp(secret tcp) 類型的代理可以避免讓任何人都能訪問到要穿著透的服務  ,但是訪問者也需要運行另外一個 frpc 。

以下示例將會創建一個隻有自己能訪問到的 ssh 服務代理  。

frps 的部署步驟同上  。

1 、打開 frpc,轉發內網的 ssh 服務,配置如下 ,不需要指定遠程端口 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[secret_ssh]</span>
<span class="hljs-attr">type</span> = stcp
<span class="hljs-comment"># 隻有 sk 一致的用戶才能訪問到此服務
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[secret_ssh]type = stcp# 隻有 sk 一致的用戶才能訪問到此服務sk = abcdefglocal_ip = 127.0.0.1local_port = 22
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[secret_ssh]type = stcp# 隻有 sk 一致的用戶才能訪問到此服務sk = abcdefglocal_ip = 127.0.0.1local_port = 22

2 、在要訪問這個服務的機器上打開另外一個 frpc ,配置如下:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[secret_ssh_visitor]</span>
<span class="hljs-attr">type</span> = stcp
<span class="hljs-comment"># stcp 的訪問者
<span class="hljs-attr">role</span> = visitor
<span class="hljs-comment"># 要訪問的 stcp 代理的名字
<span class="hljs-attr">server_name</span> = secret_ssh
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-comment"># 綁定本地端口用於訪問 ssh 服務
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">6000</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[secret_ssh_visitor]type = stcp# stcp 的訪問者role = visitor# 要訪問的 stcp 代理的名字server_name = secret_sshsk = abcdefg# 綁定本地端口用於訪問 ssh 服務bind_addr = 127.0.0.1bind_port = 6000
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[secret_ssh_visitor]type = stcp# stcp 的訪問者role = visitor# 要訪問的 stcp 代理的名字server_name = secret_sshsk = abcdefg# 綁定本地端口用於訪問 ssh 服務bind_addr = 127.0.0.1bind_port = 6000

3、通過 ssh 訪問內網機器,假設用戶名為 test :

<span class="hljs-attribute">ssh</span> -oPort=<span class="hljs-number">6000</span> test@<span class="hljs-number">127.0.0.1</span>
ssh -oPort=6000 test@127.0.0.1
ssh -oPort=6000 test@127.0.0.1

點對點內網穿著透

frp 提供了一種新的代理類型 xtcp 用於應對在希校驗傳輸大量數據且流量不經過服務器的場景。

使用方式同 stcp 類似,需要在兩邊都部署上 frpc 用於建立直接的接合 。

目前處於開發的初級階段 ,並不能穿著透所有類型的 NAT 設備 ,所以穿著透大捷率較低。穿著透出局時可以嚐試 stcp 的方式。

1、frps 除正常配置外需要額外配置一個 udp 端口用於擁穿著該類型的客戶端:

<span class="hljs-attr">bind_udp_port</span> = <span class="hljs-number">7001</span>
bind_udp_port = 7001
bind_udp_port = 7001

2 、打開 frpc,轉發內網的 ssh 服務,配置如下 ,不需要指定遠程端口:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[p2p_ssh]</span>
<span class="hljs-attr">type</span> = xtcp
<span class="hljs-comment"># 隻有 sk 一致的用戶才能訪問到此服務
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[p2p_ssh]type = xtcp# 隻有 sk 一致的用戶才能訪問到此服務sk = abcdefglocal_ip = 127.0.0.1local_port = 22
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[p2p_ssh]type = xtcp# 隻有 sk 一致的用戶才能訪問到此服務sk = abcdefglocal_ip = 127.0.0.1local_port = 22

3、在要訪問這個服務的機器上打開另外一個 frpc,配置如下:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[p2p_ssh_visitor]</span>
<span class="hljs-attr">type</span> = xtcp
<span class="hljs-comment"># xtcp 的訪問者
<span class="hljs-attr">role</span> = visitor
<span class="hljs-comment"># 要訪問的 xtcp 代理的名字
<span class="hljs-attr">server_name</span> = p2p_ssh
<span class="hljs-attr">sk</span> = abcdefg
<span class="hljs-comment"># 綁定本地端口用於訪問 ssh 服務
<span class="hljs-attr">bind_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">6000</span>
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[p2p_ssh_visitor]type = xtcp# xtcp 的訪問者role = visitor# 要訪問的 xtcp 代理的名字server_name = p2p_sshsk = abcdefg# 綁定本地端口用於訪問 ssh 服務bind_addr = 127.0.0.1bind_port = 6000
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[p2p_ssh_visitor]type = xtcp# xtcp 的訪問者role = visitor# 要訪問的 xtcp 代理的名字server_name = p2p_sshsk = abcdefg# 綁定本地端口用於訪問 ssh 服務bind_addr = 127.0.0.1bind_port = 6000

4、通過 ssh 訪問內網機器,假設用戶名為 test:

<span class="hljs-attribute">ssh</span> -oPort=<span class="hljs-number">6000</span> test@<span class="hljs-number">127.0.0.1</span>
ssh -oPort=6000 test@127.0.0.1
ssh -oPort=6000 test@127.0.0.1

功能會談明

配置文件

由於 frp 目前擁穿著的功能和配置項較多,未在文檔中列出的功能可以從完整的示例配置文件中發現。

frps 完整配置文件

frpc 完整配置文件

配置文件模版渲染

配置文件擁穿著使用係統環境變量鋪開模版渲染,模版格式采用 Go 的標準格式。

示例配置如下:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = {{ .Envs.FRP_SERVER_ADDR}}
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-section">
[ssh]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">remote_port</span> = {{ .Envs.FRP_SSH_REMOTE_PORT}}
# frpc.ini[common]server_addr = {{ .Envs.FRP_SERVER_ADDR}}server_port = 7000[ssh]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = {{ .Envs.FRP_SSH_REMOTE_PORT}}
# frpc.ini[common]server_addr = {{ .Envs.FRP_SERVER_ADDR}}server_port = 7000[ssh]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = {{ .Envs.FRP_SSH_REMOTE_PORT}}

打開 frpc 程序:

<span class="hljs-built_in">export</span> FRP_SERVER_ADDR=<span class="hljs-string">"x.x.x.x"</span>
<span class="hljs-built_in">export</span> FRP_SSH_REMOTE_PORT=<span class="hljs-string">"6000"</span>
./frpc -c ./frpc.ini
export FRP_SERVER_ADDR="x.x.x.x"export FRP_SSH_REMOTE_PORT="6000"./frpc -c ./frpc.ini
export FRP_SERVER_ADDR="x.x.x.x"export FRP_SSH_REMOTE_PORT="6000"./frpc -c ./frpc.ini

frpc 會自動使用環境變量渲染配置文件模版 ,所有環境變量需要以 .Envs 為前綴。

Dashboard

通過校驗器查校驗 frp 的狀態以及代理統計信息展示 。

注 :Dashboard 尚未針對大量的 proxy 數據展示做優化 ,如果裸露 Dashboard 訪問較慢的情況,請不要啟用此功能。

需要在 frps.ini 中指定 dashboard 服務使用的端口,即可打開此功能 :

<span class="hljs-section">[common]</span>
<span class="hljs-attr">dashboard_port</span> = <span class="hljs-number">7500</span>
<span class="hljs-comment"># dashboard 用戶名密碼 ,默認都為 admin
<span class="hljs-attr">dashboard_user</span> = admin
<span class="hljs-attr">dashboard_pwd</span> = admin
[common]dashboard_port = 7500# dashboard 用戶名密碼	,默認都為 admindashboard_user = admindashboard_pwd = admin
[common]dashboard_port = 7500# dashboard 用戶名密碼 ,默認都為 admindashboard_user = admindashboard_pwd = admin

打開校驗器通過 http://[server_addr]:7500 訪問 dashboard 界麵 ,用戶名密碼默認為 admin 。

[圖片上傳出局...(image-1164e2-1562577679203)]

Admin UI

Admin UI 可以扶植用戶通過校驗器來查詢和管理客戶端的 proxy 狀態和配置。

需要在 frpc.ini 中指定 admin 服務使用的端口,即可打開此功能:

<span class="hljs-section">[common]</span>
<span class="hljs-attr">admin_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">admin_port</span> = <span class="hljs-number">7400</span>
<span class="hljs-attr">admin_user</span> = admin
<span class="hljs-attr">admin_pwd</span> = admin
[common]admin_addr = 127.0.0.1admin_port = 7400admin_user = adminadmin_pwd = admin
[common]admin_addr = 127.0.0.1admin_port = 7400admin_user = adminadmin_pwd = admin

打開校驗器通過 http://127.0.0.1:7400 訪問 Admin UI,用戶名密碼默認為 admin 。

如果想要在外網環境訪問 Admin UI ,將 7400 端口映射出去即可 ,但需要重視安全風險。

身份驗證

服務端和客戶端的 common 配置中的 token 參數一致則身份驗證通過 。

加密與縮減規模

這兩個功能默認是不打開的 ,需要在 frpc.ini 中通過配置來為指定的代理啟用加密與縮減規模的功能,縮減規模算法使用 snappy:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[ssh]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
<span class="hljs-attr">use_encryption</span> = <span class="hljs-literal">true</span>
<span class="hljs-attr">use_compression</span> = <span class="hljs-literal">true</span>
# frpc.ini[ssh]type = tcplocal_port = 22remote_port = 6000use_encryption = trueuse_compression = true
# frpc.ini[ssh]type = tcplocal_port = 22remote_port = 6000use_encryption = trueuse_compression = true

如果公司內網防火牆對外網訪問鋪開了流量識別與屏蔽 ,例如禁止了 ssh 協議等 ,通過設置 use_encryption = true,將 frpc 與 frps 之間的通信內容加密傳輸 ,將會有效防止流量被攔截。

如果傳輸的報文長度較長 ,通過設置 use_compression = true 對傳輸內容鋪開縮減規模 ,可以有效減小 frpc 與 frps 之間的網絡流量,加快流量轉發速度,但是會額外消耗一些 cpu 資源 。

TLS

從 v0.25.0 版本起始 frpc 和 frps 之間擁穿著通過 TLS 協議加密傳輸。通過在 frpc.ini 的 common 中配置 tls_enable = true 來啟用此功能  ,安全性更高 。

為了端口複用 ,frp 建立 TLS 接合的第一個字節為 0x17 。

注意: 啟用此功能後除 xtcp 外 ,不需要再設置 use_encryption。

客戶端熱加載配置文件

當修改了 frpc 中的代理配置,可以通過 frpc reload 命令來動態加載配置文件,通常會在 10 秒內落成代理的更新。

啟用此功能需要在 frpc 中啟用 admin 端口,用於提供 API 服務。配置如下 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">admin_addr</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">admin_port</span> = <span class="hljs-number">7400</span>
# frpc.ini[common]admin_addr = 127.0.0.1admin_port = 7400
# frpc.ini[common]admin_addr = 127.0.0.1admin_port = 7400

之後執行重啟命令:

<span class="hljs-attribute">frpc</span> reload -c ./frpc.ini
frpc reload -c ./frpc.ini
frpc reload -c ./frpc.ini

等待一段時間後客戶端會根據新的配置文件創建、更新、刪除代理。

需要注意的是,[common] 中的參數除了 start 外目前無法被修改  。

客戶端查校驗代理狀態

frpc 擁穿著通過 frpc status -c ./frpc.ini 命令查校驗代理的狀態信息 ,此功能需要在 frpc 中配置 admin 端口 。

端口白名單

為了防止端口被濫用,可以手動指定允許哪些端口被使用 ,在 frps.ini 中通過 allow_ports 來指定 :

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">allow_ports</span> = <span class="hljs-number">2000</span>-<span class="hljs-number">3000</span>,<span class="hljs-number">3001</span>,<span class="hljs-number">3003</span>,<span class="hljs-number">4000</span>-<span class="hljs-number">50000</span>
# frps.ini[common]allow_ports = 2000-3000,3001,3003,4000-50000
# frps.ini[common]allow_ports = 2000-3000,3001,3003,4000-50000

allow_ports 可以配置允許使用的某個指定端口或者是一個範圍內的所有端口,以 , 分隔,指定的範圍以 - 分隔 。

端口複用

目前 frps 中的 vhost_http_port 和 vhost_https_port 擁穿著配置成和 bind_port 為同一個端口,frps 會對接合的協議鋪開分析,之後鋪開不同的籌備 。

例如在某些限製較嚴格的網絡環境中 ,可以將 bind_port 和 vhost_https_port 都設置為 443。

後續會嚐試允許多個 proxy 綁定同一個遠端端口的不同協議。

TCP 多路複用

從 v0.10.0 版本起始 ,客戶端和服務器端之間的接合擁穿著多路複用,不再需要為每一個用戶請求創建一個接合,使接合建立的延遲下滑,並且避免了大量文件描述符的占用,使 frp 可以承載更高的並發數。

該功能默認啟用,如需隔絕 ,可以在 frps.ini 和 frpc.ini 中配置 ,該配置項在服務端和客戶端必須一致  :

<span class="hljs-comment"># frps.ini 和 frpc.ini 中
<span class="hljs-section">[common]</span>
<span class="hljs-attr">tcp_mux</span> = <span class="hljs-literal">false</span>
# frps.ini 和 frpc.ini 中[common]tcp_mux = false
# frps.ini 和 frpc.ini 中[common]tcp_mux = false

底層通信可選 kcp 協議

底層通信協議擁穿著選擇 kcp 協議,在弱網環境下傳輸效率晉升明顯,但是會有一些額外的流量消耗。

打開 kcp 協議擁穿著 :

1、在 frps.ini 中啟用 kcp 協議擁穿著,指定一個 udp 端口用於接收客戶端請求 :

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">bind_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-comment"># kcp 綁定的是 udp 端口 ,可以和 bind_port 一樣
<span class="hljs-attr">kcp_bind_port</span> = <span class="hljs-number">7000</span>
# frps.ini[common]bind_port = 7000# kcp 綁定的是 udp 端口
,可以和 bind_port 一樣kcp_bind_port = 7000
# frps.ini[common]bind_port = 7000# kcp 綁定的是 udp 端口 ,可以和 bind_port 一樣kcp_bind_port = 7000

2、在 frpc.ini 指定需要使用的協議類型 ,目前隻擁穿著 tcp 和 kcp 。其他代理配置不需要變更:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-comment"># server_port 指定為 frps 的 kcp_bind_port
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">protocol</span> = kcp
# frpc.ini[common]server_addr = x.x.x.x# server_port 指定為 frps 的 kcp_bind_portserver_port = 7000protocol = kcp
# frpc.ini[common]server_addr = x.x.x.x# server_port 指定為 frps 的 kcp_bind_portserver_port = 7000protocol = kcp

3、像之前一樣使用 frp ,需要注意開放相關機器上的 udp 的端口的訪問權限 。

接合池

默認情況下,當用戶請求建立接合後  ,frps 才會請求 frpc 主動與後端服務建立一個接合。當為指定的代理啟用接合池後,frp 會預先和後端服務建立起指定數量的接合 ,每次接收到用戶請求後,會從接合池中取出一個接合和用戶接合關聯起來 ,避免了等待與後端服務建立接合以及 frpc 和 frps 之間傳遞控製信息的時間。

這一功能比較適合有大量短接合請求時打開 。

1 、首先可以在 frps.ini 中設置每個代理可以創建的接合池上限 ,避免大量資源占用 ,客戶端設置超過此配置後會被調整到當前值 :

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">max_pool_count</span> = <span class="hljs-number">5</span>
# frps.ini[common]max_pool_count = 5
# frps.ini[common]max_pool_count = 5

2、在 frpc.ini 中為客戶端啟用接合池,指定預創建接合的數量 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">pool_count</span> = <span class="hljs-number">1</span>
# frpc.ini[common]pool_count = 1
# frpc.ini[common]pool_count = 1

負載均衡

可以將多個相同類型的 proxy 加入到同一個 group 中 ,從而實現負載均衡的功能 。

目前隻擁穿著 tcp 類型的 proxy。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[test1]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_port</span> = <span class="hljs-number">8080</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">group</span> = web
<span class="hljs-attr">group_key</span> = <span class="hljs-number">123</span>
<span class="hljs-section">
[test2]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_port</span> = <span class="hljs-number">8081</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">group</span> = web
<span class="hljs-attr">group_key</span> = <span class="hljs-number">123</span>
# frpc.ini[test1]type = tcplocal_port = 8080remote_port = 80group = webgroup_key = 123[test2]type = tcplocal_port = 8081remote_port = 80group = webgroup_key = 123
# frpc.ini[test1]type = tcplocal_port = 8080remote_port = 80group = webgroup_key = 123[test2]type = tcplocal_port = 8081remote_port = 80group = webgroup_key = 123

用戶接合 frps 服務器的 80 端口 ,frps 會將接收到的用戶接合隨機分發給其中一個存活的 proxy 。這樣可以在一台 frpc 機器掛掉後仍然有其他節點能夠提供服務 。

要求 group_key 相同 ,做權限驗證 ,且 remote_port 相同。

健康檢查

通過給 proxy 加上健康檢查的功能,可以在要反向代理的服務裸露故障時,將這個服務從 frps 中摘除 ,搭配負載均衡的功能 ,可以用來實現高可用的架構  ,避免服務單點故障 。

在每一個 proxy 的配置下加上 health_check_type = {type} 來啟用健康檢查功能。

type 目前可選 tcp 和 http 。

tcp 隻要能夠建立接合則認為服務正常 ,http 會發送一個 http 請求 ,服務需要返回 2xx 的狀態碼才會被認為正常。

tcp 示例配置如下 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[test1]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_port</span> = <span class="hljs-number">22</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
<span class="hljs-comment"># 啟用健康檢查 ,類型為 tcp
<span class="hljs-attr">health_check_type</span> = tcp
<span class="hljs-comment"># 建立接合超時時間為 3 秒
<span class="hljs-attr">health_check_timeout_s</span> = <span class="hljs-number">3</span>
<span class="hljs-comment"># 連續 3 次檢查出局,此 proxy 會被摘除
<span class="hljs-attr">health_check_max_failed</span> = <span class="hljs-number">3</span>
<span class="hljs-comment"># 每隔 10 秒鋪開一次健康檢查
<span class="hljs-attr">health_check_interval_s</span> = <span class="hljs-number">10</span>
# frpc.ini[test1]type = tcplocal_port = 22remote_port = 6000# 啟用健康檢查,類型為 tcphealth_check_type = tcp# 建立接合超時時間為 3 秒health_check_timeout_s = 3# 連續 3 次檢查出局	
,此 proxy 會被摘除health_check_max_failed = 3# 每隔 10 秒鋪開一次健康檢查health_check_interval_s = 10
# frpc.ini[test1]type = tcplocal_port = 22remote_port = 6000# 啟用健康檢查 ,類型為 tcphealth_check_type = tcp# 建立接合超時時間為 3 秒health_check_timeout_s = 3# 連續 3 次檢查出局,此 proxy 會被摘除health_check_max_failed = 3# 每隔 10 秒鋪開一次健康檢查health_check_interval_s = 10

http 示例配置如下 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-comment"># 啟用健康檢查 ,類型為 http
<span class="hljs-attr">health_check_type</span> = http
<span class="hljs-comment"># 健康檢查發送 http 請求的 url ,後端服務需要返回 2xx 的 http 狀態碼
<span class="hljs-attr">health_check_url</span> = /status
<span class="hljs-attr">health_check_interval_s</span> = <span class="hljs-number">10</span>
<span class="hljs-attr">health_check_max_failed</span> = <span class="hljs-number">3</span>
<span class="hljs-attr">health_check_timeout_s</span> = <span class="hljs-number">3</span>
# frpc.ini[web]type = httplocal_ip = 127.0.0.1local_port = 80custom_domains = test.yourdomain.com# 啟用健康檢查,類型為 httphealth_check_type = http# 健康檢查發送 http 請求的 url,後端服務需要返回 2xx 的 http 狀態碼health_check_url = /statushealth_check_interval_s = 10health_check_max_failed = 3health_check_timeout_s = 3
# frpc.ini[web]type = httplocal_ip = 127.0.0.1local_port = 80custom_domains = test.yourdomain.com# 啟用健康檢查 ,類型為 httphealth_check_type = http# 健康檢查發送 http 請求的 url,後端服務需要返回 2xx 的 http 狀態碼health_check_url = /statushealth_check_interval_s = 10health_check_max_failed = 3health_check_timeout_s = 3

修改 Host Header

通常情況下 frp 不會修改轉發的任何數據。但有一些後端服務會根據 http 請求 header 中的 host 字段來展現不同的網站 ,例如 nginx 的虛擬主機服務 ,啟用 host-header 的修改功能可以動態修改 http 請求中的 host 字段 。該功能僅限於 http 類型的代理。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-attr">host_header_rewrite</span> = dev.yourdomain.com
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhost_header_rewrite = dev.yourdomain.com
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhost_header_rewrite = dev.yourdomain.com

原來 http 請求中的 host 字段 test.yourdomain.com 轉發到後端服務時會被替換為 dev.yourdomain.com。

設置 HTTP 請求的 header

對於 type = http 的代理  ,可以設置在轉發中動態增補的 header 參數 。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-attr">host_header_rewrite</span> = dev.yourdomain.com
<span class="hljs-attr">header_X-From-Where</span> = frp
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhost_header_rewrite = dev.yourdomain.comheader_X-From-Where = frp
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhost_header_rewrite = dev.yourdomain.comheader_X-From-Where = frp

對於參數配置中所有以 header_ 開頭的參數(擁穿著同時配置多個),城市被增補到 http 請求的 header 中,根據如上的配置 ,會在請求的 header 中加上 X-From-Where: frp。

得到用戶真實 IP

HTTP X-Forwarded-For
目前隻有 http 類型的代理擁穿著這一功能 ,可以通過用戶請求的 header 中的 X-Forwarded-For 來得到用戶真實 IP,默認啟用。

Proxy Protocol

frp 擁穿著通過 Proxy Protocol 協議來傳遞經過 frp 代理的請求的真實 IP ,此功能擁穿著所有以 TCP 為底層協議的類型 ,不擁穿著 UDP 。

Proxy Protocol 功能啟用後,frpc 在和本地服務建立接合後 ,會先發送一段 Proxy Protocol 的協議內容給本地服務 ,本地服務通過解析這一內容可以得到訪問用戶的真實 IP 。所以不僅僅是 HTTP 服務,任何的 TCP 服務,隻要擁穿著這一協議,都可以得到用戶的真實 IP 地址。

需要注意的是,在代理配置中如果要啟用此功能 ,需要本地的服務能夠擁穿著 Proxy Protocol 這一協議,目前 nginx 和 haproxy 都能夠很好的擁穿著 。

這裏以 https 類型為例:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = https
<span class="hljs-attr">local_port</span> = <span class="hljs-number">443</span>
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-comment"># 目前擁穿著 v1 和 v2 兩個版本的 proxy protocol 協議。
<span class="hljs-attr">proxy_protocol_version</span> = v2
# frpc.ini[web]type = httpslocal_port = 443custom_domains = test.yourdomain.com# 目前擁穿著 v1 和 v2 兩個版本的 proxy protocol 協議。proxy_protocol_version = v2
# frpc.ini[web]type = httpslocal_port = 443custom_domains = test.yourdomain.com# 目前擁穿著 v1 和 v2 兩個版本的 proxy protocol 協議 。proxy_protocol_version = v2

隻需要在代理配置中增補一行 proxy_protocol_version = v2 即可打開此功能。

本地的 https 服務可以通過在 nginx 的配置中啟用 Proxy Protocol 的解析並將結果設置在 X-Real-IP 這個 Header 中就可以在自己的 Web 服務中通過 X-Real-IP 得到到用戶的真實 IP。

通過密碼駐防你的 web 服務

由於所有客戶端共用一個 frps 的 http 服務端口,任何知道你的域名和 url 的人都能訪問到你部署在內網的 web 服務,但是在某些場景下需要確保隻有限定的用戶才能訪問 。

frp 擁穿著通過 HTTP Basic Auth 來駐防你的 web 服務,使用戶需要通過用戶名和密碼才能訪問到你的服務。

該功能目前僅限於 http 類型的代理,需要在 frpc 的代理配置中增補用戶名和密碼的設置  。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = test.yourdomain.com
<span class="hljs-attr">http_user</span> = abc
<span class="hljs-attr">http_pwd</span> = abc
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhttp_user = abchttp_pwd = abc
# frpc.ini[web]type = httplocal_port = 80custom_domains = test.yourdomain.comhttp_user = abchttp_pwd = abc

通過校驗器訪問 http://test.yourdomain.com ,需要輸入配置的用戶名和密碼才能訪問。

自定義二級域名

在多人同時使用一個 frps 時,通過自定義二級域名的方式來使用會更加方便 。

通過在 frps 的配置文件中配置 subdomain_host,就可以啟用該特性 。之後在 frpc 的 http、https 類型的代理中可以不配置 custom_domains  ,而是配置一個 subdomain 參數。

隻需要將 *.{subdomain_host} 解析到 frps 所在服務器 。之後用戶可以通過 subdomain 自行指定自己的 web 服務所需要使用的二級域名,通過 {subdomain}.{subdomain_host} 來訪問自己的 web 服務。

<span class="hljs-comment"># frps.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">subdomain_host</span> = frps.com
# frps.ini[common]subdomain_host = frps.com
# frps.ini[common]subdomain_host = frps.com

將泛域名 *.frps.com 解析到 frps 所在服務器的 IP 地址。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">subdomain</span> = test
# frpc.ini[web]type = httplocal_port = 80subdomain = test
# frpc.ini[web]type = httplocal_port = 80subdomain = test

frps 和 frpc 都打開大捷後 ,通過 test.frps.com 就可以訪問到內網的 web 服務  。

注 :如果 frps 配置了 subdomain_host ,則 custom_domains 中不能是屬於 subdomain_host 的子域名或者泛域名。

同一個 http 或 https 類型的代理中 custom_domains 和 subdomain 可以同時配置 。

URL 路由

frp 擁穿著根據請求的 URL 路徑路由轉發到不同的後端服務。

通過配置文件中的 locations 字段指定一個或多個 proxy 能夠匹配的 URL 前綴(目前僅擁穿著最大前綴匹配  ,之後會思索正則匹配) 。例如指定 locations = /news,則所有 URL 以 /news 開頭的請求城市被轉發到這個服務 。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[web01]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">80</span>
<span class="hljs-attr">custom_domains</span> = web.yourdomain.com
<span class="hljs-attr">locations</span> = /
<span class="hljs-section">
[web02]</span>
<span class="hljs-attr">type</span> = http
<span class="hljs-attr">local_port</span> = <span class="hljs-number">81</span>
<span class="hljs-attr">custom_domains</span> = web.yourdomain.com
<span class="hljs-attr">locations</span> = /news,/about
# frpc.ini[web01]type = httplocal_port = 80custom_domains = web.yourdomain.comlocations = /[web02]type = httplocal_port = 81custom_domains = web.yourdomain.comlocations = /news,/about
# frpc.ini[web01]type = httplocal_port = 80custom_domains = web.yourdomain.comlocations = /[web02]type = httplocal_port = 81custom_domains = web.yourdomain.comlocations = /news,/about

按照上述的示例配置後 ,web.yourdomain.com 這個域名下所有以 /news 以及 /about 作為前綴的 URL 請求城市被轉發到 web02,其餘的請求會被轉發到 web01。

通過代理接合 frps

在隻能通過代理訪問外網的環境內,frpc 擁穿著通過 HTTP PROXY 和 frps 鋪開通信。

可以通過設置 HTTP_PROXY 係統環境變量或者通過在 frpc 的配置文件中設置 http_proxy 參數來使用此功能。

僅在 protocol = tcp 時生效 。

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[common]</span>
<span class="hljs-attr">server_addr</span> = x.x.x.x
<span class="hljs-attr">server_port</span> = <span class="hljs-number">7000</span>
<span class="hljs-attr">http_proxy</span> = http://user:pwd@192.168.1.128:8080
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000http_proxy = http://user:pwd@192.168.1.128:8080
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000http_proxy = http://user:pwd@192.168.1.128:8080

範圍端口映射

在 frpc 的配置文件中可以指定映射多個端口,目前隻擁穿著 tcp 和 udp 的類型 。

這一功能通過 range: 段落標記來實現 ,客戶端會解析這個標記中的配置 ,將其拆分成多個 proxy ,每一個 proxy 以數字為後綴命名。

例如要映射本地 6000-6005, 6007 這6個端口 ,主要配置如下 :

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[range:test_tcp]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">local_ip</span> = <span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>
<span class="hljs-attr">local_port</span> = <span class="hljs-number">6000</span>-<span class="hljs-number">6006</span>,<span class="hljs-number">6007</span>
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>-<span class="hljs-number">6006</span>,<span class="hljs-number">6007</span>
# frpc.ini[range:test_tcp]type = tcplocal_ip = 127.0.0.1local_port = 6000-6006,6007remote_port = 6000-6006,6007
# frpc.ini[range:test_tcp]type = tcplocal_ip = 127.0.0.1local_port = 6000-6006,6007remote_port = 6000-6006,6007

實際接合大捷後會創建 8 個 proxy ,命名為 test_tcp_0, test_tcp_1 ... test_tcp_7 。

插件

默認情況下,frpc 隻會轉發請求到本地 tcp 或 udp 端口。

插件模式是為了在客戶端提供更加豐碩的功能,目前內置的插件有 unix_domain_socket 、http_proxy 、socks5 、static_file 。具體使用方式請查校驗使用示例 。

通過 plugin 指定需要使用的插件,插件的配置參數都以 plugin_ 開頭。使用插件後 local_ip 和 local_port 不再需要配置。

使用 http_proxy 插件的示例:

<span class="hljs-comment"># frpc.ini
<span class="hljs-section">[http_proxy]</span>
<span class="hljs-attr">type</span> = tcp
<span class="hljs-attr">remote_port</span> = <span class="hljs-number">6000</span>
<span class="hljs-attr">plugin</span> = http_proxy
<span class="hljs-attr">plugin_http_user</span> = abc
<span class="hljs-attr">plugin_http_passwd</span> = abc
# frpc.ini[http_proxy]type = tcpremote_port = 6000plugin = http_proxyplugin_http_user = abcplugin_http_passwd = abc
# frpc.ini[http_proxy]type = tcpremote_port = 6000plugin = http_proxyplugin_http_user = abcplugin_http_passwd = abc

plugin_http_user 和 plugin_http_passwd 即為 http_proxy 插件可選的配置參數 。

內容校驗完了

访客,请您发表评论:

© 2026. sitemap