![단일 프록시 명령을 사용하여 다중 점프를 구성하는 방법](https://linux55.com/image/136058/%EB%8B%A8%EC%9D%BC%20%ED%94%84%EB%A1%9D%EC%8B%9C%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%8B%A4%EC%A4%91%20%EC%A0%90%ED%94%84%EB%A5%BC%20%EA%B5%AC%EC%84%B1%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
내 ~/.ssh/config
파일은
Host head
User Marry
HostName xxx.xx.xxx.xx
Host machine1
User Marry
HostName xxx.xx1.xxx.xx
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null
Host machine2
User Marry
HostName xxx.xx2.xxx.xx
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null
Host machine3
User Marry
HostName xxx.xx3.xxx.xx
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null
Host machine4
User Marry
HostName xxx.xx4.xxx.xx
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null
하지만 더 많은 머신을 수동으로 설정하는 것은 지루할 것입니다. 다음과 같은 인스턴스를 어떻게 설정합니까?
Host machine*
User Marry
HostName xxx.xx*.xxx.xx
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null
호스트 이름 주소는 숫자로만 다르기 때문입니다.
고쳐 쓰다Tagwint의 제안에 따라 다음을 얻습니다.
ssh_exchange_identification: Connection closed by remote host
답변1
ProxyJump
다음 명령을 사용하여 이 작업을 수행할 수 있습니다 .
Host machine1 machine2 machine3
ProxyJump head
필요한 경우 다음과 같이 두 호스트를 통해 이중 홉을 수행할 수 있습니다.
Host machine1 machine2 machine3
ProxyJump head,jump
또는 다음과 같이 도메인의 모든 항목을 일치시킵니다.
Match host "*.example.com"
ProxyJump head,jump
현재 IP 주소를 기반으로 이 작업을 수행할 수도 있습니다.
Match host "*.example.com" !exec "ifconfig | grep -q ' 172.16.1.40 '"
ProxyJump head,jump.example.com
답변2
DNS 해상도를 이렇게 정리할 수 있다면
xxx.xx1.xxx.xx machine1
xxx.xx2.xxx.xx machine2
xxx.xx3.xxx.xx machine3
(DNS 서버 구성을 사용하거나 /etc/hosts 파일의 항목을 사용하십시오)
그러면 .ssh/config의 마지막 인스턴스에는 호스트 이름 항목이 포함되지 않습니다.
Host machine*
User Marry
IdentityFile /home/Marry/ssh_head_keys/id_rsa
ProxyCommand ssh head nc %h %p 2> /dev/null