ngrok 를 이용하여 포트포워딩 하기

Posted by Albert 437Day 19Hour 37Min 46Sec ago [2023-03-08]

Centos 상 ngrok 를 다운받고 docker로 띄운 jenkins 를 외부에서 접근가능하도록 포워딩 해보겠다.

1. 우선 ngrok를 다운받는다

https://ngrok.com/download 상 관련 파일 다운 후 리눅스 특정 폴더에 넣어준다.

[albert@docker ~]$ sudo tar xvzf ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin
ngrok
[albert@docker ~]$ ngrok
NAME:
ngrok - tunnel local ports to public URLs and inspect traffic

USAGE:
ngrok [command] [flags]

DESCRIPTION:
ngrok exposes local networked services behinds NATs and firewalls to the
public internet over a secure tunnel. Share local websites, build/test
webhook consumers and self-host personal services.
Detailed help for each command is available with 'ngrok help <command>'.
Open http://localhost:4040 for ngrok's web interface to inspect traffic.

Author:
ngrok - <support@ngrok.com>

TERMS OF SERVICE: https://ngrok.com/tos

EXAMPLES:
ngrok http 80 ' secure public URL for port 80 web server
ngrok http --subdomain=baz 8080 ' port 8080 available at baz.ngrok.io
ngrok http foo.dev:80 ' tunnel to host:port instead of localhost
ngrok http https://localhost ' expose a local https server
ngrok tcp 22 ' tunnel arbitrary TCP traffic to port 22
ngrok tls --hostname=foo.com 443 ' TLS traffic for foo.com to port 443
ngrok start foo bar baz ' start tunnels from the configuration file

COMMANDS:
api use ngrok agent as an api client
completion generates shell completion code for bash or zsh
config update or migrate ngrok's configuration file
credits prints author and licensing information
diagnose diagnose connection issues
help Help about any command
http start an HTTP tunnel
service run and control an ngrok service on a target operating system
start start tunnels by name from the configuration file
tcp start a TCP tunnel
tls start a TLS tunnel
tunnel start a tunnel for use with a tunnel-group backend
update update ngrok to the latest version
version print the version string

OPTIONS:
--config strings path to config files; they are merged if multiple
-h, --help help for ngrok
-v, --version version for ngrok


2. ngrok 계정생성

[albert@docker ~]$ ngrok http 8077
ngrok (Ctrl+C to quit)

Join us in the ngrok community @ https://ngrok.com/slack

Session Status online
Account babycut@gmail.com (Plan: Free)
Version 3.1.1
Region Japan (jp)
Latency -
Web Interface http://127.0.0.1:4040
Forwarding https://2853-27-119-54-170.jp.ngrok.io -> http://localhost:8077

Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00

로컬상 jenkins는 8077로 되어있고 https://2853-27-119-54-170.jp.ngrok.io/ 가 8077포트로 포워딩 된걸 볼 수 있다.

하지만 접속하면 ERR_NGROK_6022 오류가 뜨면서 접속 되지 않는다


내용을 보면 ngrok계정으로 로그인 후 서버단에서 관련 인증을 추가하여야 한다는걸 알 수 있다.

Sign up for a free Account 버튼을 클릭하여 

https://dashboard.ngrok.com/get-started/setup 로이동후 회원가입하고 로그인 하면 아래 내용을 확인 가능하다.


[albert@docker ~]$ ngrok config add-authtoken 2MidcoC147BEQjC03PuCA7NFeaz_4FnHUDb61xZhKr62J2Laj


토큰 추가 후 다시 브라우저로 확인하면 정상 페이지가 뜨는걸 확인 할 수 있다.

 





LIST

Copyright © 2014 visionboy.me All Right Reserved.