I am setting up ufw using ansible on a remote ubuntu server.
I am initially setting up ufw with ufw enable policy allow to enable ssh access.
After that I'm doing ufw allow from x.x.x.x to any port 22 to allow ssh from a specific port
After that I fire in the command ufw deny ssh to deny ssh from all other places except the above IP.
I then restart ufw services
But, this does not prevent ssh at all. I'm able to access the server from every place via ssh.
How can I block all ports after settings ufw policy to allow.
71 Answer
I would configure ufw this way:
first, make sure ufw is inactive so you do not cut off yourself
sudo ufw status # should say inactive if not, turn it offthan configure (note that order is critical):
sudo ufw default deny incoming # applied at the end of the last rule
sudo ufw default allow outgoing
sudo ufw allow from x.x.x.x to any 22these rules should do it as the only ssh from your specified IP is allowed.
then turn on the firewall by:
sudo ufw enable 2