Firewall setup⚓︎
How to setup the UFW Ubuntu Firewall Configure after installing your application?
Ufw (uncomplicated firewall)⚓︎
Status: inactive
check ports in use⚓︎
-t TCP ports
-u UDP ports
-n numerical addresses instead of hosts
-l listening ports
-p PID and name of listener's process
This list will show you which ports are being used. Seeing port 80 & 443 are common. In the case of Ditto, it also uses port 53, but only locally, so it doesn't need access from the outside.
source: check listening ports
setup your firewall⚓︎
Default incoming policy changed to 'deny'
(be sure to update your rules accordingly)
Default outgoing policy changed to 'allow'
(be sure to update your rules accordingly)
sudo ufw allow from 127.0.0.1 to any port 5432
enable ufw⚓︎
So far, the ufw has been disabled. As long as the port you use to access the server is allowed, you should be ok to log back in.
However, you can test if you can log in by opening a separate terminal window, without closing the one you are in.
Once you are sure of your settings:
● ufw.service - Uncomplicated firewall
Loaded: loaded (/.../ufw.service; enabled; vendor preset: e>
Active: active
...
deeper dive on configuring firewall rules with UFW
configured ports list⚓︎
This command will list all the ports you have configured and where they are allow. Review it to make sure you have all the ones liste above.
To Action From
-- ------ ----
4036 ALLOW 127.0.0.1
5432 ALLOW 127.0.0.1
53 ALLOW 127.0.0.1
443/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
2140/tcp ALLOW Anywhere
443/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
2140/tcp (v6) ALLOW Anywhere (v6)
to delete a rule⚓︎
This command will display your list of ports, with a number next to it. You can use that number to delete specific items. If you are deleting more than one port, beware that you should run this command after deleting, as the numbers will change and shift upward.
To Action From
-- ------ ----
[ 1] 111 ALLOW IN Anywhere
[ 2] 53 DENY IN Anywhere
[ 3] 4036 ALLOW IN 127.0.0.1
[ 4] 5432 ALLOW IN 127.0.0.1
...
To Action From
-- ------ ----
[ 1] 53 DENY IN Anywhere
[ 2] 4036 ALLOW IN 127.0.0.1
[ 3] 5432 ALLOW IN 127.0.0.1
...