HAProxy community

NAPT with HAproxy

Greetings,

I’m using HAproxy for his capacity to do redirection of ports in a large range.

Basically, I have this type of configuration :
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
user haproxy
group haproxy
daemon

defaults
    log     global
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000

frontend haproxy_front
  bind :6000-8000
  default_backend mee

backend redirect_sas
   server mee x.x.x.x

And I need to create multiple frontend and backend with an allocation of 2000 ports by backend. But one specifity : ports must be also redirected.

Which mean by example in my haproxy, ports 1-2000 are going to my machine 1 into it ports 1-2000, but ports in the range 2001 to 4000 must go to my machine 2 into ports 1-2000.

I’ve searched and I haven’t found basic solution or functionality into HAproxy for this case.

So my first question is “It is possible ?”. And the second : “They are a point about that in the documentation ?”.

Regards,
Darcosion.

I guess this could be achieved with set-dst-port somehow.

Maybe something like this (untested):

listen machine1
 bind :1-2000
 server machine1

listen machine2
 bind :2001-4000
 tcp-request connection set-dst-port dst_port - 2000
 server machine2

listen machine3
 bind :4001-6000
 tcp-request connection set-dst-port dst_port - 4000
 server machine3

listen machine4
 bind :6001-8000
 tcp-request connection set-dst-port dst_port - 6000
 server machine4