Load Balancer -DSR and IP address translation (SNAT)

I often asked Load Balancer (LB) and Source Network Address Translation(SNAT), I will write the answer and let them seeing this article in next time.

 

1. Direct Server Return (DSR) by LB

DSR is a function of LB to increase the availability of application throughput, such as video distribution services.

DSR compatible LB is a prerequisite. Big5 or Citrix NetScaler are capable for DSR.

 

Let me explain packet flow.

f:id:midorihige35:20210507112459p:plain

DSR

Client requests LB , LB forwards backend server , and backend server replies directly to client .

 

 

Source IP

Destination IP

Client IP

VIP of LB

Client IP

Backend server IP

Backend server IP

Client IP

 

The point is backend server does not send back the request to LB.

LB just passes only the client request, it reduces process on LB, does not become a bottleneck.

 

LB does not change source IP address, forwards to backend server in .

 

It performes asymmetric routing, if the Layer3 switch (L3SW) manages TCP session control, drops the reply packet. You must configure L3SW not to manage the sessions.

 

 

2. Source NAT on LB (Not DSR)

 

The case backend server records the source IP address, SNAT does not required on LB.

LB located inline, it can perform easily.

 

f:id:midorihige35:20210507112847p:plain


But LB has 1-armed and LB does not support DSR, leads complicated design.

I meant say it does not realize, but you had better consider following options.

 

 

If your stakeholder does not allow the options above, I recommend the following design.

 

f:id:midorihige35:20210507112852p:plain

 

Source IP

Destination IP

Client IP

VIP of LB

Client IP

Backend server IP

Backend server IP

Client IP

VIP of LB

Client IP

 

Backend servers should reply to LB VIP in , their default gateway must be LB VIP address.

If backend servers should access NTP server, logging server or MTA on different subnet, add static route for them. It might be a L3SW address.

 

 

 

 

日本語はここから

 

Load Balancer (以下LB) SNATに関する質問をいただいたので、こちらにメモします。

NSX Datacenter for vSphere がDSRに対応していないため、この質問は何年も前からよくいただいています。

 

 

1.DSR (Direct Server Return)とは

動画配信サービスなど、高いスループットを必要とするアプリケーションの可用性を高めるための LBの一機能。

 

Client (端末) からのリクエストは LB を経由してバックエンドのサーバに送られます。

バックエンドのサーバはこれを LB に戻すことなく、直接 Gateway に戻sy。

戻りのパケットは LB を経由しないため、LB の処理が少なくなり、オーバーヘッドを減らせるのがメリット。

 

LB は自分にパケットが戻らないように送信元IPアドレス (端末のIP)を付け替えずにバックエンドのサーバにパケットを送ります。

 

Gateway より先では、非対称のルーティングを行うことになるので、セッションを管理する機器があるとこれを落とす (破棄する) ことになるのが留意事項となります。

またNSX-vのLBなど、DSRに対応していないLBのもあるので、この点に留意します。 

 

 

2.LBIPアドレス変換(Source IP Network Address Translation, 以下 SNATと記載)

 

バックエンドのサーバが送信元のIPアドレスを記録するため、LB でのSNAT を行わないで欲しい(Client IPを保持したままバックエンドサーバに送りたい)というケースがあります。

 

構成パターンとしては、インライン (2-armed) のケースではほとんど問題にならないのですが、1-armedでは少し複雑な構成となります。

 

1-armed, SNAT有とした場合の代替手段として、LB X-Forwarded-For (以下XFF) HTTP ヘッダを挿入することで、 LB SNAT を行っても、Souce IP (端末のIP) を知ることはできます。

バックエンドのサーバが XFF に対応していることが前提条件ですが、それほど難しいことはなさそうです。

こちらのリンクを拝見しましたが、Apache ではLogFormatに"%{X-Forwarded-For}i"を入れるだけのようです。

 <https://www.suzu6.net/posts/244-apache-log-x-forwarded-for/>

 

1-armed, SNAT無とした場合、バックエンドサーバからClient IP宛のパケットをLB VIPに戻すために、バックエンドサーバのDefault GWLB VIPにします。

また、バックエンドサーバは自らが提供するサービスだけでなく、クライアントとしてMTANTPサーバなどにアクセスする必要があるので、これらに対応するためスタティックルートを設定する必要があります。

これを忘れるとバックエンドサーバから別セグメントへの通信ができません。

 

稀に社内イントラ向けのバックエンドサーバではClient IPレンジが決まっているというケースもあるので、その場合はClient IPレンジのGatewayLB VIPとしてスタティックルートに設定することもあります。

この場合はDefault GWとしてLayer3スイッチのアドレスを設定します。

 

以上となります。

最後まで読んでいただきありがとうございました。