Linux Forums - Linux Help,Advice & support community:LinuxSolved.com

Network Troublshooting => General Networking Support in Linux => Topic started by: ronaldjayr_jover on August 17, 2005, 01:27:02 AM

Title: How to block certain IPs and Website on Iptables
Post by: ronaldjayr_jover on August 17, 2005, 01:27:02 AM
Good day!!!

I have a proxy server, 2 lancard. 1 Lancard is connected to a Public IP DSL and one on our Private Network. I want to an IP add or a website on the 1st Lancard(Public) and at the same time block from the 2nd Lancard(Private network) that IP add or Website.

Thanks... :)
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on August 17, 2005, 10:33:45 AM
hmm.. that is so simple , infact I have answered that so many times already.

iptables -A FORWARD -d domain.com -j DROP

and ..

iptables -I INPUT -s XXX.XXX.XXX.XXX -j DROP
Title: How to block certain IPs and Website on Iptables
Post by: ronaldjayr_jover on August 18, 2005, 12:18:12 AM
Hi Ricky,

 Thanks for the reply, gladly appreciate it.

  :D
Title: How to block certain IPs and Website on Iptables
Post by: veno on September 03, 2005, 04:10:04 PM
Quote from: "Ricky"
hmm.. that is so simple , infact I have answered that so many times already.

iptables -A FORWARD -d domain.com -j DROP

and ..

iptables -I INPUT -s XXX.XXX.XXX.XXX -j DROP


ok how do i release the ip that i firewall?
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on September 04, 2005, 07:24:07 AM
you can add them in rc.local file so that it get executed everytime you start your computer.
Title: How to block certain IPs and Website on Iptables
Post by: veno on September 04, 2005, 01:31:54 PM
Quote from: "Ricky"
you can add them in rc.local file so that it get executed everytime you start your computer.

yes i know that what i'm tryign to do is block the master server from quake 3 arena for 3,5 hours and open it for 30 mins and close it again so what i tried is this in crontab

* */3 * * * /sbin/iptables -D OUTPUT 1
30 */3 * * * /sbin/iptables -A OUTPUT -p tcp -d 192.246.40.56 --destination-port 27950 -j REJECT

not sure if that will work but maybe u can tell me or someone
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on September 06, 2005, 11:24:36 AM
rather executing them directly you should made two or more script files. Say Ist one is the one who blocks the quake servers and IInd one is the one who allow the quake server.

then execute the IInd file when you want it to be open and Ist when you want it to be block.

BTW.. I don't get that when you want to block and when to allow the access so that I can correct your cronjob if its wrong.
Title: How to block certain IPs and Website on Iptables
Post by: Kal on September 10, 2006, 02:06:04 AM
I have been trying to create a similar script for my quake3 server but with not much luck.  Is there anyone out there who has successfully created such a script?  Please let me know!
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on September 10, 2006, 11:59:55 AM
As I suggested earlier you can make two files ie script, one is to block and other is to release then execute those scripts using the cron job .
Title: How to block certain IPs and Website on Iptables
Post by: Kal on September 10, 2006, 09:30:57 PM
Code: [Select]

if [ "$1" = "-u" ]
then
        iptables -D OUTPUT -d 192.246.40.56 -j REJECT
else
        iptables -A OUTPUT -d 192.246.40.56 -j REJECT
fi


Cron Job
Code: [Select]
30 0,4,8,12,16,20 * * * /path/to/q3block
0 0,4,8,12,16,20 * * * /path/to/q3block -u


I found this code on a forum and was wondering if this is what you were talking about.  I am unfortunately a newbie when it comes to writting shell scripts.  Would this code work for hiding the server 3.5 hours then releasing it for 30 minutes?  Thanks for any help you can provide.
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on September 11, 2006, 07:19:38 PM
just simple file containing command to block the server using iptables and other simple file to unblock the server and make them executables by giving execute permission . Then using cron run them accordingly. !!!
Read little about blocking a IP in iptables.
Title: How to block certain IPs and Website on Iptables
Post by: Kal on September 11, 2006, 11:33:09 PM
Ok I just want to say thanks so far for the help you have provided.  I did some research on blocking/allowing ip addresses in iptables and how crontabs work.  Here is the code I came up with.  BTW: The forums don't like it when I put in shell script code so I have left it out.

block.sh
Code: [Select]


iptables -p all -d 192.246.40.56 -j DROP


allow.sh
Code: [Select]


iptables -p all -d 192.246.40.56 -j ACCEPT


crontab
Code: [Select]


Block 192.246.40.56 heartbeats
0 0,4,8,12,16,20 * * * /path/to/block.sh
Allow 192.246.40.56 heartbeats
30 3,30 7,30 11,30 15,30 19,30 23 * * * /path/to/allow.sh


I am not sure if I setup the crontab correctly for the release/block times.  Here is the schedule for blocking/releasing.

Block 12 am 4 am 8 pm 12 pm 4pm 8 pm
Release 3:30 am, 7:30 am, 11:30 am, 3:30 pm, 7:30 pm, 11:30 pm

Please let me know if I am doing this correctly.  Thanks for any help!
Title: How to block certain IPs and Website on Iptables
Post by: Ricky on September 12, 2006, 03:37:44 PM
so far its alright but I want to let you know that I need to read cron docs to confirm it though you can test it.
Title: How to block certain IPs and Website on Iptables
Post by: Kal on September 12, 2006, 05:36:37 PM
8)
Title: How to block certain IPs and Website on Iptables
Post by: gauravbajaj on September 13, 2006, 02:03:44 AM
I think the last line should be like this:

30 3,7,11,15,19,23 * * * /path/to/allow.sh

Gaurav
Title: How to block certain IPs and Website on Iptables
Post by: Kal on September 16, 2006, 06:26:23 PM
I just want to make sure this cron job is doing what I want it to.  I unfortunately don't have a server to test it out on yet.  It needs to block the master server for 3.5 hours then allow for 30 minutes then block again for 3.5 hours and so on....   The way this cron job is setup will it do that?