[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Selecting source ip

On 28 May 2003 at 15:30, brian moore wrote:

> On Wed, May 28, 2003 at 11:02:27PM +0200, Stefan Neufeind wrote:
> > when I request a file from a linux box using lynx the source ip of
> > my request is the ip of eth0. But how can I change the source ip to
> > other ips which are also bound to eth0 (via eth0:0 etc.)? Do I need
> > to change the default gate from eth0 to eth0:0 for example? Isn't
> > there a way to just change the source ip for all programs I will
> > execute in my current environment / bash without affecting other
> > programs / tasks?
> Not without rewriting the programs.
> In geekese, the programs open their socket with code like this:
>     my_addr = sa_zero;
>     my_addr.sin_family = AF_INET;
>     my_addr.sin_addr.s_addr = INADDR_ANY;
>     if ( ( bind( fd, (struct sockaddr *) &my_addr, 
>            sizeof(struct sockaddr_in))) < 0 ) {
>  fprintf(stderr,"bind failed\n");
>  exit(1);
>     }
> (Pretty standard socket code...)
> The catch is the 'INADDR_ANY', which tells the kernel "hey, just grab
> any handy IP and use that!".  On most systems (not just Linux, most
> Unix systems and probably Windows as well), that means "use the IP
> nearest to the destination", or for single-homed machines, the IP of
> eth0 or whatever your default gateway sits on.
> This value is filled in by the kernel, in other words.
> You could change how it behaves be swapping eth0 and eth0:1, assuming
> they are both on the same subnet.

You mean swapping through which "network card" the traffic goes out, 
right? Hmm, are there kernel patches or something so you can set the 
"right IP" for the current environment? Like setting it in a bash for 
all subsequent programs? So you could have different settings in 
different environments?

Reply to: