Tuesday, May 20, 2008

Allowing An Access To Single Site And Denying All Other Sites Using IPTABLES Firewall on ubuntu

Allowing An Access To Single Site And Denying All Other Sites Using IPTABLES Firewall on ubuntu

Iptables is the name of the user space tool by which administrators create rules for the packet filtering
(both inbound and outbound) and NAT (Network Address Translation) modules. In this sceanrio we blocking all
the websites access except only one site. For example here we allowing only "google.com".

ping google.com
PING google.com (64.233.187.99) 56(84) bytes of data. (You will get the IP of that site Eg:-google)

iptables -A OUTPUT -p tcp -d ! 64.233.167.99 --dport 80 -j REJECT
iptables-save >/etc/iptables.rules
iptables-restore /etc/iptables.rules

For enabling this on every time reboot Please add the following entry on /etc/network/interfaces in the next line
of iface lo inet loopback
pre-up iptables-restore /etc/iptables.rule
iptables-restore <$FILE1 while read line do c=$(expr $c + 1) if [ $c -ne 3 ]; then echo $line>>temp.txt
else
echo $v>>temp.txt
fi
done < $FILE
rm -rf /etc/network/interfaces
cp temp.txt /etc/network/interfaces

finally run ./filname.sh

....
Sahab

No comments: