说明:Frp估计很多人都用过,一个高性能的内网穿透工具,支持tcp、udp、http、https协议,安装和使用教程可以直接查看官方中文文档→传送门,写的超详细。这里博主分享个某大佬写的Frps一键脚本,包括Frpc Windows便捷脚本,使用起来很方便,想快速上手的可以用下。
请输入图片描述

1、FRP可以做什么?

很多情况下处于NAT网络环境中没有公网IP,这个时候可疑通过FRP服务器的转发进行内网穿透。frp内网穿透服务器搭建和frp使用方法。
本教程是使用TCP模式(连接内网Windows的远程桌面),frp客户端和frp服务端以Windows服务的方式在后台默默运行,还可以使用UDP、HTTP、HTTPS模式。

2、为什么不再使用ngork

ngork2.0不再开源

3、Linux服务端安装

系统要求:CentOS 7+、Debian 8+
使用命令:

wget -N --no-check-certificate git.io/f.sh && chmod +x f.sh && bash f.sh install

3.1、常用命令

#一键修改token
bash f.sh token
    
#一键修改bind_port
bash f.sh bind_port
    
#一键修改vhost_http_port
bash f.sh vhost_http_port
    
#一键修改vhost_https_port
bash f.sh vhost_https_port

3.2、备用命令

#一键修改dashboard_port
bash f.sh dashboard_port

#一键修改dashboard_user
bash f.sh dashboard_user

#一键修改dashboard_pwd
bash f.sh dashboard_pwd

#一键修改bind_udp_port
bash f.sh bind_udp_port

#一键修改kcp_bind_port
bash f.sh kcp_bind_port

#一键修改subdomain_host(用于泛解析子域名)
bash f.sh subdomain_host

#一键卸载frps
bash f.sh uninstall

3.3、注意事项

#一键关闭 apache2、防火墙,释放80端口
bash f.sh unapache2

#注意,除http(s)以外,客户端frpc.ini内任何端口修改时须在以下范围内:
默认端口白名单:2000-3000,3001,3003,4000-50000

#转发远程桌面时,需先在本机开启允许远程协助
我的电脑-右键属性-远程设置

#需要注意frpc所在机器和frps所在机器的时间相差不能超过15分钟

4、Windows服务端安装

Github地址:https://github.com/dylanbai8/frpspro/releases
https://github.com/fatedier/frp/releases
https://github.com/fatedier/frp/releases/download/v0.13.0/frp_0.13.0_windows_amd64.zip

5、frp服务端配置文件

frps.ini

    # [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.0 bind_port = 5443
    # udp port used for kcp protocol, it can be same with ‘bind_port’
    # if not set, kcp is disabled in frps kcp_bind_port = 5443
    # if you want to configure or reload frps by dashboard, dashboard_port must be set dashboard_port = 6443
    # dashboard assets directory(only for debug mode) dashboard_user = 用户 dashboard_pwd = 密码
    # assets_dir = ./static
    
    vhost_http_port = 8080 vhost_https_port = 4443
    # console or real logFile path like ./frps.log log_file = ./frps.log
    # debug, info, warn, error log_level = info log_max_days = 30
    # privilege mode is the only supported mode since v0.10.0 privilege_token = hLzzySjVo1kMJgaz
    # only allow frpc to bind ports you list, if you set nothing, there won’t be any limit
    #privilege_allow_ports = 1-65535
    # pool_count in each proxy will change to max_pool_count if they exceed the maximum value max_pool_count = 50
    # if tcp stream multiplexing is used, default is true tcp_mux = true

启动服务器

frps.exe -c frps.ini

6、客户端配置文件

frps.ini

[common]
server_addr = 122.114.xx.xx
server_port = 5443
log_file = ./frpc.log
log_level = info
log_max_days = 30
privilege_token = hLzzySjVo1kMJgaz
pool_count = 50
tcp_mux = true
user = 用户
login_fail_exit = true
protocol = tcp
[tcp_mode]
privilege_mode = true
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 23689
custom_domains = a.zhangfangzhou.cn

启动客户端

frpc.exe -c frpc.ini

7、Windows快速添加通过防火墙规则

