Windows使用VNC Viewer远程桌面Ubuntu(内网穿透)
<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>前言</li><li>1. ubuntu安装VNC</li><li>2. 设置vnc开机启动</li><li>3. windows 安装VNC viewer连接工具</li><li>4. 内网穿透<ul class="second_class_ul"><li>4.1 安装cpolar【支持使用一键脚本命令安装】</li><li>4.2 创建隧道映射</li><li>4.3 测试公网远程访问</li></ul></li><li>5. 配置固定TCP地址<ul class="second_class_ul"><li>5.1 保留一个固定的公网TCP端口地址</li><li>5.2 配置固定公网TCP端口地址</li><li>5.3 测试使用固定公网地址远程</li></ul></li><li>总结<ul class="second_class_ul"></ul></li><li>拓展:ubuntu开启黑屏现象解决<ul class="second_class_ul"><li>一、问题描述</li><li>二、解决方案</li><ul class="third_class_ul"><li>1. 检查显卡驱动</li><li>2. 修复 GRUB 配置</li><li>3. 使用恢复模式</li></ul><li>三、验证与总结</li><ul class="third_class_ul"></ul></ul></li></ul></div><p class="maodian"></p><h2>前言</h2><p>实现ubuntu 系统桌面级别的远程连接,需要在ubuntu 系统中安装vnc,既然是桌面,前提是需要ubuntu 带有图形化界面,如果没有,可以执行以下命令安装图形化界面</p>
<div class="dxycode"><pre class="brush:bash;">sudo apt install ubuntu-desktop
sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
sudo reboot #重启即可看到图形界面</pre></div>
<p class="maodian"></p><h2>1. ubuntu安装VNC</h2>
<p>在ubuntu中安装vnc</p>
<div class="dxycode"><pre class="brush:bash;">sudo apt-get install x11vnc</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="Image" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-2505221405402K.png" /></p>
<p>安装LightDM【LightDM从设计上就是支持本地图形界面以获得最好的兼容性】</p>
<div class="dxycode"><pre class="brush:bash;">sudo apt-get install lightdm</pre></div>
<p>安装过程中会出现以下选项,选择lightdm然后回车即可</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140540242.png" /></p>
<p>设置密码,设置密码后,会问你是否需要将密码保存在:/home/root1/.vnc/passwd,输入<code>y</code>确认即可</p>
<div class="dxycode"><pre class="brush:bash;">x11vnc -storepasswd</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140540630.png" /></p>
<p class="maodian"></p><h2>2. 设置vnc开机启动</h2>
<p>创建一个<code>x11vnc.service</code>文件</p>
<div class="dxycode"><pre class="brush:bash;">sudo vim /lib/systemd/system/x11vnc.service</pre></div>
<p>按<code>i</code>键进入编辑模式,添加如下信息,<strong>!!注意: 替换为您ubuntu用户名</strong>,添加完成后按Esc键退出编辑,然后输入冒号:wq保存</p>
<div class="dxycode"><pre>
Description=Start x11vnc at startup.
After=multi-user.target
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home//.vnc/passwd -rfbport 5900 -shared
WantedBy=multi-user.target</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140540108.png" /></p>
<p>设置开机启动</p>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl enable x11vnc.service</pre></div>
<p>启动服务</p>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl start x11vnc.service</pre></div>
<p class="maodian"></p><h2>3. windows 安装VNC viewer连接工具</h2>
<p>进入vnc官网,下载windows版vnc连接工具</p>
<p>https://www.realvnc.com/en/connect/download/viewer/</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140541562.png" /></p>
<p>下载好后打开使用局域网ip进行连接,端口是5900</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140541b5.png" /></p>
<p>出现密码界面,输入上面设置的密码即可</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140541962.png" /></p>
<p>出现ubuntu桌面表示成功</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-2505221405424c.png" /></p>
<p class="maodian"></p><h2>4. 内网穿透</h2>
<p>本地测试远程连接没问题后,接下来我们实现在公网环境下的远程桌面,这里我们可以使用cpolar内网穿透工具实现程访问。支持http/https/tcp协议,不限制流量,无需公网ip,也无需设置路由器。</p>
<blockquote><p>cpolar官网:https://www.cpolar.com/</p></blockquote>
<p class="maodian"></p><h3>4.1 安装cpolar【支持使用一键脚本命令安装】</h3>
<div class="dxycode"><pre class="brush:bash;">curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash</pre></div>
<p>或 cpolar短链接安装方式:(国外使用)</p>
<div class="dxycode"><pre class="brush:bash;">curl -sL https://git.io/cpolar | sudo bash</pre></div>
<ul><li>查看版本号,有正常显示版本号即为安装成功</li></ul>
<div class="dxycode"><pre class="brush:bash;">cpolar version</pre></div>
<ul><li>token认证</li></ul>
<p>登录cpolar官网后台,点击左侧的验证,查看自己的认证token,之后将token贴在命令行里</p>
<div class="dxycode"><pre class="brush:bash;">cpolar authtoken xxxxxxx</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="20230227141344" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140543V9.png" /></p>
<ul><li>简单穿透测试,有正常生成相应的公网地址即为穿透成功</li></ul>
<div class="dxycode"><pre class="brush:bash;">cpolar http 8080</pre></div>
<p>按ctrl+c退出</p>
<ul><li>向系统添加服务</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl enable cpolar</pre></div>
<ul><li>启动cpolar服务</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl start cpolar</pre></div>
<ul><li>查看服务状态</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl status cpolar</pre></div>
<p class="maodian"></p><h3>4.2 创建隧道映射</h3>
<p>cpolar安装成功后,在浏览器上访问本地9200端口,【127.0.0.1:9200],使用cpolar邮箱账号登录 web UI管理界面。</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140543594.png" /></p>
<p>登录成功后,点击左侧仪表盘的隧道管理——创建隧道,创建一个tcp协议的隧道指向本地5900端口:</p>
<ul><li>隧道名称:可自定义,注意不要与已有的隧道名称重复</li><li>协议:tcp</li><li>本地地址:5900</li><li>域名类型:免费选择随机域名</li><li>地区:默认China top即可</li></ul>
<p>点击<code>创建</code></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140544456.png" /></p>
<p>隧道创建成功后,点击左侧的状态——在线隧道列表,可以看到,刚刚创建的隧道已经有生成了相应的公网地址+公网端口号,将其复制下来</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140544K5.png" /></p>
<p class="maodian"></p><h3>4.3 测试公网远程访问</h3>
<p>打开windows vnc viewer,使用刚刚所获取的公网地址+公网端口号进行连接。本例为<code>2.tcp.vip.cpolar.cn:13001</code></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140544618.png" /></p>
<p>输入密码</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140544W8.png" /></p>
<p>公网远程连接成功</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-2505221405452O.png" /></p>
<p class="maodian"></p><h2>5. 配置固定TCP地址</h2>
<p>由于以上创建的隧道是随机地址隧道,该地址会在24小时内变化,为了使连接更加稳定,我们需要为其配置固定的TCP地址。</p>
<blockquote><p>需要注意,配置固定TCP端口地址需要将cpolar升级到专业版套餐或以上。</p></blockquote>
<p class="maodian"></p><h3>5.1 保留一个固定的公网TCP端口地址</h3>
<p>登录cpolar官网后台,点击左侧的预留,选择保留的TCP地址。</p>
<ul><li>地区:选择China VIP</li><li>描述:即备注,可自定义填写</li></ul>
<p>点击保留</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140545U1.png" /></p>
<p>地址保留成功后,系统会生成相应的固定公网地址,将其复制下来</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140545338.png" /></p>
<p class="maodian"></p><h3>5.2 配置固定公网TCP端口地址</h3>
<p>在浏览器上登录cpolar web UI管理界面,http://127.0.0.1:9200/,点击左侧仪表盘的隧道管理——隧道列表,找到我们前面创建的vnc远程隧道,点击右侧的编辑</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-250522140545136.png" /></p>
<p>修改隧道信息,将保留成功的固定tcp地址配置到隧道中</p>
<ul><li>端口类型:修改为固定tcp端口</li><li>预留的tcp地址:填写保留成功的地址</li></ul>
<p>点击更新</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-25052214054C21.png" /></p>
<p>隧道更新成功后,点击左侧仪表盘的状态——在线隧道列表,找到vnc远程桌面隧道,可以看到公网地址已经更新成为了固定tcp地址。</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-2505221405463O.png" /></p>
<p class="maodian"></p><h3>5.3 测试使用固定公网地址远程</h3>
<p>接下来测试使用固定TCP端口地址远程ubuntu桌面,我们再次在windows上打开VNC viewer,使用固定tcp地址连接,出现密码界面,同样输入密码</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-25052214054J35.png" /></p>
<p>远程连接成功</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250522/2-25052214054Q49.png" /></p>
<p class="maodian"></p><h2>总结</h2>
<p>至此,我们成功实现了使用VNC远程桌面ubuntu:通过cpolar穿透vnc服务5900端口,使用所生成的公网地址,实现在外随时随地远程桌面控制内网的Ubuntu,不需要公网IP,也不需要配置路由器。并且,这个公网地址还是固定的,不会随机变化,连接稳定。</p>
<p>除了穿透vnc之外,cpolar也可以应用在其他众多场景下,比如公网ssh远程、远程群晖NAS、我的世界联机、微信公众号支付宝调试、公开一个本地web…【PS:cpolar目前还支持21天退款保证】</p>
<p class="maodian"></p><h2>拓展:ubuntu开启黑屏现象解决</h2>
<p class="maodian"></p><h3>一、问题描述</h3>
<p>在一些 Ubuntu 用户的电脑中,系统可能会出现开机后显示黑屏的情况。此时系统仍然在运行,但由于显示问题,用户无法进入图形界面。这种问题通常发生在更新系统或更换硬件驱动之后,或者在某些显卡配置和驱动不兼容的情况下发生。</p>
<p class="maodian"></p><h3>二、解决方案</h3>
<p class="maodian"></p><h4>1. 检查显卡驱动</h4>
<p>显卡驱动问题是导致黑屏现象的常见原因。如果你使用的是 NVIDIA 显卡,系统可能没有正确安装或启用适当的驱动。为了解决这个问题,可以通过以下步骤检查和更新显卡驱动。</p>
<p><strong>解决步骤:</strong></p>
<ul><li>首先,通过按 <code>Ctrl + Alt + F3</code> 进入 <code>tty</code> 界面(一个命令行界面)。</li><li>登录后,首先更新你的软件包列表:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo apt update
sudo apt upgrade</pre></div>
<ul><li>如果你使用的是 NVIDIA 显卡,可以通过以下命令安装推荐的驱动:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo ubuntu-drivers autoinstall</pre></div>
<ul><li>安装完成后,重启计算机:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo reboot</pre></div>
<p>如果你的显卡是 AMD 或 Intel,确保你安装了正确的驱动程序,可以参考相关文档进行安装。</p>
<p class="maodian"></p><h4>2. 修复 GRUB 配置</h4>
<p>GRUB 引导加载程序负责加载操作系统。如果 GRUB 配置文件损坏或有错误,可能导致系统无法正常启动。可以通过修改 GRUB 配置文件来修复此问题。</p>
<p><strong>解决步骤:</strong></p>
<ul><li>进入 <code>tty</code> 界面(按 <code>Ctrl + Alt + F3</code>)。</li><li>登录后,编辑 GRUB 配置文件:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo nano /etc/default/grub</pre></div>
<ul><li>查找 <code>GRUB_CMDLINE_LINUX_DEFAULT</code>,将其值修改为以下内容:</li></ul>
<div class="dxycode"><pre class="brush:plain;">GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"</pre></div>
<p>这里的 <code>nomodeset</code> 参数可以禁用内核模块对显卡驱动的自动加载,帮助解决与显卡驱动相关的问题。</p>
<ul><li>保存并退出编辑器,然后更新 GRUB 配置:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo update-grub</pre></div>
<ul><li>最后,重启计算机:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo reboot</pre></div>
<p class="maodian"></p><h4>3. 使用恢复模式</h4>
<p>如果系统依然无法启动,可以通过进入恢复模式来修复系统。恢复模式会加载一个精简的环境,允许你进行故障排除和修复。</p>
<p><strong>解决步骤:</strong></p>
<ol><li>在启动时,按住 <code>Shift</code> 键进入 GRUB 菜单。</li><li>在 GRUB 菜单中,选择 <code>Advanced options for Ubuntu</code>(高级选项)。</li><li>在下一个菜单中,选择带有 <code>(recovery mode)</code> 的内核版本。</li><li>系统会启动到一个恢复菜单,在这里你可以选择进行文件系统检查(<code>fsck</code>),修复损坏的包(<code>dpkg</code>),或者仅以安全模式启动。</li></ol>
<p class="maodian"></p><h3>三、验证与总结</h3>
<p>通过上述几种方法,通常可以解决 Ubuntu 启动时的黑屏问题。显卡驱动问题和 GRUB 配置错误是导致黑屏的主要原因,而使用恢复模式也是一个有效的故障排除工具。</p>
<p>如果问题依然没有解决,建议检查硬件是否出现问题,或者考虑重新安装操作系统。另外,你也可以通过 Ubuntu 的官方论坛或者社区寻求帮助,找到适合自己情况的解决方案。</p>
頁:
[1]