Recently, the cluster will add a batch of dual network card machines, then I suddenly think how to obtain the IP address of these network cards. But the first attempt to use inetaddress did not get the expected results.
Run results here use/etc/hosts this file to the native (MAC OS environment) to obtain the relevant IP information (of course inetaddress get host name processing is not so simple, here is not detailed)
Through/etc/hosts to get
inetaddress[] Adds = Inetaddress.getallbyname ("master");
for (inetaddress T_add:adds) {
System.out.println (T_add);
}
Later on the Internet search, the relevant processing, found that many are using the way to call external commands to obtain, I personally think it is a bit awkward, and then look at the relevant Java source code, you can use this class NetworkInterface implementation, using the method
Very simply, the code intercepts as follows:
Get local related network card information similar to Ifconfig
enumeration<networkinterface> list = NetworkInterface
. Getnetworkinterfaces ();
for (; List.hasmoreelements ();) {
NetworkInterface nint = List.nextelement ();
System.out.println ("Net card:" + nint.getdisplayname ());
for (enumeration<inetaddress> addresses = nint.getinetaddresses (); addresses
. hasMoreElements ();) {
InetAddress I_adr = Addresses.nextelement ();
System.out.println ("------->" + i_adr.gethostaddress ());
}
}
You can obtain the IP address of multiple network adapters.
The results of the operation are as follows:
Net Card:en1
------->fe80:0:0:0:xxxx:xxxx:xxxx:a6c0%5
------->192.168.1.18
Net Card:en0
------->fe80:0:0:0:xxxx:xxxx:xxxx:32e5%4
------->10.xxx.xxx.xxx
Net Card:lo0
------->0:0:0:0:0:0:0:1
------->fe80:0:0:0:0:0:0:1%1
------->127.0.0.1
X means to block out real IP.
In fact, here also the MAC address to parse out.
Here are a few questions to extend:
Is the Hadoop itself to the multi-card processing mechanism, in the master host configuration hosts this file, how to modify.
What is the utilization of the NIC when it is a multiple NIC?
Recently in the Intranet trial of the next multiple network card, found as long as a network card port access network cable, another network card mouth does not connect network cable. Or you can ping this network card (not connect network cable) IP address.