How do I allow certain ips and block all other connection in iptables?
I wrote a blog post on basic Iptables rules for the desktop user a long time ago and you should probably read it, and its linked article on Stateful firewall design. But pre kernel 2.6.39 (which includes
First handle state's that we know we want to accept or drop, and interfaces.
If you just want to do an allow by IP only, without state
you are likely to run into problems doing this though, and I suggest using state to make your life easier. For example, not allowing
Here's an (untested!) example that blocks incoming connections only. Connections over the loopback interface, coming from 192.168.3.x, ICMP, or to the SSH port are allowed. All other connections are rejected.