/

Automation of IP and MAC Address firewalling with bash script

Since there is an interesting question from one member of a mailing list that I follow, what if our clients numbered many tens or hundreds. The important thing is, we have a list of IP Address and MAC Address client is connected. By using a few simple lines of bash script, we can make the automation.

Here are the steps:

1. Create a file called rc.iplock in the directory / etc / rc.d / with the following contents:

#! / Bin / bash
# Bash script Lock, IP Address and MAC Address
iptables = "/ sbin / iptables" # path to iptables
files = "/ etc / rc.d / list.txt" # path to list the IP Address and MAC Address
device = "eth1" # ethernet devices to the client
lockall = "yes" # yes | no, yes if you register all of the IP & MAC Address
# If not, write no.
# Yes to the first method, no to the second method


if [$ lockall = "yes"]; then
$ Iptables-I PREROUTING-t nat-i $ device-j DROP
cat $ files | while read ip_address mac_address; do
$ Iptables-I PREROUTING-t nat-i $-s $ ip_address devices
-M mac - mac-source $ mac_address-j ACCEPT
$ Iptables-I FORWARD-i $ device-s! $ Ip_address
-M mac - mac-source $ mac_address-j DROP
$ Iptables-t nat-I PREROUTING-s! $ Ip_address
-M mac - mac-source $ mac_address-j DROP
done
Elif [$ lockall = "no"], then
$ Iptables-I PREROUTING-t nat-i $ device-j ACCEPT
cat $ files | while read ip_address mac_address; do
$ Iptables-I FORWARD-i $ device-s! $ Ip_address
-M mac - mac-source $ mac_address-j DROP
$ Iptables-t nat-I PREROUTING-s! $ Ip_address
-M mac - mac-source $ mac_address-j DROP
done
fi

echo "Locking IP address and Mac Address ..."
# End script


2. Create a file called list.txt in the directory / etc / rc.d / with the format of writing as follows:

" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">

Warning! Do not add any lines or anything other than the format of the above sentence!

Example contents of / etc / rc.d / list.txt for three clients:

192.168.1.5 00:89: CD: 64:01: EF
192.168.1.20 00:90: DD: 14:11: CF
192.168.1.14 00:40: EE: 21:26: GE


3. Set file rc.iplock order in execution:

chmod + x / etc / rc.d / rc.iplock


4. Add in the file / etc / rc.d / rc.local in order to be executed at start-up:

/ Etc / rc.d / rc.iplock


5. Run:

/ Etc / rc.d / rc.iplock

6. Done! Congratulations you can star = P



Related Post



RSS Feed

0 Comments for Automation of IP and MAC Address firewalling with bash script

Leave a comment!

design by tikimedia © 2010 | Converted to Blogger by Blogger Templates | I Powered by Blogger