Layer 4 Proxy
The Arvancloud Layer 4 Proxy helps you provide security and acceleration for your TCP-based applications. With this feature, you can route non-web protocols such as email, SSH, FTP, games, and more through TCP on Arvancloud, to hide your origin server addresses and protect them against DDoS attacks.
When you create a Layer 4 Proxy application, Arvancloud assigns it an IP from its own IP pool. You can also move your own IP to Arvancloud to use it. After migration, Arvancloud advertises your dedicated IP via Anycast and uses it exclusively for your website and applications.
To get started, simply create an application from Arvancloud panel > CDN > select domain > Security > Layer 4 Proxy > New Application.
Step 1: Application Settings
On the page that opens, first enter your application's name and description. Then select a subdomain of your domain that you want the application to be created on.
Note that this subdomain must not already be in use.
In the next sections, you need to specify the port, protocol, and how PROXY PROTOCOL is used.
Protocol
The protocol on which traffic from users is received. You can select the TCP protocol.
Note that the protocol can't be edited after it is selected.
Port
The port users send their requests to, which is hosted on the CDN network. The selected port must be unique among your applications, and you can't use the same port more than once.
Note that the port can't be edited after it is selected.
The range of ports available for a Layer 4 Proxy application is 1 to 65535. All ports in this range are open by default. This means you can run multiple applications on different ports at the same time. You can also assign separate ports to different services (for example: HTTP on port 80, HTTPS on port 443, SSH on port 22, a MongoDB database on port 27017, and so on).
PROXY PROTOCOL Support
Since Arvancloud inspects packets before sending them to the origin server, you will see Arvancloud's IP instead of the real user's IP in your logs.
Some services may need the user's real IP. In these cases, you can use PROXY PROTOCOL to pass the user's IP to your service. For TCP, Arvancloud supports Proxy Protocol v1 and Proxy Protocol v2, which are also supported by NGINX.
-
Enabling version 1:
Version 1 sends each connection with a header that contains the user's IP address and port.
A version 1 header has the following format:
PROXY_STRING + single space + INET_PROTOCOL + single space + CLIENT_IP + single space + PROXY_IP + single space + CLIENT_PORT + single space + PROXY_PORT + "\r\n"A sample Proxy Protocol v1 header for an IPv4 address looks like this:
PROXY TCP4 192.0.2.0 192.0.2.255 42300 443\r\nA sample Proxy Protocol v1 header for an IPv6 address looks like this:
PROXY TCP6 2001:db8:: 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff 42300 443\r\n -
Enabling version 2:
When TCP applications are configured to use Proxy Protocol v2, Arvancloud adds a binary Proxy Protocol v2 header to each incoming TCP connection, containing the user's IP address and port.
A binary Proxy Protocol header for an incoming IPv4 address looks like this:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
\+ +
| Proxy Protocol v2 Signature |
\+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|Command| AF | Proto.| Address Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A binary Proxy Protocol header for an incoming IPv6 address looks like this:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
\+ +
| Proxy Protocol v2 Signature |
\+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|Command| AF | Proto.| Address Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
\+ +
| |
\+ IPv6 Source Address +
| |
\+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
\+ +
| |
\+ IPv6 Destination Address +
| |
\+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Step 2: Load Balancing Settings
In this step, you can create a cluster by entering the addresses of several origin servers, and use the monitoring section to keep track of its status.
-
Load Balancing Method
In this section, you can specify the algorithm used to select an address from among the origin server addresses.
-
Round Robin Algorithm
This is the simplest and most common load balancing algorithm. User requests are distributed among your origin servers in a simple rotation. For example, imagine you have 6 users (u1, u2, u3, u4, u5, and u6) who want to connect to your application, and you have 3 servers (s1, s2, and s3). u1 connects to s1, u2 to s2, and u3 to s3; then u4 connects to s1, u5 to s2, and u6 to s3. The Round Robin algorithm is suitable for predictable requests and for servers with relatively equal processing power and resources.
However, if one of the servers has more capacity to handle requests than the others, you can use weighting to make full use of that server's power.
-
Weighted Round Robin
A slightly more advanced load balancing algorithm. Imagine s1 is twice as powerful as s2 and s3. So you can assign it a higher weight, because it can handle more load, and since its weight is higher, it also gets more traffic.
The main difference in the example above is that u1 connects to s1, and then u2 connects to s1 again. u3 connects to s2 and u4 to s3, and then u5 and u6 connect to s1.
There is another scenario where Weighted Round Robin can be useful. Your servers may be similar, but you may have more important data on one of them and want that server to have a lower weight. In this case, you assign higher values to the other servers. This way, they handle more load, and your critical server has less processing and traffic.
-
Source Algorithm
This method combines the source and destination IP addresses of the traffic and uses a mathematical function to convert them into a hash. Based on this hash, the request is assigned to a specific server. Since the key can be regenerated when a session drops, the user's request is directed to the same server they connected to on their first request. This method is more suitable when a user's consecutive connections must always return to the same server.
-
Least Connection Algorithm
This method assumes that all requests need the same amount of processing power, so each request goes to the server that has the fewest open connections at that moment.
-
-
Servers
In this section, enter the IP addresses of your servers along with the port and weight you want for each.
Step 3: Monitoring Settings
When an error occurs on one of the servers in the defined cluster, Arvancloud can take that server out of service and stop sending traffic to it until the error is fixed. This feature also reports the error on that server by email.
On this page, the check interval means the time between monitoring requests sent to the origin servers.
Also, the tolerable error count specifies how many errors must occur for monitoring to consider that server's status as failing.
Step 4: Firewall Settings
With the firewall, you can block access to your application based on two parameters: IP and country.
The Arvancloud Layer 4 Proxy provides DDoS protection at layers 3 and 4 of the OSI model (TCP-based attacks).
Arvancloud works as a layer 4 reverse proxy, so a proper TCP connection must first be established before traffic is proxied to the origin. This moves the impact of any SYN or SYN-ACK attacks to Arvancloud edge servers. In addition, by using the Layer 4 Proxy in front of your application, your origin IP is hidden, which prevents your servers' IPs from being targeted. It is recommended that, after moving your traffic to Arvancloud, you block all IPs from accessing the origin server and whitelist only the Arvancloud server IP range.
Final Step: Submitting a Request
Finally, to enable the Layer 4 Proxy on the cluster you created, you need to contact Arvancloud support through a ticket or the enterprise support groups.