為何需要自建遠程控制桌面
想要隨時隨地遠程一台電腦?上網搜一下常見方案有teamviewer,向日葵遠控,這2寶貝基本滿足普通用戶的大部分需求。但是如果想特定端口,商業環境公司網絡,還想在手機上遠控。那就得自己DIY了。
所需硬性條件
單純內網遠控
在家有多個電腦,想直接用手機遠控。那就直接裝TightVNC和VNCViewer就足夠了。此處唯一需要注意的是
- TightVNC提供Client Viewer,但不怎么好用。其他直接下一步就成。同時記得設置密碼。
- www.realvnc.com/en/connect/download/viewer 一看就懂,按需下載
- 連接的服務器地址請填被控電腦的內網地址。可在命令行下敲ipconfig看。
公網遠控
模擬情景是這樣的,用手機4G網絡,使用VNCViewer軟件連接114.114.114.114:55555服務器。服務器通過frp和某內網電腦192.168.1.55的frp軟件通信,frpc則和自身的vnc server服務端口127.0.0.1:5900通訊。
公網服務器FRPS安裝和使用
- 以ubuntu為例,直接下載frp https://github.com/fatedier/frp/releases
- 解壓包,找到frps.ini 進行配置
[common]
bind_addr = 0.0.0.0
bind_port = 55000 //此處端口重要
token = testtoken
//WEB HTTP服務詳情查看的端口
dashboard_port = 55500
# dashboard 用戶名密碼,默認都為 admin
dashboard_user = admin
dashboard_pwd = adminpsd
log_file = ./home/ubuntu/frps_log.log
log_level = info
log_max_days = 3
- 運行包含指定配置的frps服務器程序
frps -c ./frps.ini
服務設置,讓frps成為后台服務
- 新建一個服務文件 frps.service
[Unit]
Description=frps service
After=network.target syslog.target
Wants=network.target
[Service]
Type=simple
#啟動服務的命令(此處寫你的frps的實際安裝目錄)
ExecStart=/home/ubuntu/frp/frps -c /home/ubuntu/frp/frp_0.20.0_linux_amd64/frps.ini
[Install]
WantedBy=multi-user.target
- 復制到ubuntu的服務目錄下
/lib/systemd/system
- 通過以下指令來判斷frps的服務運行
//重載列表
systemctl daemon-reload
//確認frps是否存在
systemctl --all | grep frps
//確認具體狀態
systemctl status frps
//啟動
systemctl start frps
- 最后是設置自啟動
//是否自啟動
systemctl is-enabled frps
//是否已啟動
systemctl is-active frps
//設置自啟動
systemctl enable frps
//禁止自啟動
systemctl disable frps
客戶端設置
讓被控電腦通過FRPS將VNC服務暴露在公網
- 直接下載frp https://github.com/fatedier/frp/releases
- 解壓包,找到frpc.ini 端口和token設置
[common]
server_addr = 114.114.114.114 //公網服務器ip
server_port = 55000 //frp端口
token = testtoken //需和frps.ini的設置的一致
[range:VNC]
type = tcp
local_ip = 127.0.0.1 //
local_port = 5900 //TightVNC Service所設置的Main Server port
remote_port = 55555 //公網VNC訪問端口,日后Viewer通過114.114.114.114:55555進行鏈接
use_encryption = false
use_compression = false
- TightVNC Service設置 - 開啟回路
Access Control -> 勾選 Allow loopback connections
(可選)Windows下為frpc設自動啟動服務
- 用WINSW 來自動設置服務吧
- 下載,解壓,配置winsw.xml
<service>
<id>frpc</id>
<name>frp0.27.1-windows-amd64</name>
<description>frpc客戶端 這個服務用 frpc 實現內網穿透</description>
<executable>H:/frp_0.27.1_windows_amd64/frpc.exe</executable>
<arguments>-c H:/frp_0.27.1_windows_amd64/frpc.ini</arguments>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<log mode="append" />
<logpath>H:/frp_0.27.1_windows_amd64/frp_logs.log</logpath>
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
</service>
- 執行命令行安裝命令
//安裝服務
winsw install
//開啟服務
winsw start
- 查看結果