Ngrok 内网穿透搭建 树莓派内网穿透

2020-09-27  本文已影响0人  Morgan7

服务器端

安装Go语言环境

yum install go

clone

cd ngrok_server
git clone https://github.com/inconshreveable/ngrok.git

export NGROK_DOMAIN="ngrok.你的域名.com"

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 device.key 2048

openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr

openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

cp rootCA.pem ../assets/client/tls/ngrokroot.crt

cp device.crt ../assets/server/tls/snakeoil.crt

cp device.key ../assets/server/tls/snakeoil.key
GOOS=linux GOARCH=amd64 make release-server

客户端

sudo apt install golang

apt install make

cd ngrok

make release-client
server_addr: "ngrok.你的域名.com:4443"
trust_host_root_certs: false
tunnels:
 ssh:
  remote_port: 2222
  proto:
   tcp: "22"
./ngrok -config=ngrok.cfg start ssh

后台启动

./ngrok -config=ngrok.cfg start ssh
apt-get install screen

screen ./ngrok.sh

开机启动

case "$1" in
        start)
                echo "start ngrok service.."
                sh /data/ngrok_app/ngrok/bin/ngrok.sh
                ;;
        *)
        exit 1
        ;;
esac
/data/ngrok_app/ngrok/bin/ngrok -config=/data/ngrok_app/ngrok/bin/ngrok.cfg start ssh

添加开机启动

systemctl enable ngrok

启动

systemctl start ngrok

systemctl stop ngrok

状态

systemctl status ngrok.service
上一篇下一篇

猜你喜欢

热点阅读