Yes, I have already scoured the internet and read most of the popular IPTables / DNAT guides / pages / posts.
My Problem
Summary I have a VPC with several subnets. One subnet in particular requires an EIP for internet connectivity. I have a web server living in this subnet. I need to access it from behind a nat (also in the same subnet, has an EIP). I am attempting to set up my NAT so that incoming packets destined for a certain port are sent off to a different host (essentially i need DNAT)
Part 1: IN THE VPC:
I have SSH'd into my NAT instance through my WAN accessible SSH Proxy. Here's the default IPTables that the amazon NAT instance comes with. Nothing special, just a POSTROUTE rule as expected. The NAT instance has only one interface; eth0 (and lo, but let's pretend that does not exist)
[root@IP_NAT ec2-user]# iptables -t nat -L --line-numbers
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
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
Ok. Now let's add two port forwards, so my web server can be accessed behind the NAT
[root@IP_NAT ec2-user]# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination IP_WEBSERVER:80
[root@IP_NAT ec2-user]# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination IP_WEBSERVER:443
Right! Time to check my work:
[root@IP_NAT ec2-user]# iptables -t nat -L --line-numbers
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 DNAT tcp -- anywhere anywhere tcp dpt:http to:IP_WEBSERVER:80
2 DNAT tcp -- anywhere anywhere tcp dpt:https to:IP_WEBSERVER:443
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.us-west-1.compute.internal/16 anywhere
So, things look like they should work just fine. Except, they dont. :(. I can wget / telnet / ping / ssh my to my heart's content between the nat and the web server. I can telnet on some ports to my NAT, but others just time out. I have triple checked that the AWS Security Group governing the NAT instance allows the correct ports in and out. Just for testing, I allowed all traffic on all ports both in / out. I still have the same problem.
The webserver shows no activity on any of it's logs.
Here's a little bit of output from my local machine showing what has been bugging me all day:
LOCAL_USER@LOCAL_HOST:~$ telnet AWS_EIP 443
Trying AWS_EIP...
^C (time out, here)
LOCAL_USER@LOCAL_HOST:~$ telnet AWS_EIP 80
Trying AWS_EIP...
^C (time out, here)
LOCAL_USER@LOCAL_HOST:~$ telnet AWS_EIP 22
Trying AWS_EIP...
Connected to AWS_EIP.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.2
asd
Protocol mismatch.
Connection closed by foreign host.
So when I try to open a TCP connection on port 22, things work instantly. Why is my nat not 'listening' on port 443 or 80, despite iptables explicitly allowing traffic on these ports?
As a last bit of useful information, here's the sysctl.conf file:
[root@IP_NAT ec2-user]# cat /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
# Controls source route verification
net.ipv4.conf.default.rp_filter = 0
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 1
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
Any thoughts as to why packets don't even make it to my webserver?