MacOS

VSCode remote-ssh 플러그인 localhost port forwarding

Caniro 2021. 11. 11. 22:45

VSCode remote-ssh 플러그인 localhost port forwarding

문제점 발견

remote-ssh를 통해 라즈베리파이에서 웹서버를 열면, localhost:8000 주소가 라즈베리파이로 자동 연결되는 현상이 발생했다.

뭐가 잘못된 건지 몰랐었는데, 로컬에서 서버를 하나 더 열면서 localhost에서 8000번 포트가 사용 중인 것을 발견했다.

  $ python manage.py runserver
  Watching for file changes with StatReloader
  Performing system checks...

  System check identified no issues (0 silenced).
  November 11, 2021 - 06:52:53
  Django version 2.2.5, using settings 'mysite.settings'
  Starting development server at http://127.0.0.1:8000/
  Quit the server with CONTROL-C.
  Error: That port is already in use.

해당 포트를 사용하는 프로세스 확인

netstat

netstat 명령어로 특정 포트를 사용 중인 프로세스의 아이디PID를 찾을 수 있다.

  $ netstat -anv | head -2 | tail -1; netstat -anv | grep 8000
  Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)     rhiwat shiwat    pid   epid  state    options
  tcp4       0      0  127.0.0.1.8000         *.*                    LISTEN      131072 131072  56783      0 0x0100 0x00000106

ps

PID가 56783인 프로세스의 이름을 찾아보자

  $ ps -f 56783
  UID   PID  PPID   C STIME   TTY           TIME CMD
  501 56783 56754   0 화04PM ??         1:58.66 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper ...이하생략

VSCode에서 포트포워딩 비활성화

remote-ssh를 사용하는 VSCode 창에서 F1 이나 Command + Shift + P 를 누르고 Stop Forwaring Port 를 찾아서 포트를 비활성화하면 끝


참고