%EC%9D%84%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EC%88%98%ED%96%89%ED%95%A9%EB%8B%88%EA%B9%8C%3F.png)
저는 GNS3 서버를 가지고 있고, 우리 팀의 누군가가 포트 1100에 연결할 때 192.168.122.2:22와 같은 내부 IP로 라우팅되도록 iptable 규칙을 추가하려고 합니다. 이 내부 IP는 GNS3 프로젝트의 배스천 호스트에 속합니다. 최종 목표는 로컬 시스템에서 내부 IP 주소로 shh할 수 있는 것입니다.
내 IPTABLE은 다음과 같습니다(예를 들어 가짜 공용 IP 1.2.3.4 사용).
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 DNAT tcp -- 0.0.0.0/0 1.2.3.4 tcp dpt:1100 to:192.168.122.2:22
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 MASQUERADE all -- 0.0.0.0/0 0.0.0.0/0
Chain DOCKER (0 references)
num target prot opt source destination
Chain LIBVIRT_PRT (0 references)
num target prot opt source destination
내 로컬 컴퓨터에서 명령을 실행합니다 . Ubuntu는 GNS3 프로젝트 내부 IP에 액세스하는 데 필요한 사용자 이름입니다.ssh [email protected] -p1100
이 명령을 실행한 후 GNS3 서버(1.2.3.4)에 다음과 같은 출력이 표시됩니다.
cloud@gns3:~$ connect_to 192.168.122.2 port 1100: failed.
내 SSH 명령이 GNS3 서버에 도달하고 포트 전달을 시도하는 것 같습니다.그런데 어떤 이유에서인지 22번 포트가 아닌 1100번 포트로 포워딩을 시도하고 있는 걸까요? 누구든지 이유를 확인할 수 있습니까?
내가 지금까지 시도한 것은 다음과 같습니다.
- ipv4 포트 전달을 1로 설정
- GatewayPorts 및 AllowTcpForwarding을 1로 설정합니다.
- 로컬 컴퓨터에서 실행되었습니다(이로 인해 서버의 일부 구성이 변경된 것 같습니다) -
ssh -R 1.2.3.4:1100:192.168.122.2:22 [email protected]
- 명령을 사용하여 IPtables에 규칙을 추가했습니다.
sudo iptables --table nat --append PREROUTING --protocol tcp --destination 1.2.3.4 --dport 1100 --jump DNAT --to-destination 192.168.122.2:22
- Masquerading도 추가되었습니다:
sudo /sbin/iptables -t nat -A POSTROUTING -j MASQUERADE
답변1
DNAT를 사용하는 대신 다음 소스에 따라 REDIRECT를 수행해야 합니다.
그래서:
sudo iptables --table nat --append PREROUTING --protocol tcp --destination 1.2.3.4 --dport 1100 --jump REDIRECT --to-destination 192.168.122.2:22