@karantaneja
Since you’re using Ubuntu, you have two main firewall options that are bundled in with the OS – one is ufw
and the other is iptables
(ufw
is the easier of the two when it comes to usage).
You can check the status of ufw
by running ufw status
. If it shows as disabled, then there’s no active firewall running and you should be able to use any port that you choose.
If ufw
is active, then you can open a new port using ufw allow port/protocol
where port
is the port that you’re wanting to open and protocol
is the protocol you want to allow access over.
When it comes to protocol, you have two options, udp
and tcp
– tcp
is the most common one that you’ll use, so if you wanted to open up port 444 (for example), you could run:
ufw allow 444/tcp
If ufw
is disabled, I’d recommend setting it up. First thing I recommend is running ufw disable
just to make sure it’s really disabled. Afterwards, we’ll reset the rules.
ufw reset
Now we have a clean slate. What I recommend now is setting up a deny all, except those we allow type policy.
Deny ALL Incoming Requests
ufw default deny incoming
Allow ALL Outgoing Requests
ufw default deny incoming
Allow Specific Ports
We need SSH (Port 22), HTTP (Port 80), and HTTPS/SSL (Port 443), so we’ll start with those:
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
Now, if you want to open port 444, we’ll add that too:
ufw allow 444/tcp
Enable ufw
ufw enable
It’ll ask you to confirm, hit y
and then enter. You’re firewall is now all setup :-).