GCP 서버 내에서 외부 IP 주소를 찾고 있습니다.
애플리케이션에 대한 해당 VM 인스턴스의 외부(인터넷/공개) IP를 검색해야 하는 프로젝트에서 작업하고 있습니까?
좋은 소식 – 빨리 얻을 수 있습니다.
ifconfig 명령을 실행해 보았을 것입니다. 그리고 결과에 내부 IP만 포함되어 있음을 알 수 있습니다.
GCP와 AWS는 모두 공개 IP를 볼 수 있는 친숙한 웹 인터페이스를 가지고 있지만 서버에서 직접 가져와야 하는 경우 다음 명령이 도움이 됩니다.
GCP VM에서 외부 IP 가져오기
내가 아는 두 가지 가능한 방법이 있습니다. 첫 번째는 gcloud 명령어를 사용하는 것입니다.
gcloud compute addresses list
위의 명령은 모든 프로젝트 IP를 표시합니다. 문제 해결에 유용하거나 VM에 로그인한 상태에서 빠른 검토가 가능합니다.
전:
[email protected]:~# gcloud compute addresses list NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS instance-1 xx.xx.xx.xx us-west1 IN_USE koreantech.org-nexus xx.xx.xx.xx INTERNAL GCE_ENDPOINT us-west1 default IN_USE koreantech.org xx.xx.xx.xx us-west1 IN_USE koreantech.org-tools xx.xx.xx.xx us-west1 IN_USE [email protected]:~#
두 번째는 메타데이터에 curl 명령을 사용하는 것입니다.
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip
참고: 여러 네트워크 인터페이스가 있는 경우 네트워크 인터페이스 후 0을 그에 따라 1 또는 2로 변경해야 합니다.
메타데이터는 강력합니다. 많은 메트릭을 검색할 수 있습니다.
[email protected]:~# curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/ attributes/ cpu-platform description disks/ guest-attributes/ hostname id image licenses/ machine-type maintenance-event name network-interfaces/ preempted remaining-cpu-time scheduling/ service-accounts/ tags virtual-clock/ zone [email protected]:~#
내 말은?
이는 보고 및 자동화에 유용할 수 있습니다.
내부 IP도 가져와야 하는 경우 아래 명령을 사용하십시오.
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/ip
GCP 관리를 배우고 있습니까? 이 환상적인 것을 확인하십시오 온라인 코스.
기사를 재미있게 읽었습니까? 세상과 함께 나누는 건 어떨까요?