Network configuration often demands the need for TCP port forwarding in HAProxy.
Usually, we do this by adding the corresponding configuration to the HAProxy configuration file.
At Bobcares, we often get requests to configure HAProxy, as a part of our Server Management Services.
Today, let’s see how our Support Engineers forward the TCP port.
Need for HAProxy port forwarding
First, let’s have a quick look into HAProxy. Basically, HAProxy is a proxy and at the same time is a load balancing server. It provides high availability for both TCP connection and HTTP requests.
Hence it has improved speed and maintains performance by distributing the workload. But during network configuration users often need to forward default TCP ports to some other ports.
So for these redirections, we can forward ports in HAProxy. For doing this we edit the HAProxy configuration file. Now, let’s see how our Support Engineers do this.
How we configure TCP port forwarding?
By default, the configuration file of HAProxy is haproxy.cfg
. Our Support Engineers edit this file and add the configuration to forward the TCP port. Hence we open the file using the command,
cat /etc/haproxy/haproxy.cfg
This opens the config file. And we add the entry for forwarding the TCP port. Usually, this appears as,
Here we define some global and default parameters. Similarly, we added the frontend and backend configuration. Actually, these parameters define the way we forward the port.
The frontend configuration has the port which accepts the connection. In the backend, this gets forwarded to the specified port.
Later we check the added configuration. For this, we use the command,
haproxy -f haproxy.cfg -c
This successfully loads the configuration. Thus we ensure that the TCP port forward works.
[Still, having trouble in HAProxy port forwarding? – We can help you.]
Conclusion
In short, for enabling HAProxy TCP port forwarding, we edit the HAProxy configuration file. Today, we saw how our Support Engineers add the configuration without fail.
0 Comments