LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I block a website using iptables with this rules? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-block-a-website-using-iptables-with-this-rules-4175468990/)

rjdbarsal 07-09-2013 06:44 AM

How can I block a website using iptables with this rules?
 
Hello again guys,

I already set up a rule with mac filtering with this rule:

I set the iptables default rule to:
Code:

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

then with macfiltering this rule a certain mac address can access an internet/other networks:

Code:

iptables -A POSTROUTING -t nat -o eth0 -s 192.168.1.0/24 -d 0/0 \
        -j MASQUERADE
iptables -A FORWARD -t filter -i eth0 -d 192.168.1.0/24 -m state \
        --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -t filter -o eth0 -m mac --mac-source 00:26:6C:C7:81:C4 -m state \
        --state NEW,ESTABLISHED,RELATED -j ACCEPT

and what I want is, to block a website with this iptables rules but how?

I need any ideas, suggestions or tips from you guys.

Thanks

acid_kewpie 07-09-2013 07:01 AM

Words like "website" really don't mix with iptables. But you've not said a thing about what this site is, so it's hard to know if anything is possible. There are ways to attempt to match certain strings in web traffic which can be used to filter at a deeper level, but it's really not appropriate most of the time. You need to stay in a world of IP addresses and port numbers, so if you can define what this site is in those terms, then great, otherwise, that's what http proxies are for.

rjdbarsal 07-09-2013 07:57 AM

Thank you for your response, Chris.
The website is google.com. How can we able to block this site?
Applying iptables.

M4nd4R 07-09-2013 08:31 AM

First thing- You are using IPTABLES, so you should know the IP address of the website you want to block.
And Google has a range of IP addresses and you will have to block each of them.

Code:

sudo iptables -A INPUT -s IP_ADDRESS -j REJECT
Something like this might help.

rjdbarsal 07-09-2013 08:51 AM

Thanks but this rule not working to the iprules given above.
Code:

sudo iptables -A INPUT -s IP_ADDRESS -j REJECT
Code:

              +---+       
        eth0=>| F |        +----------+
internet ======| w |        |          |------PC1
              | / |        |  switch  |------PC2
              | S |========|          |------PC3
              |  |eth1    +----------+
              +---+

FW: FIREWALL
S: SERVER
eth0: connection from the internet/other network
eth1: internal network

acid_kewpie 07-09-2013 09:31 AM

you can't block google from IP tables. Google has HUNDREDS of potential IP addresses serving a myriad of different sites that can change at any given second. That's absolutely NOT a plan. You need a proxy, something that understands HTTP.

rjdbarsal 07-09-2013 09:38 AM

Hello Chris,

May I know how we can use proxy to block a website in ubuntu server?
any guidelines or steps?

acid_kewpie 07-09-2013 09:43 AM

sure, just google information about squid, that's exactly what it's for.


All times are GMT -5. The time now is 11:40 PM.