3

This is the weirdest thing ever. I've configured my AWS Elastic Beanstalk environment's proxy server setting to none instead of nginx or apache, to reduce the server overhead, and since I don't need the caching.

However, the most peculiar thing happened. The server is able to accept connections on port 80 and forward them to my Node.js app running on 8080, even though no service is apparently listening on port 80! I verified with the following commands:

  • sudo lsof -i :80 - no output
  • sudo iptables -L - no forward rules
  • sudo netstat -an | grep :80 | grep LISTEN - no processes listening on port 80

Running curl http://localhost/ on the actual server works, so this is not a case of tricky Elastic Load Balancer forwarding rules.

How does AWS do it? How do they forward traffic without a process listening on :80 or an iptables forward rule?

8

It's a NAT rule.

iptables -L -t nat

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination    

Thanks to @slims_s from reddit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.