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

  • 1
    Interesting and suspicious question =). – RJFalconer Jan 9 '10 at 18:20

Shorewall routes. (FAQ)

You want to redirect all local google.com connection requests to a server running in your local zone at 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.

    foo     1       202     -               eth1       loose
  2. In /etc/shorewall/tcrules add:

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

    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 ! -p tcp --dport 80 -j REDIRECT --to-ports 333          
| 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:


and add


then restart network services

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

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

| 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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