aa333
aa333

Reputation: 2576

Check if port forwarding worked for node server on AWS machine

I have deployed a node application that listens to port 5000 on a free usage tier ubuntu machine from AWS.

I've followed suggestions from: How to start node.js on port 80 on a linux server? and from: Best practices when running Node.js with port 80 (Ubuntu / Linode)

Answers to both these questions suggest port forwarding and I have done the same. But my server still doesn't respond to requests on port 80. Is there a way I can check if the port forwarding was successful?

The permission settings to listen to HTTP requests have been setup through the AWS console. Also there is nothing listening to port 80 on the machine as of now. netstat -l | grep :80 comes up empty.

The server runs fine if I access it as: http://<elastic-ip>:5000

Upvotes: 2

Views: 1455

Answers (1)

Ben Whaley
Ben Whaley

Reputation: 34426

You will not see port 80 listening since there is no daemon using that socket; the kernel is performing a packet redirect.

To check how many packets traversed the port forwarding rule you set up, inspect the PREROUTING chain on the nat tables with sudo iptables -t nat -L PREROUTING -n -v. It will show output like:

Chain PREROUTING (policy ACCEPT 15 packets, 1226 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3   180 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 3000

If you are testing from localhost, you must also redirect on OUTPUT since PREROUTING isn't used by the loopback interface. Do that with

iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 3000

And of course, check that port 80 is open to allow external traffic.

Upvotes: 1

Related Questions