3

I am trying to make a perl script to send a get request to applications I have created. My applications are running on separate servers, so in order to make it seem like a domain, I added the ip's to my /etc/hosts file. My hosts file looks like:

10.1.10.50     test1.domain.com
10.1.10.51     test2.domain.com

When I run my script, which basically just does a get:

my $res = $mech->get("http://test1.domain.com/1");

I get the following error:

Error GETING http://test1.domain.com/1: test1.domain.com: unable to resolve

I am assuming that my perl script is not using my /etc/hosts file, is there anyway to make it check the hosts file for DNS or to setup domains in the program itself?

Thank you

Eumcoz
  • 2,388
  • 1
  • 21
  • 44
  • 1
    What do you get from `perl -MSocket=inet_ntoa -E'my @h = gethostbyname($ARGV[0]); say inet_ntoa($_) for @h[4..$#h]' test1.domain.com`? – ikegami Dec 20 '12 at 22:18
  • 1
    What do you get from `set | grep _proxy`? Did you tell LWP to use a proxy? – ikegami Dec 20 '12 at 22:19
  • @ikegami 10.1.10.50 is the output. I did not tell LWP to use a proxy, how do I do that. The output to the second command is no_proxy=localhost, 127.0.0.0/8 – Eumcoz Dec 20 '12 at 22:22
  • Then I can't explain it. – ikegami Dec 20 '12 at 22:28
  • 1
    Actually, what does `perl -MSocket -E'say inet_ntoa(inet_aton($ARGV[0]))' test1.domain.com` give? – ikegami Dec 20 '12 at 22:37
  • Maybe running your script with `-d:Trace` will tell how the name is getting resolved. – ikegami Dec 20 '12 at 22:40
  • That command also returns 10.1.10.50. I will try running a trace and see what I can find out from that, thanks for the ideas. – Eumcoz Dec 20 '12 at 22:45

1 Answers1

0

Perl does not "use the /etc/hosts file". It's using the same network stack as the rest of the machine. It is the network layer that is using /etc/hosts.

Do those hostnames resolve from the shell? What do they show?

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • Yes, I can ping test1.domain.com and test2.domain.com from my terminal. I am using Ubuntu 12.04 server if that matters. – Eumcoz Dec 20 '12 at 22:12