frp 是一款高性能的反向代理应用,专注于内网穿透。它支持多种协议,包括 TCP、UDP、HTTP、HTTPS 等,并且具备 P2P 通信功能。使用 frp,您可以安全、便捷地将内网服务暴露到公网,通过拥有公网 IP 的节点进行中转。

自建 frps 内网穿透服务,基于 ubuntu22.04 ,记录部署过程。

下载

Frp github 预编译发布地址:https://github.com/fatedier/frp/releases

根据服务器系统、cpu 架构下载合适版本

wget https://github.com/fatedier/frp/releases/download/v0.54.0/frp_0.54.0_linux_amd64.tar.gz

可选,使用https://down.66a.vip/

wget https://down.66a.vip/https://github.com/fatedier/frp/releases/download/v0.54.0/frp_0.54.0_linux_amd64.tar.gz

安装

  1. 解压

    tar -zvxf frp_0.54.0_linux_amd64.tar.gz
  2. 复制可执行文件到 /usr/bin/

    sudo cp frp_0.54.0_linux_amd64/frps /usr/bin/
  3. 配置 frps

    sudo mkdir -p /etc/frp

    创建 /etc/frp/frps.toml 文件

    sudo vim /etc/frp/frps.toml

    按需填写如下内容

    bindAddr = "0.0.0.0"
    bindPort = 7000 # 绑定端口
    kcpBindPort = 7001 # kcp绑定端口,按使用需求可选配置
    quicBindPort = 7002 # quic绑定端口,按使用需求可选配置
    vhostHTTPPort = 8080 # 虚拟http端口,按使用需求可选配置
    vhostHTTPSPort = 8443 # 虚拟https端口,按使用需求可选配置
    
    # 允许穿透服务映射的远端服务器端口范围
    allowPorts = [ { start = 50000, end = 60000 } ]
    
    auth.method = "token"
    auth.token = "xxx" # 自定义授权token,客户端提供正确token才能穿透
    
    webServer.addr = "0.0.0.0"
    webServer.port = 7500
    # dashboard 用户名密码,可选,默认为空
    webServer.user = "xxx" # 修改此项
    webServer.password = "xxx" # 修改此项
  4. 添加到 systemd 服务

    新建 frps.service 文件

    sudo vim /lib/systemd/system/frps.service

    根据实际情况填写如下参考内容

    [Unit]
    # 服务名称,可自定义
    Description = frp server
    After = network.target syslog.target
    Wants = network.target
    
    [Service]
    Type = simple
    Restart=on-failure
    RestartSec=5s
    # 启动frps的命令,需修改为您的frps的安装路径
    ExecStart = /usr/bin/frps -c /etc/frp/frps.toml
    
    [Install]
    WantedBy = multi-user.target

    更新 systemd 服务列表

    sudo systemctl daemon-reload

    启动 frps 服务

    sudo systemctl start frps

    配置开机自启

    sudo systemctl enable frps

    查看 frps 运行状态

    sudo systemctl status frps

    至此,frps 服务端部署完成。