-1

I use AWS create 1 VPC (10.0.0.0/16) have 2 subnet and create 2 EC2 Instance, 1 NAT Instance (10.0.1.1) on Public Subnet (10.0.1.0/24) and 1 WebService Instance (10.0.2.1) on Private Subnet (10.0.2.0/24).

I setup everything ok but have problem when forward port 80 from NAT Instance to WebService Instance.

If I use the Iptables config on NAT Instance like below, I can ping to anything but can not download or install anything on WebService Instance

>*nat
>
>:PREROUTING ACCEPT [1:60]

>:POSTROUTING ACCEPT [0:0]

>:OUTPUT ACCEPT [0:0]

>-A POSTROUTING -o eth0 -s 10.0.2.0/24 -j MASQUERADE

>-A PREROUTING -i eth0 -p tcp --dport 3939 -j DNAT --to-destination 10.0.2.1:3939

>-A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.0.2.1:80

>COMMIT

>*filter

>:INPUT ACCEPT [0:0]

>:FORWARD ACCEPT [0:0]

>:OUTPUT ACCEPT [2138:136749]

>-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 

>-A INPUT -p icmp -j ACCEPT 

>-A INPUT -i lo -j ACCEPT 

>-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

>-A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT 

>COMMIT


And when I open port 8888 and change

>-A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.0.2.1:80

to

>-A PREROUTING -i eth0 -p tcp --dport 8888 -j DNAT --to-destination 10.0.2.1:80

I can do anything but I need use 8888 port after domain for access my website.

Anyone have solution for use 80 port on NAT instance forward to 80 port on WebService Instance?
Amida
  • 9
  • 3

1 Answers1

0

I'm not very familiar with IpTables but I think you're trying to use the NAT to accept requests from the internet and forward them to your webserver. The NAT instance in a VPC is usually there to handle outbound traffic from your instances in private subnets out to the internet. You don't use it to forward requests inbound.

You would normally use an AWS service like Elastic Load Balancing or assign the instance an Elastic IP. See http://aws.amazon.com/elasticloadbalancing/ and http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html

David Fevre
  • 844
  • 6
  • 10