简体   繁体   English

Java InetAddress.getByName和/ etc / hosts

[英]Java InetAddress.getByName & /etc/hosts

With

java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

And aliases in the host file like 和主机文件中的别名一样

10.0.0.4 bar.com
10.0.0.5 a-a.foo.com a-b.foo.com a-c.foo.com ...

Im able to resolve bar.com with InetAddress.getByName("bar.com"). 我无法使用InetAddress.getByName(“ bar.com”)解析bar.com。 But If the line is getting bigger like 30 hosts and longer than 767 Chars a UnknownHostException is thrown. 但是,如果该行越来越大,例如30台主机,并且长度超过767个字符,则会引发UnknownHostException。

How to let Java handle this line as should? 如何让Java应对这一行?

For example "ping bar.com" is doing the lookup correctly. 例如,“ ping bar.com”正确执行了查找。

There's a limit on the number of aliases per ip address depending on your system. 每个ip地址的别名数量受到限制,具体取决于您的系统。 Try adding another line for each x aliases where x is max number of aliases for your system which is 34 in your case. 尝试为每个x别名添加另一行,其中x是系统的最大别名数(在您的情况下为34)。

https://library.netapp.com/ecmdocs/ECMP1368834/html/GUID-C6F3B6D1-232D-44BB-A76C-3304C19607A3.html https://library.netapp.com/ecmdocs/ECMP1368834/html/GUID-C6F3B6D1-232D-44BB-A76C-3304C19607A3.html

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

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