Score:0

How to enable a specific port on Ubuntu version 22 so that it is accessible to outside world?

in flag

How to enable a specific port on Ubuntu version 22 so that it is accessible to outside world?

I am already logged into the server through ssh using port 22 and able to successfully execute all the commands.

I have enabled the ufw firewall and also enabled ports 22, 80 and 22786.

Both 22 and 80 are fine and accessible but not able to access 22786 from outside world.

Do I need to change some other firewall settings to enable port 22786 ?

admin@prod:~$ sudo ufw status numbered

Status: active
     To                         Action      From
     --                         ------      ----
[ 1] 22786                      ALLOW IN    Anywhere
[ 2] 22                         ALLOW IN    Anywhere
[ 3] 80                         ALLOW IN    Anywhere
[ 4] 22786 (v6)                 ALLOW IN    Anywhere (v6)
[ 5] 22 (v6)                    ALLOW IN    Anywhere (v6)
[ 6] 80 (v6)                    ALLOW IN    Anywhere (v6)

admin@prod:~$ sudo netstat -plunt

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1619/nginx: master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      834/sshd: /usr/sbin
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      927/sshd: admin@pts
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      784/systemd-resolve
tcp6       0      0 :::80                   :::*                    LISTEN      1619/nginx: master
tcp6       0      0 :::22                   :::*                    LISTEN      834/sshd: /usr/sbin
tcp6       0      0 ::1:6010                :::*                    LISTEN      927/sshd: admin@pts
udp        0      0 127.0.0.53:53           0.0.0.0:*                           784/systemd-resolve

I installed Nginx manually and was able to access it using http://ipaddress

But when I check through this online tool (https://www.yougetsignal.com/tools/open-ports/), it shows both 22 and '80' ports are enabled but 22786 is closed.

22 port was already open when I got this host and 80 got enabled after I installed Nginx and added it to ufw using sudo ufw allow 80 command. I used sudo ufw allow 22786 command to enable this port too but no luck.

Scott Stensland avatar
ir flag
the process which opens up a port can control from where it accepts incoming connections ... perhaps your process which you cannot access from an external box has such a host:port definition ... details see https://stackoverflow.com/questions/41028709/only-accept-http-connections-from-localhost-in-go
Nital avatar
in flag
Removed images as recommended
Nital avatar
in flag
@Nmath - This is a rented VPS and not my home internet connection. Ubuntu v22 is installed on that VPS
Nital avatar
in flag
I am sorry, I am not from networking domain but just trying to answer your questions. No I did not set up Port Forwarding on my router. I am assuming you mean WiFi Router here.
in flag
According to your netstat output, there is nothing actually listening on that port.
Nital avatar
in flag
Correct - I want to deploy an app using Kubernetes that will be listening to that 22786 port
Nital avatar
in flag
https://ubuntu.com/download/server - The latest version can be seen here. I am using ubuntu 22.04
Score:0
br flag

It is important whether there is an application on the server that listens on TCP port 22786.

Please, attach here a reply from the netstat command on your server.

sudo netstat -lntp

You should also see port 22786 in the list of listening TCP ports.

If the netstat is missing, install net-tools.

sudo apt-get update
sudo apt-get install net-tools

You can try netcat nc as a replacement listening application if you are missing the necessary application on port 2276 for your test.

sudo nc -l -p 22786 -k

In a terminal window other than the one where the nc runs, repeat the netstat.

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.