最近在看Envoy文檔拓提,看到Tproxy不認(rèn)識(shí),找資料記錄一下:
Dnat:通過iptable nat表變更目標(biāo)IP和PORT,需要修改數(shù)據(jù)包鹉胖,走IPTABLE需要過內(nèi)核。
Redirect:特殊的Dnat,只變更目標(biāo)端口够傍,這種場(chǎng)景下只有兩臺(tái)機(jī)器通訊甫菠。
TPROXY:開啟TCP/IP?IP_TRANSPARENT標(biāo)志,數(shù)據(jù)在兩個(gè)SOCKTS間復(fù)制冕屯,proxy服務(wù)器連接如下:
proxy_ip:proxy_port? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?downstream_ip:downstream_port (pid=xxx,fd=5)
downstream_ip:downstream_port? ? ? ? ? ? upstream_ip:upstream_port(pid=xxx,fd=6)
關(guān)鍵在與upstream host連接時(shí)寂诱,使用downstream ip and port,just like proxy (envoy) not exits.
這種場(chǎng)景不走kernel,不需要開啟ip_forward,不需要開啟connection_tracking。
Envoy文檔提及SO_ORIGINAL_DST TCP/IP SO OPTIONS安聘,這個(gè)參數(shù)只能用于DNAT及其變種REDIRECT模式痰洒,不能用于TPROXY模式瓢棒。用于獲取需要重定向的目標(biāo)地址。
source?http://gsoc-blog.ecklm.com/iptables-redirect-vs.-dnat-vs.-tproxy/