1

/etc/hosts

1.1.1.1 test.example.com

DNS

2.2.2.2 test.example.com

I use below function get hosts ip address, i want get dns ip address ,when someone modify my hosts error ip, puppet facter get correct ip to overwrite

IOSocket.getaddress('test.example.com')

Community
  • 1
  • 1
CheStar
  • 3
  • 2
  • 1
    Not sure what you are trying to solve. You could inoculate yourself against shenanigans in `/etc/hosts` by tailoring `/etc/nsswitch.conf` to your needs. – Felix Frank Oct 16 '15 at 09:46

1 Answers1

2

Use Resolv::DNS

Example:

require 'resolv'
dns = Resolv::DNS.new( :nameserver => ['8.8.8.8'] )
ip = dns.getaddress( 'test.example.com' )
MMeens
  • 76
  • 3