Class DNS

java.lang.Object
org.apache.hadoop.net.DNS

@LimitedPrivate({"HDFS","MapReduce"}) @Unstable public class DNS extends Object
A class that provides direct and reverse lookup functionalities, allowing the querying of specific network interfaces or nameservers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DNS()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getDefaultHost(String strInterface)
    Returns the default (first) host name associated by the default nameserver with the address bound to the specified network interface
    static String
    getDefaultHost(String strInterface, String nameserver)
     
    static String
    getDefaultHost(String strInterface, String nameserver, boolean tryfallbackResolution)
    Returns the default (first) host name associated by the provided nameserver with the address bound to the specified network interface
    static String
    getDefaultIP(String strInterface)
    Returns the first available IP address associated with the provided network interface or the local host IP if "default" is given.
    static String[]
    getHosts(String strInterface)
    Returns all the host names associated by the default nameserver with the address bound to the specified network interface
    static String[]
    getHosts(String strInterface, String nameserver, boolean tryfallbackResolution)
    Returns all the host names associated by the provided nameserver with the address bound to the specified network interface
    static String[]
    getIPs(String strInterface)
     
    static String[]
    getIPs(String strInterface, boolean returnSubinterfaces)
    Returns all the IPs associated with the provided interface, if any, in textual form.
    getIPsAsInetAddressList(String strInterface, boolean returnSubinterfaces)
    Returns all the IPs associated with the provided interface, if any, as a list of InetAddress objects.
    static String
    Returns the hostname associated with the specified IP address by the provided nameserver.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DNS

      public DNS()
  • Method Details

    • reverseDns

      public static String reverseDns(InetAddress hostIp, @Nullable String ns) throws NamingException
      Returns the hostname associated with the specified IP address by the provided nameserver. Loopback addresses
      Parameters:
      hostIp - The address to reverse lookup
      ns - The host name of a reachable DNS server
      Returns:
      The host name associated with the provided IP
      Throws:
      NamingException - If a NamingException is encountered
    • getIPs

      public static String[] getIPs(String strInterface) throws UnknownHostException
      Parameters:
      strInterface - input strInterface.
      Returns:
      Like getIPs(String, boolean), but returns all IPs associated with the given interface and its subinterfaces.
      Throws:
      UnknownHostException - If no IP address for the local host could be found.
    • getIPs

      public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException
      Returns all the IPs associated with the provided interface, if any, in textual form.
      Parameters:
      strInterface - The name of the network interface or sub-interface to query (eg eth0 or eth0:0) or the string "default"
      returnSubinterfaces - Whether to return IPs associated with subinterfaces of the given interface
      Returns:
      A string vector of all the IPs associated with the provided interface. The local host IP is returned if the interface name "default" is specified or there is an I/O error looking for the given interface.
      Throws:
      UnknownHostException - If the given interface is invalid
    • getDefaultIP

      public static String getDefaultIP(String strInterface) throws UnknownHostException
      Returns the first available IP address associated with the provided network interface or the local host IP if "default" is given.
      Parameters:
      strInterface - The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) or the string "default"
      Returns:
      The IP address in text form, the local host IP is returned if the interface name "default" is specified
      Throws:
      UnknownHostException - If the given interface is invalid
    • getHosts

      public static String[] getHosts(String strInterface, @Nullable String nameserver, boolean tryfallbackResolution) throws UnknownHostException
      Returns all the host names associated by the provided nameserver with the address bound to the specified network interface
      Parameters:
      strInterface - The name of the network interface or subinterface to query (e.g. eth0 or eth0:0)
      nameserver - The DNS host name
      tryfallbackResolution - if true and if reverse DNS resolution fails then attempt to resolve the hostname with InetAddress.getCanonicalHostName() which includes hosts file resolution.
      Returns:
      A string vector of all host names associated with the IPs tied to the specified interface
      Throws:
      UnknownHostException - if the given interface is invalid
    • getHosts

      public static String[] getHosts(String strInterface) throws UnknownHostException
      Returns all the host names associated by the default nameserver with the address bound to the specified network interface
      Parameters:
      strInterface - The name of the network interface to query (e.g. eth0)
      Returns:
      The list of host names associated with IPs bound to the network interface
      Throws:
      UnknownHostException - If one is encountered while querying the default interface
    • getDefaultHost

      public static String getDefaultHost(@Nullable String strInterface, @Nullable String nameserver, boolean tryfallbackResolution) throws UnknownHostException
      Returns the default (first) host name associated by the provided nameserver with the address bound to the specified network interface
      Parameters:
      strInterface - The name of the network interface to query (e.g. eth0)
      nameserver - The DNS host name
      tryfallbackResolution - Input tryfallbackResolution.
      Returns:
      The default host names associated with IPs bound to the network interface
      Throws:
      UnknownHostException - If one is encountered while querying the default interface
    • getDefaultHost

      public static String getDefaultHost(@Nullable String strInterface) throws UnknownHostException
      Returns the default (first) host name associated by the default nameserver with the address bound to the specified network interface
      Parameters:
      strInterface - The name of the network interface to query (e.g. eth0). Must not be null.
      Returns:
      The default host name associated with IPs bound to the network interface
      Throws:
      UnknownHostException - If one is encountered while querying the default interface
    • getDefaultHost

      public static String getDefaultHost(@Nullable String strInterface, @Nullable String nameserver) throws UnknownHostException
      Parameters:
      strInterface - The name of the network interface to query (e.g. eth0)
      nameserver - The DNS host name
      Returns:
      Returns the default (first) host name associated by the provided nameserver with the address bound to the specified network interface.
      Throws:
      UnknownHostException - If one is encountered while querying the default interface
    • getIPsAsInetAddressList

      public static List<InetAddress> getIPsAsInetAddressList(String strInterface, boolean returnSubinterfaces) throws UnknownHostException
      Returns all the IPs associated with the provided interface, if any, as a list of InetAddress objects.
      Parameters:
      strInterface - The name of the network interface or sub-interface to query (eg eth0 or eth0:0) or the string "default"
      returnSubinterfaces - Whether to return IPs associated with subinterfaces of the given interface
      Returns:
      A list of all the IPs associated with the provided interface. The local host IP is returned if the interface name "default" is specified or there is an I/O error looking for the given interface.
      Throws:
      UnknownHostException - If the given interface is invalid