How to open a port?

Your iptables output shows that no port is blocked.

So the question is: Is anything listening on port 8000? If nothing is listening on a port but the port is not blocked by a firewall nmap will report it as closed. From here:

closed

A closed port is accessible (it receives and responds to Nmap probe packets), but there is no application listening on it. They can be helpful in showing that a host is up on an IP address (host discovery, or ping scanning), and as part of OS detection. Because closed ports are reachable, it may be worth scanning later in case some open up. Administrators may want to consider blocking such ports with a firewall. Then they would appear in the filtered state, discussed next.

So the nmap report: "996 closed ports" actually say that those ports are not blocked by a firewall but no program is listening on them. nmap reports a blocked port as filtered:

filtered

Nmap cannot determine whether the port is open because packet filtering prevents its probes from reaching the port. The filtering could be from a dedicated firewall device, router rules, or host-based firewall software. ...

So if you put an application in listening state on port 8000 it will likely show up in the output of nmap. You can do this if you just run python3 -m http.server or python -m SimpleHTTPServer on the machine on which you are trying to open the ports, this will put a HTTP server listening on port 8000. Then run nmap again to scan the machine.

UPDATE:

Your netstat output has this line:

tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      4134/python  

That means your python program is only listening on localhost (127.0.0.1), so it is only accessible from localhost, not from outside. The program has to listen on the IP of your network adapter or on the universal 0.0.0.0 IP. The problem is what I wrote above, no program is listening on the 8000 port (from the outside world) so nmap says it is closed.


To Enable Port In Ubuntu

sudo ufw allow <port_nr>

e.g to allow ssh

sudo ufw allow 22

sudo ufw enable

Thats IT

Tags:

Firewall