免费快速实现内网穿透:windows远程桌面连接实战
ztj100 2025-05-02 14:52 32 浏览 0 评论
本次介绍使用 frp 实现内网穿透,文章是之前写的,写了很多篇,后续会一一整理出来,希望帮助到有需要的朋友。
frp简介
在某些时候,我们需要远程访问某个内网的资源或服务,但是内网设备通常是无法被外部访问的,内网穿透技术就是解决这种问题。
frp是开源的内网穿透工具,轻量、容易配置,而且支持多种协议(如 http、https、tcp、udp等),并且支持多种认证方式。
frp github 中文文档:
https://github.com/fatedier/frp/blob/master/README_zh.md
release 下载:
https://github.com/fatedier/frp/releases
注:服务器端和客户端下载的版本要保持一致。
本次下载的版本是【v0.31.2】:
https://github.com/fatedier/frp/releases/tag/v0.31.2
本次演示的是通过 frp 内网穿透,在远程连接一台windows电脑。
一、部署
frp由两部分组成:
- frps(服务器端):运行在具有公网 IP 的服务器上
- frpc(客户端):运行在内网设备上
本次部署的服务端是阿里云的一台 CentOS 云服务器,客户机就是本地一台 windows。
1.1 服务端部署
本次下载的文件是【
frp_0.31.2_linux_amd64.tar.gz】,frps.ini 是启动的配置文件:
[common]
bind_port = 7000
因为用到了服务器默认是 7000 端口,需要在防火墙中开启,如果是云服务器则只需要在安全组的入站方向增加一个端口即可。
由于下面客户端配置的端口是 6000 ,因此一起加上:
下载并运行服务端程序:
# 将文件上传到服务器
# 解压压缩包
tar -zxvf frp_0.31.2_linux_amd64.tar.gz
# 进入目录
cd frp_0.31.2_linux_amd64
# 设置后台运行frp服务端
nohup ./frps -c ./frps.ini &
或者输出到指定目录 nohup ./frps -c ./frps.ini > log/log_202212.log 2>&1 &
查看 nohub.out 日志:
[root@VM_0_7_centos frp_0.31.2_linux_amd64]# cat nohup.out
2020/03/24 22:48:05 [I] [service.go:152] frps tcp listen on 0.0.0.0:7000
2020/03/24 22:48:05 [I] [root.go:205] start frps success
[root@VM_0_7_centos frp_0.31.2_linux_amd64]#
说明服务端启动成功。
1.2 客户端部署
客户端是windows系统,本次下载的文件是【
frp_0.31.2_windows_386.zip】。
直接解压压缩包,修改 frpc.ini 文件:
[common]
server_addr = 111.X.X.34
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 6000
server_addr 是服务端 ip 地址。
进入解压的根目录,输入命令 frpc -c frpc.ini 启动客户端:
出现 start proxy success 说明启动成功。
windows开启远程桌面功能:
二、测试
找一台非局域网的电脑远程连接上面部署的windows电脑:
校验了用户名或密码错误,出现了这个说明连接到了,下面输入正确的用户名密码:
连接成功。
如有域名的话,可以将域名解析到这个公网服务器ip,然后通过【域名+端口】访问,这样方便记忆。
三、知识点
前面介绍的是基本使用,按照上面的步骤可以立马使用起来,但是缺乏安全性、便捷性等。
3.1 压缩包内文件介绍
压缩包有这个几个文件:
[root@iZbp1itnf4brss9ptmsq9fZ frp_0.31.2_linux_amd64]# ls
frpc frpc_full.ini frpc.ini frps frps_full.ini frps.ini LICENSE systemd
- 客户端使用:frpc frpc_full.ini frpc.inifrpc:命令frpc_full.ini:配置文件完整示例frpc.ini:配置文件
- 服务端使用:frps frps_full.ini frps.inifrps:命令frps_full.ini:配置文件完整示例frps.ini:配置文件
3.2 服务端
先看下配置文件完整示例 frps_full.ini 的内容:
[root@iZbp1itnf4brss9ptmsq9fZ frp_0.31.2_linux_amd64]# cat frps_full.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 = 80
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
# disable log colors when log_file is console, default is false
disable_log_color = false
# 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
[plugin.user-manager]
addr = 127.0.0.1:9000
path = /handler
ops = Login
[plugin.port-manager]
addr = 127.0.0.1:9001
path = /handler
ops = NewProxy
3.2.1 启用 dashboard
改成:
[common]
bind_port = 7000
bind_udp_port = 7001
kcp_bind_port = 7000
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
3.2.2安全认证
如果别人知道了你的服务器ip和端口,别人就能使用你的服务器做穿透了:
[common]
server_addr = 111.X.X.34
server_port = 7000
为了保证安全,需要服务端和客户端添加相同的认证 token。
服务端添加如下配置后重启:
# auth token
token = wankun666
重启 frps,然后查看端口,如下已经启动成功了,我添加了很多端口:
[root@iZbp1itnf4brss9ptmsq9fZ frp_0.31.2_linux_amd64]# netstat -lnpt|grep frps
tcp6 0 0 :::11522 :::* LISTEN 1909/./frps
tcp6 0 0 :::6022 :::* LISTEN 1909/./frps
tcp6 0 0 :::21672 :::* LISTEN 1909/./frps
tcp6 0 0 :::7433 :::* LISTEN 1909/./frps
tcp6 0 0 :::8181 :::* LISTEN 1909/./frps
tcp6 0 0 :::11672 :::* LISTEN 1909/./frps
tcp6 0 0 :::7000 :::* LISTEN 1909/./frps
tcp6 0 0 :::9306 :::* LISTEN 1909/./frps
tcp6 0 0 :::12379 :::* LISTEN 1909/./frps
[root@iZbp1itnf4brss9ptmsq9fZ frp_0.31.2_linux_amd64]# kill -9 1909
这个时候客户端会出现连接失败,查看最新日志,提示 authorization failed 认证失败:
[root@localhost frp_0.31.2_linux_amd64]# tail -10 nohup.out
2022/12/17 09:10:22 [W] [service.go:151] [ed52dcb97a69fd0b] reconnect to server error: authorization failed
2022/12/17 09:10:42 [I] [service.go:148] [ed52dcb97a69fd0b] try to reconnect to server...
2022/12/17 09:10:42 [E] [service.go:241] [ed52dcb97a69fd0b] authorization failed
2022/12/17 09:10:42 [W] [service.go:151] [ed52dcb97a69fd0b] reconnect to server error: authorization failed
2022/12/17 09:11:02 [I] [service.go:148] [ed52dcb97a69fd0b] try to reconnect to server...
2022/12/17 09:11:02 [E] [service.go:241] [ed52dcb97a69fd0b] authorization failed
2022/12/17 09:11:02 [W] [service.go:151] [ed52dcb97a69fd0b] reconnect to server error: authorization failed
2022/12/17 09:11:22 [I] [service.go:148] [ed52dcb97a69fd0b] try to reconnect to server...
2022/12/17 09:11:22 [E] [service.go:241] [ed52dcb97a69fd0b] authorization failed
2022/12/17 09:11:22 [W] [service.go:151] [ed52dcb97a69fd0b] reconnect to server error: authorization failed
...
服务端重新启动也会认证失败:
[root@localhost frp_0.31.2_linux_amd64]# ps -ef|grep frp
root 10861 5948 0 09:17 pts/0 00:00:00 grep --color=auto frp
root 20274 1 0 8月28 ? 00:37:05 ./frpc -c ./frpc.ini
[root@localhost frp_0.31.2_linux_amd64]# kill -9 20274
[root@localhost frp_0.31.2_linux_amd64]# ps -ef|grep frp
root 10947 5948 0 09:18 pts/0 00:00:00 grep --color=auto frp
[root@localhost frp_0.31.2_linux_amd64]# ./frpc -c frpc.ini
2022/12/17 09:19:56 [E] [service.go:241] authorization failed
2022/12/17 09:19:56 [W] [service.go:97] login to server failed: authorization failed
authorization failed
客户端再添加token配置,然后重启:
# auth token
token = wankun666!!
重启成功了:
[root@localhost frp_0.31.2_linux_amd64]# ./frpc -c frpc.ini
2022/12/17 09:22:25 [I] [service.go:250] [769ff70f636cb4ba] login to server success, get run id [769ff70f636cb4ba], server udp port [0]
2022/12/17 09:22:25 [I] [proxy_manager.go:144] [769ff70f636cb4ba] proxy added: [ssh redis12379 mssql7433 web11672 mysql9306 web8181 web11522 web21672]
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [web8181] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [mssql7433] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [web11672] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [mysql9306] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [ssh] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [web11522] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [web21672] start proxy success
2022/12/17 09:22:25 [I] [control.go:164] [769ff70f636cb4ba] [redis12379] start proxy success
由于当前窗口关闭之后,程序就结束了,最后使用命令让其后台运行 nohup ./frpc -c ./frpc.ini &。
总结
本次介绍了下载安装frp服务端和客户端,配置实现了windows远程桌面连接,后续会介绍其他内容,欢迎关注我,不错过,不迷路。
(完)
相关推荐
- Vue3非兼容变更——函数式组件(vue 兼容)
-
在Vue2.X中,函数式组件有两个主要应用场景:作为性能优化,因为它们的初始化速度比有状态组件快得多;返回多个根节点。然而在Vue3.X中,有状态组件的性能已经提高到可以忽略不计的程度。此外,有状态组...
- 利用vue.js进行组件化开发,一学就会(一)
-
组件原理/组成组件(Component)扩展HTML元素,封装可重用的代码,核心目标是为了可重用性高,减少重复性的开发。组件预先定义好行为的ViewModel类。代码按照template\styl...
- Vue3 新趋势:10 个最强 X 操作!(vue.3)
-
Vue3为前端开发带来了诸多革新,它不仅提升了性能,还提供了...
- 总结 Vue3 组件管理 12 种高级写法,灵活使用才能提高效率
-
SFC单文件组件顾名思义,就是一个.vue文件只写一个组件...
- 前端流行框架Vue3教程:17. _组件数据传递
-
_组件数据传递我们之前讲解过了组件之间的数据传递,...
- 前端流行框架Vue3教程:14. 组件传递Props效验
-
组件传递Props效验Vue组件可以更细致地声明对传入的props的校验要求...
- 前端流行框架Vue3教程:25. 组件保持存活
-
25.组件保持存活当使用...
- 5 个被低估的 Vue3 实战技巧,让你的项目性能提升 300%?
-
前端圈最近都在卷性能优化和工程化,你还在用老一套的Vue3开发方法?作为摸爬滚打多年的老前端,今天就把私藏的几个Vue3实战技巧分享出来,帮你在开发效率、代码质量和项目性能上实现弯道超车!一、...
- 绝望!Vue3 组件频繁崩溃?7 个硬核技巧让性能暴涨 400%!
-
前端的兄弟姐妹们五一假期快乐,谁还没在Vue3项目上栽过跟头?满心欢喜写好的组件,一到实际场景就频频崩溃,页面加载慢得像蜗牛,操作卡顿到让人想砸电脑。用户疯狂吐槽,领导脸色难看,自己改代码改到怀疑...
- 前端流行框架Vue3教程:15. 组件事件
-
组件事件在组件的模板表达式中,可以直接使用...
- Vue3,看这篇就够了(vue3 从入门到实战)
-
一、前言最近很多技术网站,讨论的最多的无非就是Vue3了,大多数都是CompositionAPI和基于Proxy的原理分析。但是今天想着跟大家聊聊,Vue3对于一个低代码平台的前端更深层次意味着什么...
- 前端流行框架Vue3教程:24.动态组件
-
24.动态组件有些场景会需要在两个组件间来回切换,比如Tab界面...
- 前端流行框架Vue3教程:12. 组件的注册方式
-
组件的注册方式一个Vue组件在使用前需要先被“注册”,这样Vue才能在渲染模板时找到其对应的实现。组件注册有两种方式:全局注册和局部注册...
- 焦虑!Vue3 组件频繁假死?6 个奇招让页面流畅度狂飙 500%!
-
前端圈的朋友们,谁还没在Vue3项目上踩过性能的坑?满心期待开发出的组件,一到高并发场景就频繁假死,用户反馈页面点不动,产品经理追着问进度,自己调试到心态炸裂!别以为这是个例,不少人在电商大促、数...
- 前端流行框架Vue3教程:26. 异步组件
-
根据上节课的代码,我们在切换到B组件的时候,发现并没有网络请求:异步组件:...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- idea eval reset (50)
- vue dispatch (70)
- update canceled (42)
- order by asc (53)
- spring gateway (67)
- 简单代码编程 贪吃蛇 (40)
- transforms.resize (33)
- redisson trylock (35)
- 卸载node (35)
- np.reshape (33)
- torch.arange (34)
- npm 源 (35)
- vue3 deep (35)
- win10 ssh (35)
- vue foreach (34)
- idea设置编码为utf8 (35)
- vue 数组添加元素 (34)
- std find (34)
- tablefield注解用途 (35)
- python str转json (34)
- java websocket客户端 (34)
- tensor.view (34)
- java jackson (34)
- vmware17pro最新密钥 (34)
- mysql单表最大数据量 (35)