SSH 터널링

SSH 터널링이란 SSH 클라이언트와 SSH 서버 사이에 마치 터널이 뚫린 것처럼 연결이 되어 데이터를 주고 받을 수 있는 것이다. 여기에 포트 포워딩이란 기술이 더해진다. SSH의 TCP/22번 포트가 방화벽에 의해 막히지만 않는다면 방화벽을 우회할 수 있다.

SSH 터널링 방식은 아래와 같다.

  1. SSH Local Port Forwarding
  2. SSH Remote Port Forwarding
  3. SSH Dynamic Port Forwarding

우선 Local / Remote Port Forwarding을 알아보도록 하자.

SSH Local Port Forwarding

ssh_tunneling 위 그림을 예시로 설명하자면

ssh -L 111:127.0.0.1:222 10.10.0.1

위 명령어를 Host A에 입력한다.

SSH Client - Host A, SSH Server - Host B

  1. SSH Client는 111 포트를 listen 하고 있는다.
  2. 111 포트로 데이터가 왔으면 SSH Server로 전송한다.
  3. SSH Server는 127.0.0.1:222로 전송한다.

222 포트가 방화벽에 의해 막혀 있어도 TCP/22번 포트(SSH)만 열려 있다면 접근이 가능하다.


잘 설명되어 있는 이미지 https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot 이미지 출처: https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot


SSH Remote Port Forwarding

ssh_tunneling 위 그림을 예시로 설명하자면

ssh -R 111:127.0.0.1:222 10.10.0.0

위 명령어를 Host B에 입력한다.

SSH Client - Host B, SSH Server - Host A

  1. SSH Server는 111 포트를 listen 하고 있는다.
  2. 111 포트로 데이터가 왔으면 SSH Client로 전송한다.
  3. SSH Client는 127.0.0.1:222로 전송한다.

잘 설명되어 있는 이미지 https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot 이미지 출처: https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot


참고
https://www.ssh.com/academy/ssh/tunneling-example
https://hbase.tistory.com/328
https://ithub.tistory.com/328
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=alice_k106&logNo=221364560794