nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

IPtables MAC & IP rule for internet access

This is a discussion on IPtables MAC & IP rule for internet access within the Networking, Firewalls and Security forums, part of the Mastering Servers category; Hello there, this is what i use to match both IP and MAC to deny access. Code: iptables -A INPUT ...


Go Back   nixCraft Linux Forum > Mastering Servers > Networking, Firewalls and Security

Linux answers from nixCraft.


Networking, Firewalls and Security No it's not a secret. Talk about firewalls and security issues.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13-07-2009, 12:33 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Fedora / RHEL 5
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Tawfiq is on a distinguished road
Default IPtables MAC & IP rule for internet access

Hello there,
this is what i use to match both IP and MAC to deny access.

Code:
iptables -A INPUT -p tcp -s 192.168.1.200 -m mac --mac-source 00:0F:EA:91:04:08 -j DROP
Now.. this is what i want to do.
* I would like to have a different file including the Matching IP and MAC addresses. and would like my firewall to deny access to any other combination to access the internet.

Q. what do i have to write in my firewall script.
Q. Please give me an example what should be the file like which consists the IP+MAC combination

Thanking you in advance,
Tawfiq
Reply With Quote
  #2 (permalink)  
Old 13-07-2009, 06:21 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Create two files ip.deny.txt:
Code:
192.168.1.2
192.168.2.5
202.54.1.0/24
mac.deny.txt:
Code:
00:0F:EA:91:04:08
00:0F:EA:91:04:03
Make changes as follows in your iptables shell script:
Code:
#!/bin/bash
IPDENY=/path/to/ip.deny.txt
MACDENY=/path/to/mac.deny.txt

for i in $IPDENY
do
  iptables -A INPUT -p tcp -s $i -j DROP
done 

for m in $MACDENY
do
 iptables -A INPUT -p tcp -m mac --mac-source $m -j DROP
done
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 14-07-2009, 09:24 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Fedora / RHEL 5
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Tawfiq is on a distinguished road
Default

hey man thats fantastic !! I will try it right away and will let you know how things are going with it.
Reply With Quote
  #4 (permalink)  
Old 14-07-2009, 11:49 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Fedora / RHEL 5
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Tawfiq is on a distinguished road
Default

Well.. something went wrong somewhere.
this is what i get when i run the script now,
Code:
[root@gateway ~]# sh /root/scripts/firewall
iptables v1.3.5: invalid mask `ip.deny.txt' specified
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.3.5: Bad mac address `/root/scripts/mac.deny.txt'
Try `iptables -h' or 'iptables --help' for more information.
and i put the right paths,
Code:
IPDENY=/root/scripts/ip.deny.txt
MACDENY=/root/scripts/mac.deny.txt
Reply With Quote
  #5 (permalink)  
Old 02-08-2009, 07:53 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Fedora / RHEL 5
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Tawfiq is on a distinguished road
Default

any insight at all about this please?
Reply With Quote
Reply

Tags
iptables , iptables block ips , iptables block mac address , linux firewall block ips


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
How do I connect two computers together to access the Internet? ibolah Computer Networking and Internet/broadband 3 14-10-2009 10:31 AM
IPtables - IP & MAC combined rule to define internet access Tawfiq Networking, Firewalls and Security 2 11-08-2009 11:04 PM
[Solved] ipTables rule to block a port for all internal IP Addresses except one pranaysharmadelhi Networking, Firewalls and Security 2 14-07-2009 09:49 PM
Iptables Two ISP Load Balancing Internet Connection please Networking, Firewalls and Security 2 23-06-2009 11:25 AM
unable to access ftp server via Internet explorer satishap Web servers 1 14-09-2008 09:26 PM


All times are GMT +5.5. The time now is 01:16 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38