I have 2 network cards. The first one is network card with the address 192.168.5.3
, the second one is network card with the address 10.1.1.252
.
How to configure using proxy as a transparent proxy,
meaning the client only need to change the gateway of 192.168.5.3
is able to go through the proxy without having to modify the browser's proxy option.
I use the following code to do this:
final ChainedProxyAdapter adapter = new ChainedProxyAdapter() {
@Override
public InetSocketAddress getChainedProxyAddress() {
return new InetSocketAddress("10.1.1.252", 8003);
}
};
ChainedProxyManager manager = new ChainedProxyManager() {
@Override
public void lookupChainedProxies(HttpRequest httpRequest, Queue<ChainedProxy> chainedProxies) {
chainedProxies.add(adapter);
}
};
HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress("192.168.5.3", 8002))
..withChainProxyManager(manager)
.start();
(port 8003 will to access the internet.)
In iptables
I add some rule as follows:
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -i eth2 -p tcp --dport 80 -j REDIRECT --to-port 8002
iptables -t nat -A PREROUTING -i eth2 -p tcp --dport 443 -j REDIRECT --to-port 8002
(the address of eth2 is 192.168.5.3
)
But when I set the client to use the gateway 192.168.5.3
and 192.168.5.3
dns, I always get 400 Bad request to URI :/ for http url and connect not secure for https url. Please just let me know the solution. Thanks.
cause: when proxy reading an request from the client, it get the first line, and when using proxy as transparent, it received request such as GET / HTTP/1.1
not contain Host, so it return bad request. With https request, the proxy can not parse, it's try parsing, and the browser throw ssl_error_rx_record_too_long
message.
The little proxy not support transparent mode, transparent in the little proxy is understood as hidden computer information when it connect via proxy.