netsh advfirewall firewall add rule name=”Open Port 5443″ dir=in action=allow protocol=TCP localport=5443
netsh advfirewall firewall add rule name=”Open Port 5443″ dir=in action=allow protocol=TCP localport=6443
netsh advfirewall firewall add rule name=”Open Port 4443″ dir=in action=allow protocol=TCP localport=4443
netsh advfirewall firewall add rule name=”Open Port 23689″ dir=in action=allow protocol=TCP localport=23689
netsh advfirewall firewall add rule name=”Open Port 8080″ dir=in action=allow protocol=TCP localport=8080

8、Windows 设置后台运行

创建一个frpc.cmd

frpc.cmd
cd
cd frp
frpc.exe -c frpc.ini

创建一个frpc.vbs,用于在后台执行frpc

frpc.vbs
Set ws = CreateObject(“Wscript.Shell”)
ws.run “cmd /c frpc”,vbhide

frpc客户端 frps服务端 创建步骤一样
这样能开机后台运行

9、Windows 设置开机启动

运行框输入下面代码,添加启动项

%programdata%MicrosoftWindowsStart MenuProgramsStartup

10、验证登录远程桌面

122.114.xx.xx:23689

11.注意事项

每次启动frp客户端后需要等待一段时间服务器才能连接正常,请耐心等待30秒

自用frpc.ini配置

#运行方法:
#FRP目录下打开CMD窗口执行:
#frpc.exe -c frpc.ini
# [common] 服务器链接信息
[common]
server_addr = 192.168.1.1
server_port = 7000
token = 12345678

# 日志文件 ./frpc.log
log_file = ./frpc.log
#可记录 trace, debug, info, warn, error
log_level = info
#存放天数
log_max_days = 3

# 通过http api设置管理地址以控制frpc的操作,例如重新加载
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = admin
admin_pwd = admin

# 连接将提前建立,默认值为0
pool_count = 5

# 如果使用多路复用tcp,则默认为true,它必须与frps服务器相同
tcp_mux = true

# 你的名称显示为 {user}.{proxy}
user = pcpc

# 第一次登录失败就退出程序,否则将持续尝试登陆 Frp 服务器
# default is true
login_fail_exit =default

# 用于连接服务器的通信协议
# 现在它支持tcp和kcp以及websocket,默认是tcp
protocol = tcp

#如果tls_enable为true,frpc将通过tls连接frps
tls_enable = true

# 穿透的端口配置
[gm2]
type = http
local_ip = 127.0.0.1
local_port = 80
use_encryption = true
use_compression = true
#http用户名和密码是http协议的安全认证
#如果未设置,您可以在没有认证的情况下访问此custom_domains
#http_user = admin
#http_pwd = admin
# 子域名
# 如果名字为 [web01] 访问的地址就是 URL http://web01.frps.com
subdomain = web01
# 自定义域名
# 如果服务端配置了主域名(frps.com),则自定义域名不能是属于主域名(frps.com) 的子域名或者泛域名。
#custom_domains = web01.frps01.com
#frpc将向本地http服务发送GET http请求'/ status'
#http http服务返回2xx http响应代码时处于活动状态
health_check_url = /status
health_check_interval_s = 10
health_check_max_failed = 3
health_check_timeout_s = 3

自用frps.ini配置

# [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.0
bind_port = 7000

# udp port to help make udp hole to penetrate nat
bind_udp_port = 7001

# udp port used for kcp protocol, it can be same with 'bind_port'
# if not set, kcp is disabled in frps
kcp_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_port
vhost_http_port = 81
vhost_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_addr's default value is same with bind_addr
# dashboard is available only if dashboard_port is set
dashboard_addr = 0.0.0.0
dashboard_port = 7500

# dashboard user and passwd for basic auth protect, if not set, both default value is admin
dashboard_user = admin
dashboard_pwd = admin

# dashboard assets directory(only for debug mode)
# assets_dir = ./static
# console or real logFile path like ./frps.log
log_file = ./frps.log

# trace, debug, info, warn, error
log_level = info

log_max_days = 3

# auth token
token = 12345678

# heartbeat configure, it's 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 won't be any limit
allow_ports = 2000-3000,3001,3003,4000-50000

# pool_count in each proxy will change to max_pool_count if they exceed the maximum value
max_pool_count = 5

# max ports can be used for each client, default value is 0 means no limit
max_ports_per_client = 0

# if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file
# when subdomain is test, the host used by routing is test.frps.com
subdomain_host = frps.com

# if tcp stream multiplexing is used, default is true
tcp_mux = true

# custom 404 page for HTTP requests
# custom_404_page = /path/to/404.html