Назад | Перейти на главную страницу

Невозможно подключиться к веб-серверу, размещенному в частной подсети VPC, через NAT, размещенном в общедоступной подсети

Я разместил свое Android / веб-приложение на экземпляре EC2 в частной подсети (10.0.1.0) моего VPC. На этом экземпляре установлен apache-tomcat, но у него нет общедоступного IP-адреса.

У меня также есть экземпляр NAT в публичной подсети (10.0.0.0) моего VPC с публичным IP-адресом, назначенным серверу.

Конфигурация iptables выглядит так:

[ec2-user@ip-10-0-0-21 ~]$ sudo iptables -t nat -L --line-numbers
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    DNAT       tcp  --  anywhere             anywhere             tcp dpt:webcache to:10.0.1.11:8080
2    DNAT       tcp  --  anywhere             anywhere             tcp dpt:http to:10.0.1.11:8080
3    DNAT       tcp  --  anywhere             anywhere             tcp dpt:http to:10.0.1.11:8080
4    DNAT       tcp  --  anywhere             anywhere             tcp dpt:https to:10.0.1.11:8080

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    MASQUERADE  all  --  ip-10-0-0-0.ap-southeast-1.compute.internal/16  anywhere
2    MASQUERADE  all  --  ip-10-0-1-0.ap-southeast-1.compute.internal/24  anywhere
[ec2-user@ip-10-0-0-21 ~]$ sudo iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to XX.XX.XX.XX

Несмотря на эти настройки, я получаю ERR_CONNECTION_TIMED_OUT ошибка при попытке подключиться к общедоступному DNS моего NAT-сервера. Если мой запрос на соединение попадал на сервер apache, я должен был получить как минимум 404.

Я проверил возможность подключения своего веб-сервера (в частной подсети) к Интернету через NAT-сервер. Я получаю верные ответы, когда ping или wget google.com.

[ec2-user@ip-10-0-1-11 ~]$ ping google.com
PING google.com (173.194.117.97) 56(84) bytes of data.
64 bytes from sin01s17-in-f1.1e100.net (173.194.117.97): icmp_seq=1 ttl=56 time=3.54 ms
64 bytes from sin01s17-in-f1.1e100.net (173.194.117.97): icmp_seq=2 ttl=56 time=3.57 ms
64 bytes from sin01s17-in-f1.1e100.net (173.194.117.97): icmp_seq=3 ttl=56 time=3.65 ms
64 bytes from sin01s17-in-f1.1e100.net (173.194.117.97): icmp_seq=4 ttl=56 time=3.79 ms
64 bytes from sin01s17-in-f1.1e100.net (173.194.117.97): icmp_seq=5 ttl=56 time=3.61 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4990ms
rtt min/avg/max/mdev = 3.546/3.637/3.799/0.116 ms
[ec2-user@ip-10-0-1-11 ~]$ wget google.com
--2015-09-02 05:22:01--  http://google.com/
Resolving google.com (google.com)... 173.194.117.96, 173.194.117.97, 173.194.117.98, ...
Connecting to google.com (google.com)|173.194.117.96|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.1’

index.html.1                                [ <=>                                                                              ]  10.97K  --.-KB/s   in 0.001s

2015-09-02 05:22:02 (12.7 MB/s) - ‘index.html.1’ saved [11230]

Может кто-нибудь указать, что не так с этой настройкой?

ДОПОЛНИТЕЛЬНАЯ ИНФОРМАЦИЯ: журналы показывают, что некоторые мусорные запросы попадают на мой веб-сервер всякий раз, когда я пингую общедоступный IP-адрес своего NAT-сервера. Я совершенно невежественен.

10.0.0.21 - - [02/Sep/2015:06:12:41 +0000] "??]7{]?zɳM?˗?9?G?68???l?xW???D?+?/?,?0?????#?'? ??$?(? " 400 -
10.0.0.21 - - [02/Sep/2015:06:12:41 +0000] "????]f???}???Q?ݹ?U}??????A?#?0D?+?/?,?0?????#?'? ??$?(? " 400 -
10.0.0.21 - - [02/Sep/2015:06:12:42 +0000] "???????{}?hA???????
                                                               j?W??P?ߠD?+?/?,?0?????#?'? ??$?(? " 400 -