SSH 역터널 및 Iptables

SSH 역터널 및 Iptables

Linux 랩톱과 원격 서버 간에 다음 명령을 사용하여 역방향 SSH 터널을 설정했습니다.

ssh -4nNT -R 2222:localhost:22 somehost.com

즉, 방화벽 뒤에 있는 랩톱은 다음 명령을 사용하여 SSH를 통해 액세스할 수 있습니다.

ssh -p 2222 -l joe somehost.com

somehost.com의 sshd_config에서 Gatewayports=yes를 활성화했습니다.

이 모든 것이 잘 작동한다고 말할 수 있어서 기쁩니다. 그러나 한 가지 아쉬운 점은 iptablessomehost.com에서 포트 2222가 열려 있지 않은 실행이 있다는 것입니다. 이 터널이 작동하고 있음에도 불구하고 그것이 어떻게 가능합니까? 원격 SSH 터널은 뒤에서 어떻게 작동합니까? 누구든지 친절하게 설명해줄 수 있나요?

다음은 iptables -L의 출력입니다.

  target     prot opt source               destination

  ACCEPT     icmp --  anywhere             anywhere             icmp destination-unreachable
  ACCEPT     icmp --  anywhere             anywhere             icmp time-exceeded
  ACCEPT     icmp --  anywhere             anywhere             icmp echo-request
  ACCEPT     icmp --  anywhere             anywhere             icmp echo-reply
  DROP       tcp  -f  anywhere             anywhere
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN/FIN,SYN
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,ACK/FIN
  DROP       tcp  --  anywhere             anywhere             tcp flags:SYN,RST/SYN,RST
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG
  DROP       udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc
  DROP       tcp  --  anywhere             anywhere             tcp dpt:kazaa
  DROP       udp  --  anywhere             anywhere             udp dpt:kazaa
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:ssh state NEW LOG level warning tcp-options ip-options prefix "firewall-> ssh1: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:ssh
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:2023 state NEW LOG level warning tcp-options ip-options prefix "firewall-> Check: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:2023
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:http state NEW LOG level warning tcp-options ip-options prefix "firewall-> HTTP: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:http
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:https state NEW LOG level warning tcp-options ip-options prefix "firewall-> HTTPS: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:https

  Chain FORWARD (policy ACCEPT)
  target     prot opt source               destination

  Chain OUTPUT (policy ACCEPT)
  target     prot opt source               destination
  ACCEPT     tcp  --  anywhere             anywhere             tcp spt:http

답변1

somehost.com에는 sshd라는 ssh 데몬이 실행됩니다. -R 2222:localhost:22를 사용하여 ssh를 호출하면 somehost.com의 sshd에 포트 2222로 전송되는 트래픽을 포트 22를 통해 방화벽 뒤의 노트북으로 터널링해야 한다고 알립니다. Gatewayports=yes로 설정했기 때문에 sshd는 모든 트래픽을 보냅니다. 트래픽은 포트 22의 터널을 통해 포트 2222로 전송되는 다른 호스트에서 랩톱으로 전송됩니다.

더 자세한 내용은 다음을 참조하세요.https://unix.stackexchange.com/questions/46235/how-does-reverse-ssh-tunneling-work.

관련 정보