Since my SSH attempts were showing port 22: connection refused , I tried
sudo ufw allow 22
Even after that, I am not able to SSH. Now I don’t want to have port 22 as a vulnerability and want to set to the default condition. Which command to use for that in 18.04 ? Thanks.
The default default rule is to deny all incoming. So if you haven’t changed the default rule, then simply deleting the rule in question should close the port again.
Now all you have to do is the following:
ufw status numbered | grep "] 22"
Find the number within the [brackets] that is assigned to the 22 ALLOW IN and don’t forget it. Then:
ufw delete 123
replacing 123 with the number you remember from the previous command.
I thought of resetting the whole ufw to default. Then wondered how Firefox, other browsers and Transmission will work. If all incoming is blocked, how will these work ?
As already explained there, your router already blocks all incoming traffic, if you did not fiddle around with the Port rules.
Only servers need open ports, that’s why all the websites you visit are on machines that have open ports. You only need outgoing ports for that, which the computer handles automatically for you, but you don’t need any open incoming ones for that.
Similar with Torrent, although you can have an open port which would help Torrent work better, you don’t need one.
You only need open ports if peers are directly connecting to you.
That said, sometimes your router automatically opens incoming ports for you, but that depends on the program requesting the open port, as well as the router’s capability and permissions to handle UPnP requests.