LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-18-2010, 06:34 AM   #1
waranha
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Rep: Reputation: 0
firewall script with MAC and IP


I have a file called mac.txt and inside it contains the following: IP and MAC,
192.168.0.10;F0:AF:FF:FE:FA:00

My script for firewall is as follows:

#!/bin/bash
for i in `cat /root/mac1.txt`;
do
MACSOURCE=`echo $i | cut -d ';' -f1`
IPSOURCE=`echo $i | cut -d ';' -f2`
iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
done
iptables v1.4.3.1: Bad mac address "192.168.0.10"
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: host/network `F0:AF:FF:FE:FA:00' not found
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: Bad mac address "192.168.0.10"
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: host/network `F0:ADF:FF:FE:FA:00' not found
Try `iptables -h' or 'iptables --help' for more information.
 
Old 02-18-2010, 08:45 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,620

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by waranha View Post
I have a file called mac.txt and inside it contains the following: IP and MAC,
192.168.0.10;F0:AF:FF:FE:FA:00

My script for firewall is as follows:
Code:
#!/bin/bash
for i in `cat /root/mac1.txt`;
do
MACSOURCE=`echo $i | cut -d ';' -f1`
IPSOURCE=`echo $i | cut -d ';' -f2`
iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
done
iptables v1.4.3.1: Bad mac address "192.168.0.10"
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: host/network `F0:AF:FF:FE:FA:00' not found
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: Bad mac address "192.168.0.10"
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.3.1: host/network `F0:ADF:FF:FE:FA:00' not found
Try `iptables -h' or 'iptables --help' for more information.
Ok...is there a question in here somewhere, or should we guess? And please put your code in CODE tags...

Based on the errors you're getting, you have syntax errors, because you're putting things in the wrong places. You're clearly defining MACSOURCE as field 1 (-f1), when your input has field 1 as an IP address. Did you do any debugging, or try anything to resolve this?
 
1 members found this post helpful.
Old 02-18-2010, 10:00 AM   #3
waranha
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
I need the output of the command to iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE-j ACCEPT.=> (iptables -t filter -A FORWARD -d 0/0 -s 192.168.0.10 -m mac --mac-source 00:xx:yy:zz:99:88 -j ACCEPT).

I need $ IPSOURCE that is in the first column and $ MACSOURCE the second column


Another script to test :

>for i in `cat /root/mac.txt`;
>do
>
>MACSOURCE=`echo $i | cut -d ';' -f1`
>IPSOURCE=`echo $i | cut -d ';' -f2`
>
>echo $MACSOURCE
>echo $IPSOURCE
>done



and the script is ok
 
Old 02-18-2010, 11:02 AM   #4
waranha
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
that's OK . Changed my script :

> for i in `cat /root/mac.txt`;
> do
> IPSOURCE=`echo $i | cut -d \; -f1`
>MACSOURCE=`echo $i | cut -d \; -f2`
>iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
>iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
>iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
>iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
>done

Thanks to all
 
Old 02-18-2010, 11:05 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,620

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by waranha View Post
that's OK . Changed my script :

> for i in `cat /root/mac.txt`;
> do
> IPSOURCE=`echo $i | cut -d \; -f1`
>MACSOURCE=`echo $i | cut -d \; -f2`
>iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
>iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
>iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
>iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
>done

Thanks to all
Right...that's what I suggested in my first post.
 
1 members found this post helpful.
  


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
firewall script with MAC and IP waranha Linux - Kernel 1 02-18-2010 07:21 AM
The best firewall, with ip and mac blocks? rowebil Linux - Security 9 03-20-2009 09:12 AM
PIX firewall MAC address trebek Linux - Networking 2 08-12-2005 05:36 PM
MAC address filtering firewall? gigaah Linux - Security 5 06-07-2004 11:05 AM
slackware's /etc/rc.d/rc.firewall equivalent ||| firewall script startup win32sux Debian 1 03-06-2004 09:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:20 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