FRP内网穿着透配置教程及配置分享_阴阳师辅助式神

FRP内网穿着透配置教程及配置分享_阴阳师辅助式神

  发布时间:2026-07-22 05:57:15   作者:玩站小弟   我要评论
FRP内网穿着透配置教程及配置分享_阴阳师辅助式神 前言随着全球IPv4地址耗尽,网穿新装电信宽带一般也只给分配内网IP,着透置分不开放外网I阴阳师科学计算...。

前言

随着全球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-07-22
  • 丫丫乐儿歌播放器 50 绿色版

    丫丫乐儿歌播放器是一款专门针对儿童精心打造的学习软件 。该软件操作更简单 、所有节目都可以全部循环播放或单曲循环播放 ,目前这款播放器在设计上采用主流软件设计概念,简单易用为特点,非常适合我们的宝宝学习独
    2026-07-22
  • 云顶之弈8星之守护者阵容怎么运营

    作为云顶星之守护者的忠实爱好者,很多朋友都喜欢粉色的颜色,但是很多人不知道怎么上分 ,让我们看看 !云顶之弈s8星之守护者阵容怎么玩1 :星之守护者是生成法力值的,但是这次是
    2026-07-22
  • Tuniac免费音乐播放器 11 最新版

    tuniac音乐播放器是款非常不错的无损音乐播放软件;它拥有传统音乐播放器的常见功能 ,并且也是款itunes风格的音乐播放器,主要就是支持所有主流的播放格式 ,而且软件还没有广告 ,插件等,使您不需要进行
    2026-07-22
  • 德国航空工程师吕迪格·科赫水下生活120天 ,创造新吉尼斯世界纪录

    快科技1月26日消息 ,近日,德国一名航空工程师吕迪格·科赫(Rüdiger Koch)在巴拿马海岸附近的水下胶囊里成功生活了120天,打破了“水下生活时间最长
    2026-07-22
  • openvideo(视频解析软件) 103 免费版

    openvideo是一款可以帮助你解析视频的软件 ,您可以通过本软件分析网络上的视频,提供强大的解析功能,立即对需要识别的视频分析 ,可以对视频播放 ,分析完毕可以立即在软件上查看内容,也提供下载功能,允许
    2026-07-22

最新评论