LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-30-2005, 10:52 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
How and I blocked a URL with IP tables?


How and I blocked a URL with IP tables?

I want to block everyone from accessing yahoo.com by using iptables, how can I do that?
 
Old 05-01-2005, 04:54 AM   #2
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
It is possible, however yahoo.com has several subdomains. I was searching for the other thread where I posted the iptables line for this, but we ended up with 6 rules I think. That was several months ago that this questions was brought up. The kicker here is to push an entry to the /etc/hosts file telling the computer that yahoo.com is 127.0.0.1. This is your best bet to get this working properly.
 
Old 05-01-2005, 06:30 AM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
What are the 6 rules? I still want to be able to access yahoo, but dont want anyone else to.
 
Old 05-01-2005, 07:18 AM   #4
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
IPTABLES -A OUTPUT -d yahoo.com -reject-with icmp-host-unreachable

Since I'm not on a linux machine, I can't tell you the other names you'll need. Open a terminal and type dig yahoo.com then input the rules for each name.
 
Old 05-01-2005, 11:47 AM   #5
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
You say you want to be able to access it but nobody else? What's your setup? Is this computer acting as a gateway for other computers or do you all share the same one?
 
Old 05-01-2005, 07:51 PM   #6
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
The easiest way to still to push an /etc/hosts file to everyone else with yahoo.com spoofed.
 
Old 05-01-2005, 09:16 PM   #7
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
How can I let me through, my IP is 10.10.0.9?

Will this work?
IPTABLES -A OUTPUT -s 10.10.0.9 -j ACCEPT
IPTABLES -A OUTPUT -d yahoo.com -reject-with icmp-host-unreachable
iptables -N state_chk
iptables -A state_chk -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A state_chk -m state --state NEW -i ! eth0 -j ACCEPT
iptables -A state_chk -j LOG --log-prefix fw-state:
iptables -A state_chk -j DROP

Is this the correct syntax?
IPTABLES -A OUTPUT -s 10.10.0.9 -j ACCEPT

If I only want to block the guy next to me can I do:
IPTABLES -A OUTPUT -s 10.10.0.10 -d yahoo.com -reject-with icmp-host-unreachable

Thanks in advance!
 
Old 05-01-2005, 09:49 PM   #8
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
Your accept needs to be after all the blocks however you are still doing this the hard way.
 
Old 05-01-2005, 09:50 PM   #9
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
You can compress that idea into one rule
Code:
iptables -t nat -A PREROUTING -d yahoo.com ! -s 10.10.0.9 -j DROP
Which reads as "Append to NAT table's PREROUTING chain: if destination is yahoo.com and source is not 10.10.0.9, reject it"

That way you can still use your chain policy since the jump (-j) directive stops the processing of the chain there may be rules you may wish to add in the future to prevent output from 10.10.0.9.

Also what is the purpose of the state_check chain?

PS musicman_ace still has the simplest solution, though it is not server-centric.

EDIT I fixed the above rule's target.

Last edited by michaelsanford; 05-02-2005 at 10:16 AM.
 
Old 05-02-2005, 02:16 AM   #10
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
Quote:
Originally posted by michaelsanford
You can compress that idea into one rule
I'm not sure that would still work. Since yahoo.com isn't the FQDN, it will get resolved to one of the other FQDNs that exist. The other thread that discussed this was using hotmail as an example and in the end I think the person went with content filters rather than IP tables.

[edit]
I known this seems odd. It should block all IP's that get resolved from yahoo.com, but the last time we discussed this idea it didn't work the way we logically think it should.

Last edited by musicman_ace; 05-02-2005 at 02:29 AM.
 
Old 05-02-2005, 10:14 AM   #11
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Thanks! But I tried
iptables -t nat -A PREROUTING -d yahoo.com ! -s 10.10.0.9 -j REJECT
and got the error:
iptables v1.2.8: ! not allowed with multiple source or destination IP addresses
Try `iptables -h' or 'iptables --help' for more information.

When I removed
! -s 10.10.0.9
It gave the error:
iptables: Invalid argument

Got any tips?
 
Old 05-02-2005, 10:25 AM   #12
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
Sorry I made a little mistake in the above rule. You do need some extra stuff to match multiple IPs, which yahoo has:
Code:
iptables -t nat -A PREROUTING -d 66.94.234.13 ! -s 10.10.0.9 -j DROP
iptables -t nat -A PREROUTING -d 216.109.112.135 ! -s 10.10.0.9 -j DROP
 
Old 05-02-2005, 10:48 AM   #13
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You need to add a rule for each IP you wish to block, not each hostname. I assume, of course, that yahoo is the a "theoretical" domain here: I don't know why you'd want to block yahoo, but that's not the point.

The rules above should work for you without a problem.
 
Old 05-02-2005, 12:25 PM   #14
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Thanks that blocks yahoo.com but its not blocking anything.yahoo.com
(yahooligans.yahoo.com and mail.yahoo.com still load)

Is there a way to block *.yahoo.com ?
 
Old 05-02-2005, 12:53 PM   #15
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
To do it with iptables you need to find the IP address of every subdomain host (if it's different) and block that too.

Let me tell you, yahoo.com has a heck of a lot.
 
  


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
ERROR The requested URL could not be retrieved While trying to retrieve the URL: /re Niceman2005 Linux - General 1 06-29-2005 09:51 AM
Blocked bhughesiii Linux - Networking 9 05-12-2005 01:44 PM
Ports Blocked spaceballs Slackware 4 05-02-2005 09:42 PM
Sound Gets Blocked Crashed_Again Linux - General 2 10-26-2003 10:12 AM
Log-in blocked Tinkster Linux - Newbie 2 08-28-2002 05:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:42 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