A instância na sub-rede privada pode conectar-se à Internet, mas não pode executar ping/traceroute

A instância na sub-rede privada pode conectar-se à Internet, mas não pode executar ping/traceroute

Tenho uma AWS VPC com algumas sub-redes públicas e uma sub-rede privada, como na imagem abaixo.

  • Ambas as instâncias podem se conectar à Internet (INSTÂNCIA Ase conecta atravésPORTA NATinstância)
  • PORTA NATpode executar ping e rastrear hosts na Internet e instâncias em outras sub-redes
  • INSTÂNCIA Apode pingarPORTA NATe outras instâncias em sua sub-rede e em outras sub-redes

OPORTA NATé uma instância do Ubuntu 16.04 (t2.micro), configurada por mim. Não é um gateway AWS NAT gerenciado. Está funcionando perfeitamente como gateway para todos os outros hosts dentro da VPC, bem como para D-NAT (para alguns servidores Apache privados) e também atuando como um bastião SSH.

O problema é queINSTÂNCIA Anão é possível executar ping ou rastrear hosts na Internet. Eu já tentei/verifiquei:

  • Tabelas de rotas
  • Grupos de segurança
  • Regras IPTABLES
  • parâmetros do kernel

diagrama vpc

Grupos de segurança

 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

Tabelas de rotas

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

Regras do 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

Parâmetros do kernel

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

Amostra de traceroute da INSTÂNCIA A

Obrigado ao @hargut por apontar um detalhe sobre o traceroute usando UDP (e meus SGs não permitem isso). Então, usando-o com -Iopção para ICMP:

# 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  * * *
 ...

Responder1

O traceroute Linux/Unix usa UDP para solicitações padrão. Seu grupo de segurança não permite pacotes de entrada UDP.

Na página de manual do 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

Veja a -Iopção tracerout que alterna o modo traceroute para rastreamento baseado em ICMP.

informação relacionada