abyin007
abyin007

Reputation: 401

Is underscore support in hostname?

In my unix vm, I can give the following entry in /etc/hosts ABC_XYZ_HOSTNAME.abc.com 15.115.112.*** and after that I can "ping ABC_XYZ_HOSTNAME.abc.com" successfully. But my code is breaking at

InetAddresses.forString(ip)

with exception, IllegalArgumentException with IP string literal is not valid.

So the question is, is underscore supported hostname or something else is wrong here?

Upvotes: 1

Views: 1111

Answers (1)

Aleh Maksimovich
Aleh Maksimovich

Reputation: 2650

You can't use DNS names with InetAddresses.forString. The javadoc for this method states:

Returns the InetAddress having the given string representation.

This deliberately avoids all nameservice lookups (e.g. no DNS).

Parameters: ipString - String containing an IPv4 or IPv6 string literal, e.g. "192.168.0.1" or "2001:db8::1"

DNS name is not a valid value.

For DNS lookup of your address you should use

InetAddress.getByName(host)

Upvotes: 2

Related Questions