need help with ufw

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.

7

1 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 off

than 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 22

these rules should do it as the only ssh from your specified IP is allowed.

then turn on the firewall by:

sudo ufw enable
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like