跳转至主要内容
在同一子网内为模块配置两个接口,并不意味着模块拥有两个独立的输入/输出接口。虽然模块确实拥有两个输入接口,但STCP在发送数据包时仅使用其中一个接口。无论客户端连接到哪个接口,STCP都会采用这种方式进行传输。

 

例如,在 172.16.1.0/24 子网中存在这两个接口时
%phx_vos#sdlmux.m16.10.11-2 IP: 172.16.1.116 MAC: 00:00:a8:42:52:22
%phx_vos#sdlmux.m16.11.11-2 IP: 172.16.1.226 MAC: 00:00:a8:43:52:22

 

请注意图1中,发往172.16.1.226的数据包使用了目标MAC地址00:00:a8:43:52:22,但回复却来自00:00:a8:42:52:22, 该地址属于172.16.1.116,尽管数据包显示回复来自172.16.1.226。

 

11:04:57.117 Xmit Ether Dst 00:00:a8:43:52:22  Src 00:00:a8:42:3b:6e Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   2c, ID 2045, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  0363, Src ac100122, Dst ac1001e2
TCP from 172.16.1.34.49183 to 172.16.1.226.telnet
. . .
11:04:57.130 Rcvd Ether Dst 00:00:a8:42:3b:6e  Src 00:00:a8:42:52:22 Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   2c, ID  7c8, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  1be0, Src ac1001e2, Dst ac100122
TCP from 172.16.1.226.telnet to 172.16.1.34.49183
. . .
图1 – 向模块发送的连接请求(在客户端捕获的跟踪信息)
如果模块主动建立连接而非被动接收连接,它将始终使用第一个(116)接口。
13:01:36.479 Rcvd Ether Dst 00:00:a8:42:3b:6e  Src 00:00:a8:42:52:22 Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   2c, ID 4a33, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  d9e2, Src ac100174, Dst ac100122
TCP from 172.16.1.116.49320 to 172.16.1.34.4680
. . .
图2 – 模块向另一台服务器发出的连接请求(在服务器端捕获的跟踪记录)
即使你在发送数据包时绑定到第二个(226)IP地址,该数据包仍会通过第一个(116)接口发出。
13:02:55.349 Rcvd Ether Dst 00:00:a8:42:3b:6e  Src 00:00:a8:42:52:22 Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   2c, ID 4b7a, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  d82d, Src ac1001e2, Dst ac100122
TCP from 172.16.1.226.49321 to 172.16.1.34.4680
. . .
图3 – 模块向另一台服务器发送的连接请求(在另一台服务器上捕获的跟踪信息)
客户端应用程序绑定到172.16.1.226 IP接口
仅当第一个(116)接口失效时,模块才会切换至使用第二个(226)接口。此时连接至第二个(226)接口的连接将保持有效,而连接至第一个(116)接口的连接将失败。
13:14:43.884 Xmit Ether Dst 00:00:a8:43:52:22  Src 00:00:a8:42:3b:6e Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   28, ID 5072, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  d339, Src ac100122, Dst ac1001e2
TCP from 172.16.1.34.49186 to 172.16.1.226.telnet
. . .
13:14:43.885 Rcvd Ether Dst 00:00:a8:42:3b:6e  Src 00:00:a8:42:52:22 Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   28, ID 53ef, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  cfbc, Src ac1001e2, Dst ac100122
TCP from 172.16.1.226.telnet to 172.16.1.34.49186
. . .
接口 172.16.1.116 故障——注意源 MAC 地址的变化
13:15:56.718 Xmit Ether Dst 00:00:a8:43:52:22  Src 00:00:a8:42:3b:6e Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   29, ID 50e7, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  d2c3, Src ac100122, Dst ac1001e2
TCP from 172.16.1.34.49186 to 172.16.1.226.telnet
. . .
13:15:56.719 Rcvd Ether Dst 00:00:a8:42:3b:6e  Src 00:00:a8:43:52:22 Type 0800
+(IP)
IP   Ver/HL 45, ToS  0, Len   29, ID 5552, Flg/Frg    0, TTL 3c,  Prtl  6
Cksum  ce58, Src ac1001e2, Dst ac100122
TCP from 172.16.1.226.telnet to 172.16.1.34.49186
. . .
图4 – 首个接口故障时MAC的变化(客户端采集的跟踪数据)
如何判断将使用哪个接口发送流量?
有几种方法。第一种是在远程主机或网络上使用 packet_monitor 或其他协议分析器来评估源 MAC 地址,参见图 1 至图 4。
其次是使用 netstat 查看接口状态,生成一些流量,再次运行 netstat 并进行比较。此时只有一个接口的“已传输帧”计数器应有所增加。
netstat -interface #sdlmux.m16.10.11-2; netstat -interface #sdlmux.m16.11.11-2
. . .
MAC Statistics:
Received frames                          : 1598960
Received multicast and broadcast frames  : 1564503
Received octets                          : 258513766
Transmitted frames                       : 531
Transmitted octets                       : 50850
. . .
MAC Statistics:
Received frames                          : 1603838
Received multicast and broadcast frames  : 1569292
Received octets                          : 259291185
Transmitted frames                       : 15
Transmitted octets                       : 947
. . .
ready  13:29:48
ping 172.16.1.34
Pinging host 172.16.1.34 : 172.16.1.34
ICMP Echo Reply:TTL 60 time = 0 ms
ICMP Echo Reply:TTL 60 time = 0 ms
ICMP Echo Reply:TTL 60 time = 0 ms
ICMP Echo Reply:TTL 60 time = 0 ms
Host 172.16.1.34 replied to all 4 of the 4 pings
ready  13:29:55
netstat -interface #sdlmux.m16.10.11-2; netstat -interface #sdlmux.m16.11.11-2
. . .
MAC Statistics:
Received frames                          : 1603142
Received multicast and broadcast frames  : 1568591
Received octets                          : 259187870
Transmitted frames                       : 535
Transmitted octets                       : 51274
. . .
MAC Statistics:
Received frames                          : 1607492
Received multicast and broadcast frames  : 1572869
Received octets                          : 259880655
Transmitted frames                       : 15
Transmitted octets                       : 947
. . .
图5 – 使用netstat比较已传输帧计数器
第三种方法是连接到另一台系统上的服务,并查看其使用的本地源地址。除非你明确绑定到另一个地址,否则源IP地址将对应于活动接口。
netstat -numeric
Active connections
Proto Recv-Q Send-Q  Local Address      Foreign Address    (state)
. . .
tcp        0      0  172.16.1.116:49369 172.16.1.34:23     ESTABLISHED
. . .
图6 – 用于出站连接的接口
我认为在同一子网内配置多个接口只会造成混乱,通常得不偿失。若因特殊需求需在同一子网使用两个IP地址,建议为首个接口添加别名。
ifconfig #sdlmux.m16.10.11-2 172.16.1.226 -add -alias
将IP地址172.16.1.226添加至接口%phx_vos#sdlmux.m16.10.11-2
%phx_vos#sdlmux.m16.10.11-2: <UP, BROADCAST, RUNNING, NOFORWARDBROADCAST, KEEPAL
+IVE>
172.16.1.116 netmask 0xffffff00 broadcast 172.16.1.255
Number of additional address(es): 1
172.16.1.226
图7 – 为接口添加别名