How do I allow only certain ips via iptables to connect?
Want to disallow all connections to the server unless connecting from a specific ip(s).
Any example of how to do this? And would I just append it to the end of my iptables file or no? I have current rules in there now that were automatic and something with fail2ban as well.
6 Replies
The order of your rules depend strictly on which order you want them processed. Being an IP filter, it can go at the beginning.
Let me know if I can help you more.
iptables -A INPUT -i eth1 -s 10.50.0.0/16 -j ACCEPT
Ok.
1 how do I know what goes after -i (the eth1 part). How do I know if it's eth1 or eth0?
-s can be a straight ip without subnet?
That's all I need?
@arachn1d:
So at the beginning I have to do something like:
iptables -A INPUT -i eth1 -s 10.50.0.0/16 -j ACCEPT
Ok.
1 how do I know what goes after -i (the eth1 part). How do I know if it's eth1 or eth0?
-s can be a straight ip without subnet?
That's all I need?
If you look at the iptables manual
You can use "ip link" to list the interfaces on your server and find out which one should be added after -i.