Table of Contents

Prototype: ip2host(ip)

Return type: string

The return value is cached.

Description: Returns the primary name-service host name for the IP address ip.

Uses whatever configured name service is used by the resolver library to translate an IP address to a hostname. IPv6 addresses will also resolve, if supported by the resolver library.

Note that DNS lookups may take time and thus cause CFEngine agents to wait for responses, slowing their progress significantly.


  • ip: string - IP address (IPv4 or IPv6) - in the range: .*


body common control
      bundlesequence => { "reverse_lookup" };

bundle agent reverse_lookup
      "local4" string => ip2host("");

      # this will be localhost on some systems, ip6-localhost on others...
      "local6" string => ip2host("::1");

      "we got local4" if => isvariable("local4");

      "local4 is $(local4)";
      "local6 is $(local6)";


R: we got local4

See also: host2ip(), iprange(), isipinsubnet()

History: Was introduced in version 3.1.3, Nova 2.0.2 (2010)