UFW Firewall – How to Deny Incoming Connections Except for One IP

debianfirewalllinuxportufw

I want to deny all incoming connections to port 6677 except for one ip-address (so it can only be reached from a docker container running on the host, the port should not be accessible from "outside").
Everything else should be allowed (ufw default allow outgoing, ufw default allow incoming).
How can I do this with UFW firewall?

With nftables I did something like this:
ip saddr != 172.19.0.2 tcp dport 6677 drop

Thank you

Best Answer

You can try use ufw allow from 172.19.0.2 to any port 6677

But as far as I know, whenever you launch the docker container it runs on a different IP unless you fix the IP.