У меня есть AWS VPC с несколькими общедоступными подсетями и частной подсетью, как на изображении ниже.
В NAT GATEWAY - это настроенный мной экземпляр Ubuntu 16.04 (t2.micro). Это не управляемый шлюз AWS NAT. Он отлично работает как шлюз для всех других хостов внутри VPC, а также для D-NAT (для некоторых частных серверов Apache), а также действует как бастион SSH.
Проблема в том, что ЭКЗЕМПЛЯР А не может пинговать или трассировать хосты в Интернете. Я уже пробовал / проверял:
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 -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
Спасибо @hargut за указание подробностей о traceroute с использованием UDP (и мои SG не позволяют этого). Итак, используя его с -I
вариант для 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 * * *
...
Linux / Unix traceroute использует 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
Увидеть -I
опция tracerout, которая переключает режим traceroute на трассировку на основе ICMP.