监听本地地址效果差异分析127.0.0.1/0.0.0.0/192.168.*

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)

最近研究本地监听不同的地址127.0.0.1/IP地址/0.0.0.0,形成的差异效果,发现差异还是挺大的:需要配置时谨慎以对。
如果遇到局域网访问失败等情况,可以参考下面检查一下是否配置异常。

测试主机环境:Mac OS 主机IP 192.168.0.102

 

归结起来来看:

1. 使用127.0.0.1作为监控地址,仅支持本地通过127.0.0.1访问。
2. 使用0.0.0.01作为监控地址,支持所有:支持本地通过127.0.0.1或IP访问,支持其它主机通过IP访问。
3. 使用IP作为监控地址,支持本地以IP访问和其它主机通过IP访问。

下面是各种地址的测试情况。

 

监听127.0.0.1:

查看监听:netstat -an
tcp4       0      0  127.0.0.1.28881     *.*                    LISTEN 

效果:
1. 本机通过127.0.0.1访问成功,网络接口-loopback
2. 本机通过局域网IP 192.168.0.102 访问失败,网络接口-loopback
3. 同一局域网下的外部主机通过局域网IP 192.168.0.102访问失败,网络接口-et1

 

监听192.168.0.102:

查看监听:netstat -an
tcp4       0      0  192.168.0.102.1086     *.*                    LISTEN 

效果:
1. 本机通过127.0.0.1访问失败,网络接口-loopback
2. 本机通过局域网IP 192.168.0.102 访问成功,网络接口-loopback
3. 同一局域网下的外部主机通过局域网IP 192.168.0.102访问成功,网络接口-et1

 

监听0.0.0.0:

查看监听:netstat -an
tcp4       0      0  *.28881     *.*                    LISTEN 

效果:
1. 本机通过127.0.0.1访问成功,网络接口-loopback
2. 本机通过局域网IP 192.168.0.102 访问成功,网络接口-loopback
3. 同一局域网下的外部主机通过局域网IP 192.168.0.102访问成功,网络接口-et1

 

127.0.0.1的ACK抓包情况:

    127.0.0.1抓取服务器返回ACK包的情况如下;其它访问方法:抓取成功和失败情况和这个类似。 

    外部连接包:使用局域网IP访问,返回ACK/RST,连接拒绝,连接被重置。网络接口 et1。
    本机连接包,使用本地IP访问,返回ACK/RST,连接拒绝,连接被重置。网络接口 loopback。
    本机连接包,使用127.0.0.1,连接成功。网络接口loopback。

et0-抓到的局域网其它主机访问时的ACK返回包
Frame 26: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
Ethernet II, Src: Apple_cd:dc:e9 (20:c9:d0:cd:dc:e9), Dst: AsustekC_43:3b:77 (14:da:e9:43:3b:77)
Internet Protocol Version 4, Src: 192.168.0.102, Dst: 192.168.0.103
Transmission Control Protocol, Src Port: 28881, Dst Port: 1591, Seq: 1, Ack: 1, Len: 0
    Source Port: 28881
    Destination Port: 1591
    [Stream index: 5]
    [TCP Segment Len: 0]
    Sequence number: 1    (relative sequence number)
    [Next sequence number: 1    (relative sequence number)]
    Acknowledgment number: 1    (relative ack number)
    0101 .... = Header Length: 20 bytes (5)
    Flags: 0x014 (RST, ACK)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...1 .... = Acknowledgment: Set
        .... .... 0... = Push: Not set
        .... .... .1.. = Reset: Set
            [Expert Info (Warning/Sequence): Connection reset (RST)]
                [Connection reset (RST)]
                [Severity level: Warning]
                [Group: Sequence]
        .... .... ..0. = Syn: Not set
        .... .... ...0 = Fin: Not set
        [TCP Flags: ·······A·R··]
    Window size value: 0
    [Calculated window size: 0]
    [Window size scaling factor: -1 (unknown)]
    Checksum: 0x2e1b [unverified]
    [Checksum Status: Unverified]
    Urgent pointer: 0

loopback-抓到的本机通过192.168.0.102访问时的ACK返回包
Frame 2: 44 bytes on wire (352 bits), 44 bytes captured (352 bits) on interface 0
Null/Loopback
Internet Protocol Version 4, Src: 192.168.0.102, Dst: 192.168.0.102
Transmission Control Protocol, Src Port: 28881, Dst Port: 58254, Seq: 1, Ack: 1, Len: 0
    Source Port: 28881
    Destination Port: 58254
    [Stream index: 0]
    [TCP Segment Len: 0]
    Sequence number: 1    (relative sequence number)
    [Next sequence number: 1    (relative sequence number)]
    Acknowledgment number: 1    (relative ack number)
    0101 .... = Header Length: 20 bytes (5)
    Flags: 0x014 (RST, ACK)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...1 .... = Acknowledgment: Set
        .... .... 0... = Push: Not set
        .... .... .1.. = Reset: Set
            [Expert Info (Warning/Sequence): Connection reset (RST)]
                [Connection reset (RST)]
                [Severity level: Warning]
                [Group: Sequence]
        .... .... ..0. = Syn: Not set
        .... .... ...0 = Fin: Not set
        [TCP Flags: ·······A·R··]
    Window size value: 0
    [Calculated window size: 0]
    [Window size scaling factor: -1 (unknown)]
    Checksum: 0x8237 [unverified]
    [Checksum Status: Unverified]
    Urgent pointer: 0


loopback-抓到的本机通过127.0.0.1访问时的ACK返回包
Frame 6: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Null/Loopback
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 28881, Dst Port: 58327, Seq: 0, Ack: 1, Len: 0
    Source Port: 28881
    Destination Port: 58327
    [Stream index: 1]
    [TCP Segment Len: 0]
    Sequence number: 0    (relative sequence number)
    [Next sequence number: 0    (relative sequence number)]
    Acknowledgment number: 1    (relative ack number)
    1011 .... = Header Length: 44 bytes (11)
    Flags: 0x012 (SYN, ACK)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...1 .... = Acknowledgment: Set
        .... .... 0... = Push: Not set
        .... .... .0.. = Reset: Not set
        .... .... ..1. = Syn: Set
            [Expert Info (Chat/Sequence): Connection establish acknowledge (SYN+ACK): server port 28881]
                [Connection establish acknowledge (SYN+ACK): server port 28881]
                [Severity level: Chat]
                [Group: Sequence]
        .... .... ...0 = Fin: Not set
        [TCP Flags: ·······A··S·]
    Window size value: 65535
    [Calculated window size: 65535]
    Checksum: 0xfe34 [unverified]
    [Checksum Status: Unverified]
    Urgent pointer: 0
    Options: (24 bytes), Maximum segment size, No-Operation (NOP), Window scale, No-Operation (NOP), No-Operation (NOP), Timestamps, SACK permitted, End of Option List (EOL)
        TCP Option - Maximum segment size: 16344 bytes
        TCP Option - No-Operation (NOP)
        TCP Option - Window scale: 5 (multiply by 32)
        TCP Option - No-Operation (NOP)
        TCP Option - No-Operation (NOP)
        TCP Option - Timestamps: TSval 253620883, TSecr 253620883
        TCP Option - SACK permitted
        TCP Option - End of Option List (EOL)

 

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)

 

你可能感兴趣的:(网络)