LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-06-2011, 12:27 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Filter a single website using iptables?


Hi,

I just setup a Slackware gateway/firewall/proxy/server in a school. It has two NICs and filters all traffic using Squid and Squidguard. So far, the filter works very nice, I only have one minor problem left. Squidguard currently only filters HTTP requests, since setting up HTTPS filtering is a real PITA. Now I have only one single website left for filtering, that's https://www.facebook.com. I thought the best thing would be to block it entirely using iptables. How would I go about that?

(If you wonder why I would block Facebook for students, http://www.facebook.com is still available for all students, but only outside class hours...)

Cheers from the sunny South of France.
 
Old 09-06-2011, 02:06 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Don't. You don't need to setup https to block by IP address, which is what you'd do in iptables. Just use a dest ip acl in squid. You just need to find all the IP addresses for Facebook.
 
Old 09-06-2011, 02:14 AM   #3
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by acid_kewpie View Post
Don't. You don't need to setup https to block by IP address, which is what you'd do in iptables. Just use a dest ip acl in squid. You just need to find all the IP addresses for Facebook.
Yes but no

I could explain why, but it would be long. So let me restate my question. How can I block requests to https://www.facebook.com using iptables?
 
Old 09-06-2011, 02:17 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Well that just sounds daft. If that's the case then you need to explain that. Arbitrary restrictions are awful.

Anyway you just block all the relevant ip's just like you would do in squid. You can't block it by name.

Last edited by acid_kewpie; 09-06-2011 at 02:19 AM.
 
Old 09-06-2011, 02:47 AM   #5
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Anybody able to answer a simple question without making me jump through burning loops?
 
Old 09-06-2011, 02:53 AM   #6
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
I'm not sure that you can block by name from iptables, although I could easily be wrong. But I was under the impression that squidguard could do that, and also do it inside certain time periods. You say you are in fact using squidguard - why won't you let it block that particular site ?
(note - I might be confusing squidguard with dansguardian - I have exactly what you want running on my home server, but it's going to be another 8 hours before I get home to check !)
 
Old 09-06-2011, 03:05 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
iptables -A INPUT -d 1.2.3.4 -j REJECT

etc, for each IP address that facebook uses.

use squid for this.
 
Old 09-06-2011, 03:06 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by Mark Pettit View Post
I'm not sure that you can block by name from iptables, although I could easily be wrong. But I was under the impression that squidguard could do that, and also do it inside certain time periods. You say you are in fact using squidguard - why won't you let it block that particular site ?
(note - I might be confusing squidguard with dansguardian - I have exactly what you want running on my home server, but it's going to be another 8 hours before I get home to check !)
you can't check the destination of an https connection unless you are proxying the CONNECT http method or transparently decrypt the session.
 
Old 09-06-2011, 03:11 AM   #9
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by acid_kewpie View Post
iptables -A INPUT -d 1.2.3.4 -j REJECT

etc, for each IP address that facebook uses.

use squid for this.
Thanks for answering my question. I poked around a bit to follow your suggestion as well (apologies for not having explained the details), and now I wonder about the "for each IP address that Facebook uses". I would do this:

Code:
$ dig www.facebook.com
Which returns this:

Code:
;; ANSWER SECTION:
www.facebook.com.       103     IN      A       66.220.158.32

;; AUTHORITY SECTION:
facebook.com.           114985  IN      NS      ns1.facebook.com.
facebook.com.           114985  IN      NS      ns4.facebook.com.
facebook.com.           114985  IN      NS      ns2.facebook.com.
facebook.com.           114985  IN      NS      ns5.facebook.com.
facebook.com.           114985  IN      NS      ns3.facebook.com.

;; ADDITIONAL SECTION:
ns3.facebook.com.       41      IN      A       66.220.151.20
ns4.facebook.com.       1369    IN      A       69.63.186.49
ns5.facebook.com.       64      IN      A       66.220.145.65
I'm not sure about this, but I'd figure that something as huge as Facebook would use a lot more IP addresses. How would I go about to find all of Facebook's IP addresses?

@acid_kewpie: yeah, I guess I'll follow your advice and use Squid for that. I just figured out that my downloaded blacklist database does not only rely on domain names, but also on IP addresses. My mistake.
 
Old 09-06-2011, 03:21 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it'll use load's of IP's but it'll also be globally load balanced to each data center.


$ dig www.facebook.com @ns1.facebook.com

; <<>> DiG 9.8.0-P4-RedHat-9.8.0-7.P4.fc15 <<>> www.facebook.com @ns1.facebook.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24499
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 2
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;www.facebook.com. IN A

;; AUTHORITY SECTION:
www.facebook.com. 86400 IN NS glb2.facebook.com.
www.facebook.com. 86400 IN NS glb1.facebook.com.

;; ADDITIONAL SECTION:
glb2.facebook.com. 3600 IN A 69.171.255.10
glb1.facebook.com. 3600 IN A 69.171.239.10

;; Query time: 74 msec
;; SERVER: 204.74.66.132#53(204.74.66.132)
;; WHEN: Tue Sep 6 09:18:57 2011
;; MSG SIZE rcvd: 104


you can see there that this dig says that you need to go to these glb's to get an IP address for facebook which is suitable to your geographical location. You can *never* know you have all the IP addresses.

as far as your blacklist goes, check how it is being used. it would need to be used against a "dst" acl, not a "dstdomain" acl.

But then going from what you've said, what are you doing with HTTPS connections? If they are already just using a CONNECT via the proxy then you can filter on the domain. It's when you're doing transparent stuff that you're SOL.

Last edited by acid_kewpie; 09-06-2011 at 03:24 AM.
 
Old 09-06-2011, 03:35 AM   #11
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
Quote:
Originally Posted by acid_kewpie View Post
you can't check the destination of an https connection unless you are proxying the CONNECT http method or transparently decrypt the session.
Ah - I'm sorry - I misread the 'https' for 'http'. Thanx for pointing that out.
 
Old 09-06-2011, 05:03 AM   #12
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,183

Rep: Reputation: 237Reputation: 237Reputation: 237
Quote:
Originally Posted by acid_kewpie View Post
Don't. You don't need to setup https to block by IP address, which is what you'd do in iptables. Just use a dest ip acl in squid. You just need to find all the IP addresses for Facebook.
Maybe blocking DNS is simpler and less offensive, as blocking IP addresses is similarly ineffective to enthusiastic users (e.g. proxy users).

Last edited by guanx; 09-06-2011 at 05:07 AM.
 
Old 09-06-2011, 05:20 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by guanx View Post
Maybe blocking DNS is simpler and less offensive, as blocking IP addresses is similarly ineffective to enthusiastic users (e.g. proxy users).
sure, opendns could be a great solution.
 
Old 09-06-2011, 05:20 AM   #14
Lexus45
Member
 
Registered: Jan 2010
Distribution: Debian, Centos, Ubuntu, Slackware
Posts: 361
Blog Entries: 3

Rep: Reputation: 48
Yes, you can block FQDNs with iptables.
But don't think that I filter FQDNs in this way. :-)

Something like this:
Code:
-A OUTPUT -p tcp -m string --string facebook.com --algo kmp -j DROP

Last edited by Lexus45; 09-26-2011 at 05:11 AM.
 
Old 09-06-2011, 05:43 AM   #15
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by Lexus45 View Post
Yes, you can block FQDNs with iptables.
But don't think that I filter FQDNs in this way. :-)

Something like this:
Code:
-A OUTPUT -p tcp -m string --string facebook.com --algo kmp -j DROP
point is, the domain name is inside an SSL session. want to break SSL with iptables too?
 
  


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
iptables can't initialize iptables table `filter': Bad file descriptor donalbane Linux - Networking 2 08-17-2011 08:36 AM
Allow single website from iptables Madhushanka Linux - Security 1 11-21-2008 12:05 AM
What is best for a website filter for my kids? Snort in inline mode, or a squid proxy abefroman Linux - Software 1 10-27-2008 03:19 AM
iptables filter s not anything Ygrex Linux - Networking 1 02-27-2008 01:31 PM
iptables v1.3.8: can't initialize iptables table `filter' sebastien.lorandel Linux - Networking 11 09-22-2007 06:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:58 PM.

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