免费快速实现内网穿透:windows远程桌面连接实战
sinye56 2024-12-31 14:29 10 浏览 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远程桌面连接,后续会介绍其他内容,欢迎关注我,不错过,不迷路。
(完)
- 上一篇:一款免费的远程控制工具:GotoHTTP
- 下一篇:原来连接Linux,还有这个方法
相关推荐
- CTO偷偷传我的系统性能优化十大绝招(万字干货)
-
上篇引言:取与舍软件设计开发某种意义上是“取”与“舍”的艺术。关于性能方面,就像建筑设计成抗震9度需要额外的成本一样,高性能软件系统也意味着更高的实现成本,有时候与其他质量属性甚至会冲突,比如安全性、...
- 提升效率!VMware虚拟机性能优化十大实用技巧
-
我40岁,干跨境婚恋中介的。为服务各国用户,常得弄英语、日语、俄语系统环境,VMware虚拟机帮了不少忙。用久了发现优化下性能,效率能更高。今儿就来聊聊优化技巧和同类软件。一、VMware虚拟...
- 低延迟场景下的性能优化实践
-
本文摘录自「全球C++及系统软件技术大会」ScottMeyers曾说到过,如果你不在乎性能,为什么要在C++这里,而不去隔壁的Pythonroom呢?今天我们就从“低延迟的概述”、“低延迟系...
- Linux性能调优之内存负载调优的一些笔记
-
写在前面整理一些Linux内存调优的笔记,分享给小伙伴博文没有涉及的Demo,理论方法偏多,可以用作内存调优入门博文内容涉及:Linux内存管理的基本理论寻找内存泄露的进程内存交换空间调优不同方式的...
- 优化性能套路:带你战胜这只后段程序员的拦路虎
-
来源|极客时间《卖桃者说》作者|池建强编辑|成敏你好,这里是卖桃者说。今天给大家推荐一篇文章,来自倪朋飞老师的专栏《Linux性能优化实战》,文章主要讲的是优化性能的套路,这几乎是每个后端程序员...
- SK海力士CXL优化解决方案已成功搭载于Linux:带宽提升30%,性能提升12%以上
-
SK海力士宣布,已将用于优化CXL(ComputeExpressLink)存储器运行的自研软件异构存储器软件开发套件(HMSDK)中主要功能成功搭载于全球最大的开源操作系统Linux上,不但提升了...
- Linux内核优化:提升系统性能的秘诀
-
Linux内核优化:提升系统性能的艺术在深入Linux内核优化的世界之前,让我们先来理解一下内核优化的重要性。Linux内核是操作系统的核心,负责管理系统资源和控制硬件。一个经过精心优化的内核可以显著...
- Linux系统性能优化:七个实战经验
-
Linux系统的性能是指操作系统完成任务的有效性、稳定性和响应速度。Linux系统管理员可能经常会遇到系统不稳定、响应速度慢等问题,例如在Linux上搭建了一个web服务,经常出现网页无法打开、打开速...
- 腾讯面试:linux内存性能优化总结
-
【1】内存映射Linux内核给每个进程都提供了一个独立且连续的虚拟地址空间,以便进程可以方便地访问虚拟内存;虚拟地址空间的内部又被分为内核空间和用户空间两部分,不同字长的处理器,地址空间的范围也不同...
- Linux文件系统性能调优《参数优化详解》
-
由于各种的I/O负载情形各异,Linux系统中文件系统的缺省配置一般来说都比较中庸,强调普遍适用性。然而在特定应用下,这种配置往往在I/O性能方面不能达到最优。因此,如果应用对I/O性能要求较高,除...
- Nginx 性能优化(吐血总结)
-
一、性能优化考虑点当我需要进行性能优化时,说明我们服务器无法满足日益增长的业务。性能优化是一个比较大的课题,需要从以下几个方面进行探讨当前系统结构瓶颈了解业务模式性能与安全1、当前系统结构瓶颈首先需要...
- Linux问题分析与性能优化
-
排查顺序整体情况:top/htop/atop命令查看进程/线程、CPU、内存使用情况,CPU使用情况;dstat2查看CPU、磁盘IO、网络IO、换页、中断、切换,系统I/O状态;vmstat2查...
- 大神级产品:手机装 Linux 运行 Docker 如此简单
-
本内容来源于@什么值得买APP,观点仅代表作者本人|作者:灵昱Termux作为一个强大的Android终端模拟器,能够运行多种Linux环境。然而,直接在Termux上运行Docker并不可行,需要...
- 新手必须掌握的Linux命令
-
Shell就是终端程序的统称,它充当了人与内核(硬件)之间的翻译官,用户把一些命令“告诉”终端程序,它就会调用相应的程序服务去完成某些工作。现在包括红帽系统在内的许多主流Linux系统默认使用的终端是...
- Linux 系统常用的 30 个系统环境变量全解析
-
在Linux系统中,环境变量起着至关重要的作用,它们犹如隐藏在系统背后的“魔法指令”,掌控着诸多程序的运行路径、配置信息等关键要素。尤其在shell脚本编写时,巧妙运用环境变量,能让脚本如虎...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- oracle忘记用户名密码 (59)
- oracle11gr2安装教程 (55)
- mybatis调用oracle存储过程 (67)
- oracle spool的用法 (57)
- oracle asm 磁盘管理 (67)
- 前端 设计模式 (64)
- 前端面试vue (56)
- linux格式化 (55)
- linux图形界面 (62)
- linux文件压缩 (75)
- Linux设置权限 (53)
- linux服务器配置 (62)
- mysql安装linux (71)
- linux启动命令 (59)
- 查看linux磁盘 (72)
- linux用户组 (74)
- linux多线程 (70)
- linux设备驱动 (53)
- linux自启动 (59)
- linux网络命令 (55)
- linux传文件 (60)
- linux打包文件 (58)
- linux查看数据库 (61)
- linux获取ip (64)
- linux进程通信 (63)