How-to: Easy configuration of HAProxy in TCP mode on Debian

So, i needed to connect to RDP on a remote location (my home actually) but the network im sitting on is not allowing outgoing traffic on 3389.

Fortunately port 8080 is allowed and i do not use that for anything else.

Wondering why i just didnt make a port forward in my router from 8080 to 3389? Well ye, would have been easier but 8080 is locked for remote management even if it remote mangement is disabled. Therefore i needed another box out in the public where i did the forwarding and therefore haproxy was used.

I needed a quick and easy proxy for TCP traffic. I have used HA Proxy before, which i remembered as pretty easy to setup – that was correct remembered 🙂

The installation was done on a Debian server that already was running.

Install HA Proxy:

 apt-get install haproxy

Add the following to the /etc/haproxy/haproxy.cfg file.

frontend local8080
 bind *:8080
 mode tcp
 default_backend homesrv3389
 timeout client 1m

backend homesrv3389
 mode tcp
 server homesrv
 timeout connect 10s
 timeout server 1m

Its pretty self explainable. The frontend is what your proxy is listening on and the backend is what it redirects the traffic to. In the frontend section “default_backend” just has to match the backend node.

Then just restart HA Proxy and it loads the default configuration

/etc/init.d/haproxy restart

If you wanted to loadbalance between multiple servers in the backend you’ll just add it like:

backend homesrv3389
 mode tcp
 balance roundrobin
 server homesrv01
 server homesrv02
 timeout connect 10s
 timeout server 1m

You can create multiple frontends/backends like this.

Hope you can use it.





Skriv et svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *