Search code examples
node.jsexpressfirewalliptables

Unable to access express/node server on port 3001 despite enabling via firewall-cmd


I've been searching around this morning trying to figure out how to resolve my issue but nothing appears to suit my situation or solve my problem and so here I am.

I have a server running on CentOS Linux release 7.5.1804 (Core) and I have installed node v10.11.0 in order to host a website. I have a domain foo.ca whereby I have two separate web servers running (one for client, one for server). The client runs on port 3000, and I used iptables to forward port 80 to port 3000 so I can actually view my website without explicitly listing the port (i.e. by entering foo.ca in the address bar)

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

This works fine, and I can see foo.ca

My problem arises when I try to access the server which is running on port 3001. I have enabled the port via tcp using firewall-cmd:

sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent
sudo firewall-cmd --zone=public --add-port=3001/tcp --permanent
sudo firewall-cmd --reload

If I type foo.ca:3001 chrome tells me the site can't be reached, foo.ca took too long to respond.

I tested port 3001 via an online tool and it says that it is open, I also checked netstat:

netstat -tuplen
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      995        12161      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          12066      -
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      1000       56647615   4926/node
tcp        0      0 0.0.0.0:3001            0.0.0.0:*               LISTEN      1000       56671635   6195/node

Some online suggestions included using 0.0.0.0 rather than localhost but as you can see I already have that implemented. I don't really know what my options are at this point, I've tried enabling the port via iptables as well but I am not sure that did anything:

iptables -A INPUT -p tcp --dport 3001 -j ACCEPT

One last thing, my express server code is like so:

const express = require('express')
const app = express()
const port = 3001

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, '0.0.0.0', () => console.log(`Example app listening on port ${port}!`))

And I run it like node test

Anyone have any ideas? I'm not much of a network guru


Solution

  • The solution was my network was blocking it for some reason