DEV Community

Médéric Burlet for Pixium Digital

Posted on

Listen on port 80 for node in linux

Node Permission Denied

Today I came across a node error when trying to run a simple express server on a amazon ec2.

Error: listen EACCES: permission denied 0.0.0.0:80

After some commands and research I realized that Linux architechture by default only lets ports lower than 1024 be listened by root.

This means that for running applications such as node which, should not be ran as root, we need to create a port redirect.

Using iptables to fix it

iptables is a user-space utility program that allows a system administrator to configure the tables provided by the Linux kernel firewall.

We will create a redirect of port 80 to 8080 in our scenario.

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

To check if the route has been added successfully you can execute the following command:

sudo iptables --table nat --list

You should see something like this:

REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080

Top comments (0)