十分钟快速搭建内网穿透工具 —— frp

时间:2022-07-28
本文章向大家介绍十分钟快速搭建内网穿透工具 —— frp,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

# 简介

  • frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcpudphttphttpsstcp 协议。
  • frp 需要服务端和客户端共同作用,服务端为 frps,一般安装在 vps 服务器上;客户端为 frpc,一般安装在路由器或 NAS 上。
  • frpsfrpc 配置使用,可以远程访问或控制内网设备。

# frps 一键安装

为了节省精力,这里使用 clangcn 的一键安装脚本

支持的平台:

  • Centos 6/7 32/64bit
  • Debian 6/7 32/64bit
  • Ubuntu 14 32/64bit

# 安装

下载脚本

$ wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh

1

修改权限

$ chmod 700 ./install-frps.sh

1

开始安装

$ ./install-frps.sh install

1

安装过程选项的说明

选项

说明

默认

download_url

frp 镜像源下载地址

aliyun

bind_port

frp 提供服务的端口

5443

vhost_http_port

http 服务端口

80

vhost_https_port

https 服务端口

443

dashboard_port

frps 仪表盘端口,用于查看 frp 工作状态

6443

dashboard_user

仪表盘登录账号

admin

dashboard_pwd

仪表盘登录密码

随机

token

frps 和 frpc 通讯密码

随机

max_pool_count

每个代理的连接上线

50

log_level

日志等级

info

log_max_days

日志保留天数

3

log_file

是否开启日志

enable

tcp_mux

是否开启多路复用,减少 tcp 的握手延迟

enable

kcp support

是否开启 kcp

enable

注意设置安全组或者防火墙

# 功能命令

命令

说明

frps start

启动

frps stop

停止

frps restart

重启

frps status

当前服务状态

frps config

vi 编辑配置

frps version

查看版本

install-frps.sh update

更新脚本

install-frps.sh uninstall

卸载

# fprc 配置

客户端以 Windows 系统为例,路由器或者 NAS 的对照参考即可

# 下载

在这里 frp 下载对应 frps 的版本

下载后只需要这三个文件即可

  • frpc.exe
  • frpc.ini
  • frpc_full.ini

# 配置

修改 frpc.ini 文件

[common]
server_addr = xxxxxx    # 服务器 IP
server_port = 5443      # bind_port
token = xxxxxx          # 与服务器一致

[test]
type = http             # 类型
local_ip = 127.0.0.1    # 本地 IP
local_port = 80         # 本地端口
use_encryption = true   # 传输加密
use_gzip = true         # gzip 压缩
custom_domains = xxxxxx # 自定义域名
http_user = xxxxxx      # 可选,访问账号
http_pwd = xxxxxx       # 可选,访问密码

[test2]
type =
local_ip =
local_port =
use_encryption =
use_gzip =
custom_domains =
http_user =
http_pwd =

log_file = /dev/null
log_level = info
log_max_days = 3

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

# 启动

打开 cmd,运行 frpc.exe 即可

# Nginx 端口转发

80 端口被 Nginx 占用的情况下,利用 Nginx 进行端口转发

这里 7080frpshttp 服务端口

添加站点文件 test.conf,内容如下:

server
    {
        listen 80;
        server_name www.cnguu.cn;
        location / {
            proxy_pass http://127.0.0.1:7080;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        access_log off;
        error_log /dev/null;
    }

1 2 3 4 5 6 7 8 9 10 11 12 13 14