LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 08-05-2010, 05:39 AM   #1
ekalavya
LQ Newbie
 
Registered: Feb 2009
Posts: 23

Rep: Reputation: 0
IP tables rule help


Hi,

We have following setup for Internet access through broadband connection:

1) FC4
2) Squid
3) Dansguardian
4) eth0 into our LAN
5) eth1 is on modem with static public ip

I want to allow certain IPs with Mac addresses and rest all to be stopped. In this regard, as new to iptables, please let me know with example based on the above said setup.

I tried with the following but in vain:

iptables -P INPUT DROP
/sbin/iptables -A INPUT -s xxx.xxx.x.xxx -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT

If i give second rule alone works but if any body changes their IP still they can access. If i put both the rules nobody are able to access Internet.

Thanks & regards,

Ekalavya
 
Old 08-05-2010, 06:33 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by ekalavya View Post
Hi,

We have following setup for Internet access through broadband connection:

1) FC4
2) Squid
3) Dansguardian
4) eth0 into our LAN
5) eth1 is on modem with static public ip

I want to allow certain IPs with Mac addresses and rest all to be stopped. In this regard, as new to iptables, please let me know with example based on the above said setup.

I tried with the following but in vain:

iptables -P INPUT DROP
/sbin/iptables -A INPUT -s xxx.xxx.x.xxx -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT

If i give second rule alone works but if any body changes their IP still they can access. If i put both the rules nobody are able to access Internet.

Thanks & regards,

Ekalavya


The problem here is that we do not know which rules you have in already, as i dont recall seeing you flush previous rules out...
 
Old 08-05-2010, 06:36 AM   #3
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
I never block/allow internet access through mac address through iptables but you can create mac base acl in squid to allow/deny particular mac address.

Code:
acl aclname arp macaddress
 
Old 08-05-2010, 06:49 AM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Since this is a router box you might want to put the rule in the FORWARD table not the INPUT table and a corresponding established,related rule also in FORWARD
 
Old 08-06-2010, 04:06 AM   #5
ekalavya
LQ Newbie
 
Registered: Feb 2009
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by sem007 View Post
I never block/allow internet access through mac address through iptables but you can create mac base acl in squid to allow/deny particular mac address.

Code:
acl aclname arp macaddress
i did as per your suggestion, but still if somebody changes mac address can still access.

Can you please share dansguardian and Squid configuration. As a paranoid measure, i want to implement this.

Thanks & regards,

Ekavalya
 
Old 08-06-2010, 05:23 AM   #6
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
For one thing, you don't want "iptables -P INPUT DROP" above anything that you want to have access. Iptables rules work like a waterfall. If a rule matches it is acted upon and the process stops. If there is no match, then it continues on to the next rule. Therefore you want to put this as the last line of your rules to make it a default catch all.

I second estabroo's comments that given your setup, you will want to put restrictions somewhere other than your INPUT table. Also, ip tables has functions that assist with routing and can be used to perform NAT, which may be beneficial to you for configuring a router.

Now lets look at your rule: -A INPUT -s xxx.xxx.x.xxx -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT.

As you pointed out, using just this has little effect IP address changes and it becomes useless. In the IP address (-s xxx....) you will need to specify the range of addresses that a host can be assigned (xxx.xxx.xxx.xxx/CIDR mask) OR guarantee that each host gets a particular IP address that doesn't change. By following this command with the -A INPUT -j DROP as a last rule, unless the mac address matches, it will get dropped.

As was also pointed out, implementing this through your proxy may be a better approach.

One important point to remember: this method will NOT be fool proof. It is possible to obtain the MAC addresses associated with an access point, especially if wireless devices are involved and then spoof as that mac address. It may be another hurdle for an attacker to get past, but do not put this in place and consider yourself secure. Continue to secure the rest of the network as if this feature were not even in place.
 
Old 08-09-2010, 11:42 PM   #7
ekalavya
LQ Newbie
 
Registered: Feb 2009
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Noway2 View Post
For one thing, you don't want "iptables -P INPUT DROP" above anything that you want to have access. Iptables rules work like a waterfall. If a rule matches it is acted upon and the process stops. If there is no match, then it continues on to the next rule. Therefore you want to put this as the last line of your rules to make it a default catch all.

I second estabroo's comments that given your setup, you will want to put restrictions somewhere other than your INPUT table. Also, ip tables has functions that assist with routing and can be used to perform NAT, which may be beneficial to you for configuring a router.

Now lets look at your rule: -A INPUT -s xxx.xxx.x.xxx -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT.

As you pointed out, using just this has little effect IP address changes and it becomes useless. In the IP address (-s xxx....) you will need to specify the range of addresses that a host can be assigned (xxx.xxx.xxx.xxx/CIDR mask) OR guarantee that each host gets a particular IP address that doesn't change. By following this command with the -A INPUT -j DROP as a last rule, unless the mac address matches, it will get dropped.

As was also pointed out, implementing this through your proxy may be a better approach.

One important point to remember: this method will NOT be fool proof. It is possible to obtain the MAC addresses associated with an access point, especially if wireless devices are involved and then spoof as that mac address. It may be another hurdle for an attacker to get past, but do not put this in place and consider yourself secure. Continue to secure the rest of the network as if this feature were not even in place.
Hi,

Thank you for your reply.

Can you please provide me eg. of iptables rule based on my scenario as explained by you.

Thanks & regards,

Ekalavya.
 
Old 08-10-2010, 03:34 PM   #8
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Noway2 View Post
For one thing, you don't want "iptables -P INPUT DROP" above anything that you want to have access. Iptables rules work like a waterfall. If a rule matches it is acted upon and the process stops. If there is no match, then it continues on to the next rule. Therefore you want to put this as the last line of your rules to make it a default catch all.
That's not how it works. That command sets the policy for the INPUT chain. There is no need to execute that command before or after any rule commands. Setting a chain's policy is not the same as implementing a rule in a chain.

FWIW, a catch all rule would look like this (example):
Code:
iptables -A INPUT -j DROP
That sort of rule would definitely need to go at the end of the chain.
 
Old 08-11-2010, 08:10 AM   #9
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Win32sux,

Thank you for catching my error. I read the original post as meaning that when he put that line in that everything was blocked and was thinking that it stopped everything, which one needs to be careful of with IPtables, and then mis-interpreted it as a defacto drop statement.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables: rule with RETURN target just after a rule with ACCEPT target Nerox Linux - Networking 6 09-04-2011 03:33 PM
IP Tables - help myubuntu Linux - Newbie 2 03-26-2010 12:56 PM
IP Tables Jeewhizz Linux - Security 3 02-26-2009 01:27 PM
IP Tables gjagadish Linux - Security 1 02-10-2006 11:49 AM
IP Tables help muru Linux - Security 3 09-27-2005 11:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration