Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Say I want to route all requests to google.com to localhost:333 , how to do so?

share|improve this question
1  
Interesting and suspicious question =). –  RJFalconer Jan 9 '10 at 18:20

2 Answers 2

Shorewall routes. (FAQ)

You want to redirect all local google.com connection requests to a server running in your local zone at 127.0.0.1 and listening on port 333. Your local interface is eth1.

Disclaimer; I've not done exactly this with Shorewall, so modified an example Squid server setup:

  1. Add this entry to your /etc/shorewall/providers file.

    #NAME   NUMBER  MARK    DUPLICATE       INTERFACE       GATEWAY         OPTIONS
    foo     1       202     -               eth1            127.0.0.1     loose
    
  2. In /etc/shorewall/tcrules add:

    #MARK    SOURCE              DEST        PROTO    DEST
    #                                                 PORT(S)
    202:P    net:google.com   0.0.0.0/0   tcp      80
    
  3. In /etc/shorewall/interfaces :

    #ZONE   INTERFACE    BROADCAST    OPTIONS
    loc     eth1         detect       routeback          
    
  4. On localhost, arrange for the following command to be executed after networking has come up

    iptables -t nat -A PREROUTING -i eth0 -d ! 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports 333          
    
share|improve this answer
1  
redirecting google by hand-added IPs won't work very well -- you'll get a different IP for the DNS lookup every 5 minutes or so due to load balancing. for google.com, you'd really want to reroute at the DNS level. can Shorewall do that? –  quack quixote Jan 9 '10 at 18:18
    
I suspect "net:google.com" should do the trick. Yeah, you caught me mid edit there. –  RJFalconer Jan 9 '10 at 18:19
    
fair enuff. leaving the comment for the time being but glad to see you were working on it already. :) –  quack quixote Jan 9 '10 at 18:25
    
That's the best I can come up with I think. I'll leave it here for someone more experienced with shorewall to comment on / edit. –  RJFalconer Jan 9 '10 at 18:35
    
I want it to be on the same machine, so pinging google.com should go to some port that I specify on my local machine, say 333 –  khelll Jan 9 '10 at 21:51

If you just want to do this on a single machine, you can edit:

/etc/hosts 

and add

google.com 127.0.0.1

then restart network services

/etc/rc.d/init.d/network restart

This would redirect normal web traffic to localhost:80 though.

share|improve this answer
    
Nice idea to keep track of local network connections! :D –  dag729 Jan 9 '10 at 21:30
    
That's what I wanted originally but also I want to control to which port the request will go. –  khelll Jan 9 '10 at 21:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.