xjasonlyu / tun2socks

tun2socks - powered by gVisor TCP/IP stack
https://github.com/xjasonlyu/tun2socks/wiki
GNU General Public License v3.0
3.14k stars 433 forks source link

Docker multiple containers question #128

Closed AvgAwsmDude closed 2 years ago

AvgAwsmDude commented 2 years ago

Can i run multiple docker container and also run tun2socks docker container and config each of the other containers to a different socks5 proxy that i provide?

xjasonlyu commented 2 years ago

I think it should work if you configured properly.

chromer030 commented 2 years ago

You need to create tun on each container which is explained here how to : https://stackoverflow.com/questions/59451531/how-to-create-tun-interface-inside-docker-container-image and use tun2socks.

AvgAwsmDude commented 2 years ago

@chromer030 why isnt it possible with redsocks? like i force each containers ip:port to redsocks where i wouldve mapped it to use proxy?

AvgAwsmDude commented 2 years ago

@chromer030 im asking this because i found it easy to setup redsocks+iptables but i have no idea how to use tun2socks

AvgAwsmDude commented 2 years ago

https://stackoverflow.com/questions/72198113/running-docker-containers-each-with-socsk5-proxy this is what im trying to achieve

AvgAwsmDude commented 2 years ago

I think it should work if you configured properly.

but i want to use just one tun container not one for each other container im trying to proxy

xjasonlyu commented 2 years ago

Easy. Try to use a proxy’s proxy (that’s what I call 😂) and redirect the connections to target socks5 proxy by your rule.

And for that, you can use a tool called v2ray, it has some advanced routing mechanism for proxy.

AvgAwsmDude commented 2 years ago

damn, it all looks so complicated :'( , tell me ,


iptables -t nat -A REDSOCKS -p tcp --dport 80 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 443 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 11371 -j REDIRECT --to-ports 12345

when i do this , my app runs using the proxy, now if i want to use many instances of my app , how will i get my container ip and port or dport , so that i can map it all right? and provide the right config in redsocks.conf


base {

    log_debug = off;

    log_info = on;

    log = "syslog:daemon";

    daemon = on;

    user = redsocks;
    group = redsocks;

    redirector = iptables;
}

redsocks {

    local_ip = 127.0.0.1;
    local_port = 12345;

    ip = proxy-ip;
    port = port;

    type = socks5;

     login = "user";
     password = "pass";
}
xjasonlyu commented 2 years ago

what’s that… don’t make it complicated, iptables is not needed at all in your case.

AvgAwsmDude commented 2 years ago

what’s that… don’t make it complicated, iptables is not needed at all in your case.

Alright , to redirect the connections of the containers I need to figure out what ip:port the container is running on , how do I do that?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days