简体   繁体   English

如何理解NetworkInterface和InetAddress概念?

[英]how to understand NetworkInterface and InetAddress concept?

I think in java, NetworkInterface is abstraction of network card . 我认为在Java中,NetworkInterface是网卡的抽象。 If this is right , why one NetworkInterface contains more than one InetAddress ? 如果正确,为什么一个NetworkInterface包含多个InetAddress

for example this code in my macbook : 例如我的macbook中的以下代码:

NetworkInterface en0 = NetworkInterface.getByName("en0");
Enumeration<InetAddress> adrs = en0.getInetAddresses() ;
while(adrs.hasMoreElements()){
    InetAddress adr = adrs.nextElement();
    System.out.println(adr.getHostAddress());
}

Output: 输出:

fe80:0:0:0:7a31:c1ff:feb7:a3a2%4
192.168.1.100

There are two address, but I didn't use IPv6. 有两个地址,但是我没有使用IPv6。

My question is that, how to understand this two concepts? 我的问题是,如何理解这两个概念? What's their relationship? 他们是什么关系

why one NetworkInterface contains more than one InetAddress? 为什么一个NetworkInterface包含多个InetAddress?

Because you can configure an NIC with multiple addresses. 因为您可以配置具有多个地址的NIC。 This has been the case for about twenty years. 大约二十年来一直是这种情况。

I didn't use IPv6 我没有使用IPv6

Somebody did. 有人做到了 Maybe you're using DHCP and it came from there. 也许您使用的是DHCP,它来自那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM