前言

一切基于 frp 官方 wiki

内网穿透哪家强?中国 xx 找 frp!(项目作者是国人哦~)

服务端部署

演示机为 Debian 11

  1. 下载二进制文件

    1
    2
    3
    4
    5
    6
    7
    8
    # 下载
    wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
    # 解压
    tar -zxvf frp_0.61.1_linux_amd64.tar.gz
    # 改名
    mv frp_0.61.1_linux_amd64.tar.gz frp && cd frp
    # 创建日志文件
    cd frp && touch log/frps.log
  2. 编辑服务端配置文件(Dashboard 和日志可以不配置)

    1
    nano frps.toml

    内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    bindPort = <自己想个五位端口>
    auth.method = "token"
    auth.token = "<自己生成一段字母 + 数字的多位 token>"
    # Web Dashboard 配置
    webServer.addr = "0.0.0.0"
    webServer.port = <自己想个五位端口>
    webServer.user = "<自己想个用户名>"
    webServer.password = "<自己想个密码>"
    # 日志配置
    log.to = "<上面创建的 frps.log 的绝对路径>"
    log.level = "info"
    log.maxDays = 3
  3. 生成 frp 服务

    1
    sudo nano /etc/systemd/system/frps.service

    内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [Unit]
    # 服务名称,可自定义
    Description = frps
    After = network.target syslog.target
    Wants = network.target

    [Service]
    Type = simple
    # 启动 frps 的命令,需修改为 frps 的安装路径
    ExecStart = < frps 文件的绝对路径> -c < frps.toml 文件的绝对路径>

    [Install]
    WantedBy = multi-user.target
  4. 启动服务并设置开机自启

    1
    2
    3
    systemctl daemon-reload
    systemctl start frps
    systemctl enable frps

客户端部署

跟服务端一模一样的,Windows 就随便找些带 GUI 的客户端,比如 frpmgr 之类的,群晖就套件或者 Docker,Linux 的正经发行版就按照上面的服务端一模一样部署,不过是把 frps 改成 frpc,下面展示 Linux 本机部署吧

  1. 下载二进制文件

    1
    2
    3
    4
    5
    6
    7
    8
    # 下载
    wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
    # 解压
    tar -zxvf frp_0.61.1_linux_amd64.tar.gz
    # 改名
    mv frp_0.61.1_linux_amd64.tar.gz frp && cd frp
    # 创建代理配置文件夹和日志文件
    cd frp && mkdir conf.d && touch log/frpc.log
  2. 编辑客户端配置文件(日志可以不配置)

    1
    nano frpc.toml

    内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    serverAddr = "<服务端 IP>"
    bindPort = <服务端设置的端口>
    auth.method = "token"
    auth.token = "<服务端设置的 token>"
    # 日志配置
    log.to = "<上面创建的 frpc.log 的绝对路径>"
    log.level = "info"
    log.maxDays = 3
    # 代理配置
    includes = ["./conf.d/*.toml"]
  3. 编辑代理配置

    比如我要穿透我本机的 8080 端口的 qBittorrent

    1
    nano ./conf.d/qb.toml

    内容如下

    1
    2
    3
    4
    5
    6
    [[proxies]]
    name = "qb"
    type = "tcp"
    localIP = "127.0.0.1"
    localPort = 8080
    remotePort = 12345 # 记得在服务端放行相应端口
  4. 生成 frp 服务

    1
    sudo nano /etc/systemd/system/frpc.service

    内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [Unit]
    # 服务名称,可自定义
    Description = frpc
    After = network.target syslog.target
    Wants = network.target

    [Service]
    Type = simple
    # 启动 frpc 的命令,需修改为 frpc 的安装路径
    ExecStart = < frpc 文件的绝对路径> -c < frpc.toml 文件的绝对路径>

    [Install]
    WantedBy = multi-user.target
  5. 启动服务并设置开机自启

    1
    2
    3
    systemctl daemon-reload
    systemctl start frpc
    systemctl enable frpc