Score:0

Cannot connect to home ubuntu server using public static IP address outside of LAN

cr flag

Running ubuntu 22.04

I have a test express.js app running and I can connect to it via 192.168.1.6:3000 as local ip and also as (static public IP):3000 but only from devices connected to my WiFi.

As soon as I try to access the (static public IP):3000 with mobile data, I receive an error CONNECTION_REFUSED with an HTTP error code of 102

root@server:~# ss -lntu
Netid           State            Recv-Q           Send-Q                          Local Address:Port                      Peer Address:Port           Process
udp             UNCONN           0                0                               127.0.0.53%lo:53                             0.0.0.0:*
udp             UNCONN           0                0                          192.168.1.6%enp1s0:68                             0.0.0.0:*
tcp             LISTEN           0                4096                            127.0.0.53%lo:53                             0.0.0.0:*
tcp             LISTEN           0                128                                   0.0.0.0:22                             0.0.0.0:*
tcp             LISTEN           0                128                                      [::]:22                                [::]:*

I've tried messing with the firewall, enabled, disabled and also adding port 3000 to exceptions list.

root@server:~# ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 80/tcp                     ALLOW IN    Anywhere
[ 2] 443                        ALLOW IN    Anywhere
[ 3] 3000                       ALLOW IN    Anywhere
[ 4] 3000                       ALLOW IN    0.0.0.0
[ 5] 80/tcp (v6)                ALLOW IN    Anywhere (v6)
[ 6] 443 (v6)                   ALLOW IN    Anywhere (v6)
[ 7] 3000 (v6)                  ALLOW IN    Anywhere (v6)

  • I've tried setting up the server to listen to port 3000 but apparently not to much avail.
  • I've set up port forwarding from my router settings and that's why my app loads at all with the public static IP address

In addition, regardless if logged in as root or not, I seem to be getting denied permission to run on port 80.

root@server:/home/user/testsite/testapp2# npm run start

> start
> node index.js

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied 0.0.0.0:80
    at Server.setupListenHandle [as _listen2] (node:net:1446:21)
    at listenInCluster (node:net:1511:12)
    at Server.listen (node:net:1599:7)
    at Function.listen (/home/user/testsite/node_modules/express/lib/application.js:635:24)
    at Object.<anonymous> (/home/user/testsite/testapp2/index.js:9:5)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1490:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EACCES',
  errno: -13,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 80
}

I have no idea what the issue is and 8 hours of googling confirmed I am not asking the right questions. I think maybe the server itself is refusing the WAN connection, but I'm really new to this and I don't know how to troubleshoot properly.

Update: My port forwarding options I've set up so far for testing the webserver

enter image description here

ru flag
is the server behind a router? If so then you should never have to touch your server's settings, you need to port forward from your router. Your NPM error also indicates that you're not allowed to bind to port 80. Is this an actual full server or something like a WSL environment?
Newbie avatar
cr flag
Yes, server is connected to a router and yes it's a physical server at home and not a virtual environment. I have set up port forwarding and now I have access to server both via local 192.168.1.6:3000 and 46.xx.xx.xx:3000 but ONLY if I'm connected to my Wifi. I have an actual app but I decided to simplify everything to get to the bottom of the issue and after I sort this out I will deploy.
ar flag
Check your port forwarding setting and add it to your question.
Newbie avatar
cr flag
Updated, I've set it up for 80, 3000, and 5000. I presume the public ports are the ones you enter as an end user and the private ones are the ones you are running on the server. In addition, I don't have apache or nginx or any other server hosting software installed so I don't know if there's extra default configurations I'm missing.
Artur Meinild avatar
vn flag
Hello! While this might be correct, it hasn't got anything to do with Ubuntu at all ...
Score:0
cr flag

You should not have port forwarding with the same port going to different internal LAN ip addresses, one port per IP, otherwise it doesn't work.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.