단일 프록시 명령을 사용하여 다중 점프를 구성하는 방법

단일 프록시 명령을 사용하여 다중 점프를 구성하는 방법

~/.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

관련 정보