Say I want to route all requests to google.com to localhost:333 , how to do so?
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:
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
In /etc/shorewall/tcrules add:
#MARK SOURCE DEST PROTO DEST # PORT(S) 202:P net:google.com 0.0.0.0/0 tcp 80
In /etc/shorewall/interfaces :
#ZONE INTERFACE BROADCAST OPTIONS loc eth1 detect routeback
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