使用tcpdump測試反向代理和lvs的nat區別

關於反向代理,一個請求過來,實際反向代理服務器要和兩個對象作3次握手html

客戶端到反向代理服務器,是一個3次握手node

反向代理服務器請求後端web服務器,是一個3次握手linux

 

lvs的nat和反向代理不一樣。web

lvs實際只修改數據包的目標地址,不作其它的操做。數據包的隨機序列號seq等沒變,實際仍是客戶端和後端web服務器作的3次握手vim

 

能夠經過tcpdump抓取反向代理服務器的端口記錄和後端web服務器的端口記錄,看到一個請求過來以後,兩個請求的seq是不同的。後端

tcpdump 命令用法bash

-i 接網卡名 ,我這裏網卡是是ens33,不是eth0,服務器

port 接端口號 ,抓取哪一個端口的數據tcp

-vvv顯示的信息多一點代理

查看抓取過程

能夠看到Flag標誌位,若是是S,表示syn。 序列號seq是個隨機的值

 

 

接下來經過是研究證實,反向代理和後端web服務器,客戶端和反向代理是2個3次握手

爲了防止健康檢查的干擾,把haproxy健康檢查時間設置長一點,好比100秒,或者乾脆取消健康檢查

[root@linux-node1 ~]# vim /etc/haproxy/haproxy.cfg
[root@linux-node1 ~]# tail -3 /etc/haproxy/haproxy.cfg
   option httpchk  GET /index.html 
   balance  roundrobin
   server	linux-node2	10.0.1.106:8080	   check inter 100000 rise 3 fall 3 weight 1
[root@linux-node1 ~]# /etc/init.d/haproxy restart

而後客戶端去訪問http://10.0.1.105/test.js

 這樣請求必定是發送到node2,由於反向代理作了規則設置,js爲結尾的文件都指向了node2上

 

 抓取反向代理的80端口,看到seq是2964464279

[root@linux-node1 ~]# tcpdump -i ens33 port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 65535 bytes
02:39:39.219612 IP 10.0.1.72.56057 > linux-node1.example.com.http: Flags [S], seq 2964464279, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
02:39:39.219664 IP linux-node1.example.com.http > 10.0.1.72.56057: Flags [S.], seq 3532921320, ack 2964464280, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
02:39:39.221150 IP 10.0.1.72.56057 > linux-node1.example.com.http: Flags [.], ack 1, win 16425, length 0
02:39:39.221193 IP 10.0.1.72.56059 > linux-node1.example.com.http: Flags [S], seq 1955250633, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
02:39:39.221209 IP linux-node1.example.com.http > 10.0.1.72.56059: Flags [S.], seq 127908139, ack 1955250634, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
02:39:39.222792 IP 10.0.1.72.56059 > linux-node1.example.com.http: Flags [.], ack 1, win 16425, length 0
02:39:39.239383 IP 10.0.1.72.56057 > linux-node1.example.com.http: Flags [P.], seq 1:485, ack 1, win 16425, length 484
02:39:39.242443 IP linux-node1.example.com.http > 10.0.1.72.56057: Flags [P.], seq 1:123, ack 485, win 237, length 122
02:39:39.437364 IP 10.0.1.72.56057 > linux-node1.example.com.http: Flags [.], ack 123, win 16394, length 0
^C
9 packets captured
9 packets received by filter
0 packets dropped by kernel
[root@linux-node1 ~]# 

抓取後端web服務器的8080端口,看到seq是4209329376

[root@linux-node2 conf]# tcpdump -i ens33 port 8080 -vvv
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 65535 bytes
02:39:39.259521 IP (tos 0x0, ttl 64, id 35579, offset 0, flags [DF], proto TCP (6), length 60)
    10.0.1.105.52292 > linux-node2.example.com.webcache: Flags [S], cksum 0xaac9 (correct), seq 4209329376, win 29200, options [mss 1460,sackOK,TS val 446549531 ecr 0,nop,wscale 7], length 0
02:39:39.259574 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    linux-node2.example.com.webcache > 10.0.1.105.52292: Flags [S.], cksum 0x1701 (incorrect -> 0xaaf9), seq 2283093898, ack 4209329377, win 28960, options [mss 1460,sackOK,TS val 446504562 ecr 446549531,nop,wscale 7], length 0
02:39:39.260064 IP (tos 0x0, ttl 64, id 35580, offset 0, flags [DF], proto TCP (6), length 52)
    10.0.1.105.52292 > linux-node2.example.com.webcache: Flags [.], cksum 0x4a01 (correct), seq 1, ack 1, win 229, options [nop,nop,TS val 446549531 ecr 446504562], length 0
02:39:39.260236 IP (tos 0x0, ttl 64, id 35581, offset 0, flags [DF], proto TCP (6), length 534)
    10.0.1.105.52292 > linux-node2.example.com.webcache: Flags [P.], cksum 0xb821 (correct), seq 1:483, ack 1, win 229, options [nop,nop,TS val 446549532 ecr 446504562], length 482
02:39:39.260276 IP (tos 0x0, ttl 64, id 8696, offset 0, flags [DF], proto TCP (6), length 52)
    linux-node2.example.com.webcache > 10.0.1.105.52292: Flags [.], cksum 0x16f9 (incorrect -> 0x4817), seq 1, ack 483, win 235, options [nop,nop,TS val 446504563 ecr 446549532], length 0
02:39:39.260876 IP (tos 0x0, ttl 64, id 8697, offset 0, flags [DF], proto TCP (6), length 174)
    linux-node2.example.com.webcache > 10.0.1.105.52292: Flags [P.], cksum 0x1773 (incorrect -> 0x3575), seq 1:123, ack 483, win 235, options [nop,nop,TS val 446504564 ecr 446549532], length 122
02:39:39.261330 IP (tos 0x0, ttl 64, id 35582, offset 0, flags [DF], proto TCP (6), length 52)
    10.0.1.105.52292 > linux-node2.example.com.webcache: Flags [.], cksum 0x47a1 (correct), seq 483, ack 123, win 229, options [nop,nop,TS val 446549533 ecr 446504564], length 0
^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel
[root@linux-node2 conf]# 
相關文章
相關標籤/搜索