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

I have been using a pm that does syslog sending, Syslog.pm. Works great, but when I put it on a multi-interface Linux box, I can't make it use the correct interface. I need it to go out a certain ip address and can't. The pm itself doesn't allow you to specify the 'from' address. Maybe if I understand how a pm selects what interface to use, maybe I can rig it. Any suggestions ? Thanks

Retitled by davido from 'Interface Selection in a PM'.

  • Comment on Network interface selection in a Perl module.

Replies are listed 'Best First'.
Re: Network interface selection in a Perl module. (route)
by tye (Sage) on Jan 28, 2005 at 21:05 UTC

    In a normal TCP setup, you should not need to specify which interface is used to send network packets. The operating system should figure this out for you automatically. It is even explicitly possible that more than one interface could be used (to increase throughput or to allow network failures to be routed around).

    If the operating system is selecting the wrong interface, then the way to fix this is to adjust your routing table so this incorrect interface is no longer considered a candidate for traffic destined for the remote address in question.

    If you have difficulty figuring out how to do this, include the output from "route print" and remote IP address you are trying to connect and/or send to.

    - tye        

      yep, you can add a static route pointing to your syslog machine going out your interface you want.... looks something like ..... # route add -host x.x.x.x dev interfacename
Re: Network interface selection in a Perl module.
by nobull (Friar) on Jan 29, 2005 at 09:31 UTC
    I think you have here is an X-Y problem.

    You want to select the source IP address but you ask how to select the interface.

    Selecting the interface is difficult but selecting the IP address is easy. You use bind().

    You don't say which Syslog module you are using so I will assume Sys::Syslog. I've looked in Sys::Syslog and it's pure Perl so although it does not currently take a source IP address argument you could easily hack it to set the source IP address of the socket between creating and connecting.