프라이빗 서브넷의 인스턴스는 인터넷에 연결할 수 있지만 ping/traceroute는 불가능합니다.

프라이빗 서브넷의 인스턴스는 인터넷에 연결할 수 있지만 ping/traceroute는 불가능합니다.

아래 이미지와 같이 일부 퍼블릭 서브넷과 프라이빗 서브넷이 있는 AWS VPC가 있습니다.

  • 두 인스턴스 모두 인터넷에 연결할 수 있습니다(인스턴스 A을 통해 연결NAT 게이트웨이사례)
  • NAT 게이트웨이인터넷의 호스트와 다른 서브넷의 인스턴스를 핑하고 경로를 추적할 수 있습니다.
  • 인스턴스 A핑할 수 있다NAT 게이트웨이해당 서브넷과 다른 서브넷의 다른 인스턴스

그만큼NAT 게이트웨이내가 구성한 Ubuntu 16.04(t2.micro) 인스턴스입니다. 관리형 AWS NAT 게이트웨이가 아닙니다. 이는 VPC 내부의 다른 모든 호스트와 D-NAT(일부 개인 Apache 서버의 경우)에 대한 게이트웨이로 완벽하게 작동하고 SSH Bastion 역할도 합니다.

문제는인스턴스 A인터넷에서 호스트를 ping하거나 추적할 수 없습니다. 나는 이미 시도/확인했습니다:

  • 라우팅 테이블
  • 보안 그룹
  • IPTABLES 규칙
  • 커널 매개변수

vpc 다이어그램

보안 그룹

 NAT GATEWAY
 Outbound: 
  * all traffic allowed
 Inbound:
  * SSH from 192.168.0.0/16 (VPN network)
  * HTTP/S from 172.20.0.0/16 (allowing instances to connect to the internet)
  * HTTP/S from 0.0.0.0/0 (allowing clients to access internal Apache servers through D-NAT)
  * ALL ICMP V4 from 0.0.0.0/0 


 INSTANCE A
 Outbound: 
  * all traffic allowed
 Inbound:
  * SSH from NAT GATEWAY SG
  * HTTP/S from 172.20.0.0/16 (public internet throught D-NAT)
  * ALL ICMP V4 from 0.0.0.0/0

라우팅 테이블

PUBLIC SUBNET
172.20.0.0/16: local
0.0.0.0/0: igw-xxxxx (AWS internet gateway attached to VPC)

PRIVATE SUBNET
0.0.0.0/0: eni-xxxxx (network interface of the NAT gateway)
172.20.0.0/16: local

IPtables 규칙

# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

# iptables -tnat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE

커널 매개변수

net.ipv4.conf.all.accept_redirects = 0  # tried 1 too
net.ipv4.conf.all.secure_redirects = 1
net.ipv4.conf.all.send_redirects = 0  # tried 1 too
net.ipv4.conf.eth0.accept_redirects = 0  # tried 1 too
net.ipv4.conf.eth0.secure_redirects = 1
net.ipv4.conf.eth0.send_redirects = 0  # tried 1 too
net.ipv4.ip_forward = 1

인스턴스 A의 샘플 추적 경로

UDP를 사용하는 Traceroute에 대한 세부 정보를 지적한 @hargut에게 감사드립니다(내 SG에서는 이를 허용하지 않습니다). 따라서 -IICMP 옵션과 함께 사용하면 다음과 같습니다.

# traceroute -I 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  ip-172-20-16-10.ec2.internal (172.20.16.10)  0.670 ms  0.677 ms  0.700 ms
 2  * * *
 3  * * *
 ...

답변1

Linux/Unix 추적 경로는 표준 요청에 UDP를 사용합니다. 보안 그룹은 UDP 인바운드 패킷을 허용하지 않습니다.

Traceroute 매뉴얼 페이지에서:

In the modern network environment the traditional traceroute methods can not be always applicable, because of widespread use of firewalls. Such firewalls filter the "unlikely" UDP ports, or even ICMP echoes. To solve this, some additional tracerouting methods are implemented (including tcp), see LIST OF AVAILABLE METHODS below. Such methods try to use particular protocol and source/destination port, in order to bypass firewalls (to be seen by firewalls just as a start of allowed type of a network session)

https://linux.die.net/man/8/traceroute

-ITraceroute 모드를 ICMP 기반 추적으로 전환하는 Tracerout 옵션을 참조하세요 .

관련 정보