使用 frp 实现 Windows 远程桌面连接教程

一、frp 介绍

项目地址:https://github.com/fatedier/frp

FRP (Fast Reverse Proxy) 是一个可用于内网穿透的高性能的反向代理应用,支持 TCP , UDP , HTTP , HTTPS 协议,可以实现 Windows 远程桌面搭建。

使用体验:搭建好了 frp,用了下远程桌面,发现速度比 AnyDesk 快不少,跟 TeamViewer 差不多,TeamViewer 最近商业化查的越来越严了,明明是自用,也会提醒你商业使用,所以搭建一个 frp 服务器作为替代(备用)还是很有必要的。

二、准备工作

需要:

  • 一个有公网 IP 的 VPS 服务器

如果你需要连接的服务器在国内,那么直接选择阿里云或者腾讯云都行,现在轻量应用服务器价格都非常便宜,学生的话更是几十块钱 / 年就能买到 5M 带宽的轻量,用来做远程连接完全够了。

学生优惠:

  • 腾讯云学生:https://cloud.tencent.com/act/campus
  • 阿里云学生:https://developer.aliyun.com/plan/grow-up

其他优惠:

  • 腾讯云秒杀:https://cloud.tencent.com
  • 阿里云云小站:https://www.aliyun.com/minisite/goods

三、frp 服务器端搭建

下载地址:https://github.com/fatedier/frp/releases

一般服务器都是 Linux 系统的,目前最新版本是 0.36.2,直接下载对应的版本:
wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz

解压:

tar -zxvf frp_0.36.2_linux_amd64.tar.gz
至此,你会得到一个frp_0.36.2_linux_amd64 的文件夹,进入文件夹:

cd frp_0.36.2_linux_amd64

作为服务器端,你只需要关心 2 个文件:

  • frps
  • frps.ini
    其中 frps 是运行程序,frps.ini 是配置文件。

修改 frps.ini :

vi frps.ini
文件内容如下:

bind_port = 7000
dashboard_port = 7500
token = token
dashboard_user = user
dashboard_pwd = pwd

这里主要是配置了绑定的端口(7000),控制面板的端口(7500),token(会在客户端用到),控制面板的 user 用户名和 pwd 密码。

运行 frp 客户端:
./frps -c frps.ini

如果没有问题的话,就会直接运行成功了:
frps started successfully
通过(http://152.67..:7500)可以访问控制面板了。

可以借助 nohup 后台运行 frps,命令如下:
nohup ./frps -c frps.ini > /root/frp/log.log 2>&1 &

通过systemcl设置开机自启动
将frps注册为系统服务

[root@frp_server ~]# vim /usr/lib/systemd/system/frps.service
[Unit]
Description=frp server
After=network.target

[Service]
Type=simple

ExecStart=/usr/local/frp_server/frps -c /usr/local/frp_server/frps.ini
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target
[root@frp_server ~]# systemctl enable frps
[root@frp_server ~]# systemctl start  frps.service
[root@frp_server ~]# systemctl status frps
 frps.service - frp server
   Loaded: loaded (/usr/lib/systemd/system/frps.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-09-25 17:47:44 CST; 20s ago
 Main PID: 4168 (frps)
   CGroup: /system.slice/frps.service
           └─4168 /usr/local/frp_server/frps -c /usr/local/frp_server/frps.ini

Sep 25 17:47:44 frp_server systemd[1]: Started frp server.
Sep 25 17:47:44 frp_server systemd[1]: Starting frp server...

四、frp 客户端配置

下载地址:https://github.com/fatedier/frp/releases

同样是下载 releases,以 Windows 为例,下载与服务器端对应版本的 frp_0.36.2_windows_amd64.zip。

作为客户端端,你只需要关心 2 个文件:

  • frpc
  • frpc.ini
    编辑 frpc.ini文件,加入如下内容:
server_addr = 152.67.*.*
server_port = 7000
token = token
[rdp]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 7001
[smb]
type = tcp
local_ip = 127.0.0.1
local_port = 445
remote_port = 7002

“server_addr”是服务端 IP 地址,填入即可,“server_port”为服务器端口,即 bind_port 的值,“token”是你在服务器上设置的连接口令。

这里用到了 2 个自定义规则,一个是 rdp,一个是 smb:

  • RDP,即 Remote Desktop 远程桌面,Windows 的 RDP 默认端口是 3389,协议为 TCP,本条规则可以实现远程桌面连接。
  • SMB,即 Windows 文件共享所使用的协议,默认端口号 445,协议 TCP,本条规则可实现远程文件访问。
    打开 cmd,进入 frp 的目录,执行如下命令运行 frp 客户端(不能双击 frpc.exe):
    frpc -c frpc.ini
    结果如下所示:
2021/07/06 08:40:09 [I] [service.go:304] [bb69e2195d1e242d] login to server success, get run id [bb69e2195d1e242d], server udp port [0]
2021/07/06 08:40:09 [I] [proxy_manager.go:144] [bb69e2195d1e242d] proxy added: [rdp smb ssh]
2021/07/06 08:40:09 [I] [control.go:180] [bb69e2195d1e242d] [rdp] start proxy success
2021/07/06 08:40:09 [I] [control.go:180] [bb69e2195d1e242d] [smb] start proxy success
2021/07/06 08:40:09 [I] [control.go:180] [bb69e2195d1e242d] [ssh] start proxy success

之后开启 Windows 远程访问:Windows 开启远程访问,直接直接在本地远程连接即可,地址就是 152.67..:7001 (服务器 IP 和绑定的端口),之后输入用户名和密码就能成功远程了。

所有评论(3)

  1. 111说道:

    This message is used to verify that this feed (feedId:73642078670399488) belongs to me (userId:73641743010498560). Join me in enjoying the next generation information browser https://follow.is.

  2. View More说道:

    First off I want to say superb blog! I had a quick question that I’d
    like to ask if you do not mind. I was interested to know how you center yourself and clear your mind before writing.
    I have had difficulty clearing my mind in getting my
    ideas out. I do enjoy writing but it just seems like
    the first 10 to 15 minutes are generally wasted simply just trying to figure out how to begin. Any suggestions or hints?
    Appreciate it!

  3. More information说道:

    Good day! I know this is somewhat off topic but I was wondering which blog platform
    are you using for this site? I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform.
    I would be awesome if you could point me in the direction of a good platform.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注