perlCrazy has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

want to change the ip address(basically want to use vip) when using DBI connect method. Is there any way to set vip forcibly or set some variable so that on destination side when we check incoming connection, it should see vip(PIP which is not same to real host ip) what we are passing via connect method.
Any help will be appreciated. Thanks.

Adding some more information:

lo:1 is already configured on hosts. How we can dynamically change outbound traffic for a process from eth -> lo:1.
example: have one perl program, using dbi->connect() method for connection to RDBMS. once connection gets established if check incoming connection on db host,it always sees real host ip address. my requirement is to change the routing via lo:1 dynamically in program so that it will see vip ip address. any possibility ?

  • Comment on How to modify source ip address during connection to DB via DBI

Replies are listed 'Best First'.
Re: How to modify source ip address during connection to DB via DBI
by Corion (Patriarch) on Apr 25, 2014 at 06:36 UTC

    DBI has no concept of "IP address". If your database driver has such a parameter, maybe it is documented in the documentation of the DBD.

    If you want to connect to a host from a multihomed machine and want to specify the source address that is used in a general way, you will have to look at the routing table of the multihomed machine and configure it properly.

Re: How to modify source ip address during connection to DB via DBI ( LocalAddr bind address)
by Anonymous Monk on Apr 25, 2014 at 06:56 UTC
      Thanks for response. Looking at some other options as well. Can we change outbound network interface dynamically for specific process ? looked at use IO::Interface qw(:flags);getIng permission denied when trying to change. Is this require root permission. can we do without root, want to implement in user space.
      my $s = IO::Socket::INET->new(Proto => 'udp'); my @interfaces = $s->if_list; for my $if (@interfaces) { print "interface = $if\n"; my $flags = $s->if_flags($if); print "addr = ",$s->if_addr($if),"\n", "broadcast = ",$s->if_broadcast($if),"\n", "netmask = ",$s->if_netmask($if),"\n", "dstaddr = ",$s->if_dstaddr($if),"\n", print "is running\n" if $flags & IFF_RUNNING; print "is broadcast\n" if $flags & IFF_BROADCAST; print "is loopback\n" if $flags & IFF_LOOPBACK; print "is promiscuous\n" if $flags & IFF_PROMISC; print "is multicast\n" if $flags & IFF_MULTICAST; print "is notrailers\n" if $flags & IFF_NOTRAILERS; print "is noarp\n" if $flags & IFF_NOARP; } my $interface = $s->addr_to_interface('127.0.0.1'); # my $oldaddr = $s->if_addr('eth0'); $s->if_addr('lo','X.X.X.X') || die "couldn't set address: $!";

        Yeah, this enters the realm of system programming ... firewalls and things like that ... its frequently common for linux and alikes to restrict socket operations for regular users

        Also IO::Interface tells you the new/better interface is IO::Interface::Simple