UFW blocking port 8001 until I login to ubuntu

February 10, 2017 406 views
Firewall Linux Basics WordPress Nginx Ubuntu 16.04

Ubuntu Desktop 16.04 LTS, running on Hyper-V on windows 10 pro x64
I have two wordpress sites, one is on port 80 with server_name directive pointing to root
The other is running on port 8001. I don't remember why I configured it this way but I'm ok with changing it. The problem seems to be that even though I have all the ports open I have to login to ubuntu before the firewall rule kicks in . My port 80 site works fine but the 8001 gives chrome a sad page icon until after the login.

[02/11/2017 12:25:50 AM] Status: Enabled
[02/11/2017 12:25:37 AM] Status: Disabled
[02/11/2017 12:25:20 AM] Status: Enabled
[02/10/2017 07:35:52 AM] Appending new rules: ufw allow in 81 > Skipping adding existing rule | Skipping adding existing rule (v6)
[02/10/2017 07:35:52 AM] Appending new rules: ufw allow in 8001 > Skipping adding existing rule | Skipping adding existing rule (v6)
[02/10/2017 07:35:52 AM] Appending new rules: ufw allow in 81 > Rule added | Rule added (v6)
[02/10/2017 07:35:52 AM] Appending new rules: ufw allow in 8001 > Rule added | Rule added (v6)
[02/10/2017 07:35:52 AM] Deleting previous rules: 3 ufw --force delete 3 > Rule deleted
[02/10/2017 07:35:52 AM] Deleting previous rules: 6 ufw --force delete 6 > Rule deleted (v6)
[02/10/2017 07:35:51 AM] Status: Enabled
[02/10/2017 07:35:50 AM] Changing profile: Public
1 Answer
jtittle February 11, 2017
Accepted Answer

@iburnthings

What I would recommend doing, just to make sure we get the correct setup, is running

ufw disable

Then

ufw reset

The above stops ufw and then resets all rules. With a clean slate, we setup our default policies first.

ufw default deny incoming \
&& ufw default allow outgoing

With those rules in place, we then add the rules we need to work for whatever our purposes are. To start, I recommend allowing SSH in first.

ufw allow 22/tcp

We can then allow application-specific ports, such as 80, 443, 8001, etc. I'll start with those three.

ufw allow 80/tcp \
&& ufw allow 443/tcp \
&& ufw allow 8001/tcp

We could also run just one command (copy and paste directly)

ufw disable \
&& ufw reset \
&& ufw default deny incoming \
&& ufw default allow outgoing \
&& ufw allow 22/tcp \
&& ufw allow 80/tcp \
&& ufw allow 443/tcp \
&& ufw allow 8001/tcp

Now, if you need to add any other ports, now's the time to go ahead and add them. If nothing more needs to be added, we can then run

ufw enable

When prompted to confirm, type y, hit enter, and ufw is active once again.

The benefit to the above is outgoing connections are always allowed, though only the ports you define are permitted to connect (i.e. incoming).

  • the script didn't work in one shot in bash but I removed the operators and executed them fine. That seems to have resolved my issue. Thanks for the quick response.

Have another answer? Share your knowledge.