Redirecting All Container Traffic via SOCKS Proxy Using tun2socks
17.06.2025
Sometimes it becomes necessary to route all outgoing traffic from a specific container through a proxy server. This can be useful for ensuring anonymity, bypassing geo-restrictions, or for testing network configurations. In this article, we’ll look at how to set up such a system using the tun2socks utility and iptables rules, as well as how to manage this process with systemd.
What is tun2socks?
tun2socks is a powerful tool that allows you to redirect network traffic intended for a TUN device through a SOCKS proxy. It creates a virtual network interface (TUN device), and all traffic flowing through it is encapsulated into a SOCKS connection. This is especially convenient when direct application-level proxying is impossible or undesirable.