user4035 user4035 -5 years ago 287
Perl Question

HTTP::Request use IPv6 interface

I have a Linux machine with IPv6 support, local loopback interface:


I created a perl script that sends an HTTP request to the local virtual host:


use strict;
use warnings;

use Net::INET6Glue::INET_is_INET6;
use LWP;

my $user_agent = LWP::UserAgent->new;
my $url = 'http://lwt/docs/info.php';
my $request = HTTP::Request->new(GET => $url);
my $response = $user_agent->request($request);
if ($response->is_success) {
print $response->decoded_content;
else {

info.php file:


alias is written in /etc/hosts file like this: lwt

Currently the output is: "". So, the request is sent via IPv4.

Is it possible to tell Perl to use IPv6 interface instead?

Answer Source

In order to make an IPv6 connection, LWP has to find an IPv6 address for your hostname. Since the address you're provoding via /etc/hosts,, is an IPv4 address, this doesn't happen. You need a hosts entry like ::1 lwt so that the hostname resolves to the IPv6 loopback address instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download