搭建ngrok远程桌面的环境
服务器server的centos环境
yum -y install zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker hg wget gcc gcc-c++ git
## 安装go
sudo yum remove golang
cd /usr/local/src/
sudo wget https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
echo 'export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin
export NGROK_DOMAIN="my.zuoer.xin"' | sudo tee -a /etc/profile
source /etc/profile
## 安装ngrok
git clone https://github.com/inconshreveable/ngrok.git ngrok
cd ngrok
export NGROK_DOMAIN="my.zuoer.xin"
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
生成服务端
-----------
Linux 平台 32 位系统:GOOS=linux GOARCH=386
Linux 平台 64 位系统:GOOS=linux GOARCH=amd64
Windows 平台 32 位系统:GOOS=windows GOARCH=386
Windows 平台 64 位系统:GOOS=windows GOARCH=amd64
MAC 平台 32 位系统:GOOS=darwin GOARCH=386
MAC 平台 64 位系统:GOOS=darwin GOARCH=amd64
ARM 平台:GOOS=linux GOARCH=arm
------------
我的是
服务器 GOOS=linux GOARCH=amd64 make release-server
客户端 GOOS=windows GOARCH=386 make release-client
启动ngrokd
apt install screen
screen -S ngrok
# 安装ctrl+ A+D 就在后台运行了 ; screen -ls 查看列表; screen -r ngrok 回到对应的名称的前台
nohup ./bin/ngrokd -tlsKey="assets/server/tls/snakeoil.key" -tlsCrt="assets/server/tls/snakeoil.crt" -domain="$NGROK_DOMAIN" -httpAddr=":8081" -httpsAddr=":8082" -tunnelAddr=":4443"
或者(http)
nohup ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="my.zuoer.xin" -httpAddr=":8081" &
或者sudo ./ngrokd -domain $NGROK_DOMAIN
把bin/windows_386下的ngrok.exe 拷到Windows上
scp root@***://usr/local/src/ngrok/bin/windows_386/ngrok.exe /Users/***/Desktop
客户端使用
把编译生成ngrok.exe发送到window机器,新建ngrok.cfg,追加下面的内容
server_addr: "zuoer.xin:4443"
trust_host_root_certs: false
tunnels:
mstsc:
remote_port: 50123
proto:
tcp: "127.0.0.1:3389"
使用cmd执行:
ngrok.exe -config=ngrok.cfg start mstsc
ngrok 其他使用在下面
server_addr: "zuoer.xin:4443"
trust_host_root_certs: false
ngrok.exe -subdomain hello -proto=http -config=ngrok.cfg 3000
linux客户端同理, 只需要把ngrok.exe换成ngrok
执行报错,配置的server_addr的域名需要和上面server中配置的域名一致
#client报错
Tunnel Status reconnecting
Version 1.7/
Web Interface 127.0.0.1:4040
Conn 0
Avg Conn Time 0.00ms
#server端报错
[20:33:07 CST 2018/11/19] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [pub:77b2576c] New connection from 185.10.68.26:34410
[20:33:07 CST 2018/11/19] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [pub:77b2576c] Found hostname in request
[20:33:07 CST 2018/11/19] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [pub:77b2576c] No tunnel found for hostname
[20:33:07 CST 2018/11/19] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [pub:77b2576c] Closing
8 客户端绑定多种方式
绑定client的3000端口映射到http|https://hello.zuoer.xin
./ngrok -subdomain hello -proto=http -config=ngrok.cfg 3000
绑定client的3000端口映射到tcp://hello.zuoer.xin
./ngrok -subdomain hello -proto=tcp -config=ngrok.cfg 3000
如果想一次性转发多个端口或者想指定远程的对应端口,需要完善ngrok.cfg
server_addr: ngrok.moonwalker.me:4443
trust_host_root_certs: false
tunnels:
ssh:
remote_port: 1122
proto:
tcp: 22
ss:
emote_port: 8388
proto:
tcp: 8388
ftp:
remote_port: 20
proto:
tcp: 20
ftp2:
remote_port: 21
proto:
tcp: 21
http:
subdomain: www
proto:
http: 80
https: 443
管理员已关闭本篇文章评论!