Re: [OT] ipv4: how to choose src ip?

From: Willy Tarreau (willy@w.ods.org)
Date: Thu Dec 05 2002 - 15:58:17 EST


On Thu, Dec 05, 2002 at 08:00:54PM +0100, Tomas Szepe wrote:
 
> Suppose I have two IP addresses from the same subnet on the same
> interface, and this interface also happens to be what my default
> gateway is on, like so:
>
> /sbin/ifconfig eth1 213.168.178.209 netmask 255.255.255.192 \
> broadcast 213.168.178.255
> /sbin/ifconfig eth1:0 213.168.178.210 netmask 255.255.255.192 \
> broadcast 213.168.178.255
> /sbin/route add default gw 213.168.178.193

Honnestly, the simplest way to deal with aliases and source addresses is to
forget ifconfig/route and replace them with iproute2 (ftp.inr.ac.ru), which
lets you specify the source address among many other settings. Really a
wonderful and cleanly coded tool.

In your case, you'd call it this way :

  ip addr add 213.168.178.209/26 dev eth0
  ip addr add 213.168.178.210/26 dev eth0
  ip route add default via 213.168.178.193

When several addresses can resolve for the source, the first one is used by
default, so in the above case, it will be .209. But it's easy to specify the
other one :

  ip route add default via 213.168.178.193 src 213.168.178.210

In fact, you can even set the source of another interface, which is very useful
on point-to-point connections above private networks.

I really don't understand why modern distros don't use it by default, and still
prefer prehistoric ifconfig and route. These ones are extremely limited
regarding what the kernel can do.

Cheers,
Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Dec 07 2002 - 22:00:24 EST