damp
By:
damp

Opening ports on my server

October 3, 2014 38.9k views

Hi

I have tried to follow this guide here (How To Set Up a Firewall Using IPTables on Ubuntu 14.04) and have done everything this tutorial said. But still when I scan my server with nmap <myserverip> i still only get port 22 and port 80 as open. I need to open port 50010 for a service I am trying to create, but I see no way for me to open this port.

sudo iptables -L:
Chain INPUT (policy ACCEPT)
target prot opt source destination

ACCEPT all -- anywhere anywhere

ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:50010

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Answers will be greately appreciated!

3 Answers

Ports are open by default.

The port won't be considered "open" until something is listening on it. Your firewall config looks right so just install the service and run it and you should be good to go. You might have to configure it to listen on 0.0.0.0 instead of 127.0.0.1 or localhost, but that depends on the service's defaults.

So for those of you still having a problem, the answer is simple. Apache needs a rule to allow traffic through the port. First find your port lsof -i :5000 (5000 is the port in question).

This will give you
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
app 2850 root 3u IPv4 22462 0t0 TCP *:5000 (LISTEN)

As you can see we are listening to 5000 with TCP connection. Now just add the rule to apache:
sudo ufw allow 5000/tcp. This will tell the firewall (ufw) to let traffic through. Now you should be okay to use the http://<yourport>:5000/path/to/service. Good Luck.

Have another answer? Share your knowledge.