Linode Forum
https://forum.linode.com/

How do I allow only certain ips via iptables to connect?
https://forum.linode.com/viewtopic.php?f=19&t=9827
Page 1 of 1

Author:  arachn1d [ Wed Feb 27, 2013 4:14 pm ]
Post subject:  How do I allow only certain ips via iptables to connect?

Have a staging server.

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.

Author:  gparent [ Wed Feb 27, 2013 4:21 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

I googled your question verbatim and this was the 2nd result:

http://serverfault.com/questions/161401 ... h-iptables

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.

Author:  arachn1d [ Wed Feb 27, 2013 4:27 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

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?

Author:  gparent [ Wed Feb 27, 2013 4:32 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

arachn1d wrote:
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 will find -i and -s in the PARAMETERS section. It should explain how these two options work in detail.

You can use "ip link" to list the interfaces on your server and find out which one should be added after -i.

Author:  vonskippy [ Wed Feb 27, 2013 7:49 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

If you're going to open up /16 ranges - why bother locking it down?

Author:  arachn1d [ Mon Mar 04, 2013 7:05 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

I only want to allow one ip but I can't seem to figure it out. :(

Author:  vonskippy [ Mon Mar 04, 2013 7:30 pm ]
Post subject:  Re: How do I allow only certain ips via iptables to connect?

If you want step by step, it'd help if you told people what Distro you're using.

Page 1 of 1 All times are UTC-04:00
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/