I have two interfaces on my server, eth0 and eth0:0. Those are two different external IP addresses and obviously two different reverse domains.
When I open a IO::Socket::INET connection, Perl uses the eth0 interface by default. I would like to use the second interface (eth0:0) because this has a different IP and I dont want to use my main IP or domain.
I have absolutely no idea how to select which interface to connect through.
Here's the code I use to open a socket:
my $sock = new IO::Socket::INET(PeerAddr => $server,
PeerPort => $serverPort,
Proto => 'tcp') or
die "Can't connect to server: $!";
You have to give IO::Socket::INET the address of the interface you want to use as LocalAddr
parameter. Imagine that 10.0.0.1
is the IP address of eth0 and 10.0.0.2
the IP address of eth0:0, then it would work like this.
my $sock = new IO::Socket::INET(PeerAddr => $server,
PeerPort => $serverPort,
Proto => 'tcp'
LocalAddr => '10.0.0.2') or
die "Can't connect to server: $!";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With