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

Re: Configure two gateways



George P. Burdell wrote:
> allow-hotplug eth0
> iface eth0 inet static
>  address 192.168.1.200
>  netmask 255.255.255.0
>  broadcast 192.168.1.255
>  gateway 192.168.1.1
>  dns-domain lan
>  dns-nameservers 192.168.1.1
> 
> allow-hotplug eth1
> iface eth1 inet static
>  address 192.168.2.1
>  netmask 255.255.255.0
>  gateway 192.168.2.1

Do not include this last gateway.  Remove that line.  This is not your
gateway.  Your gateway you have listed in the first set for eth0.  You
said in your description that this network segment did not connect to
any other network.

Note also that you are trying to configure yourself as the gateway.
Does that make sense to you to do this?  Both the address and the
gateway are the same address.  Strangely that is actually a valid
configuration!  Some networks use this with a router that is
configured to detect this situation and to automatically route those
packets.  This made it into something of an automated configuration
since it wasn't otherwise a valid configuration.  But don't do it.

> The "route" command gives me this ("amade" is the name of the linux box):
> 
> ===============================
> Kernel IP routing table
> Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
> 192.168.2.0     *               255.255.255.0   U     0      0        0 eth1
> 192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
> default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
> default         amade-eth1      0.0.0.0         UG    0      0        0 eth1
> ===============================
> 
> What am I doing wrong here?

By including two gateways you have literally put two of them into your
routing table.  But the routing table is matched on a first match
basis.  The first match from the top wins.  The second gateway won't
ever match because all packets will match the first gateway first.
Which is good because the second one isn't valid.

> One problem is that sometimes the "route" command gives me something like:
> 
> ===============================
> Kernel IP routing table
> Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
> 192.168.2.0     *               255.255.255.0   U     0      0        0 eth1
> 192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
> default         amade-eth1      0.0.0.0         UG    0      0        0 eth1
> default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
> ===============================

Right.  If you 'ifdown eth1' and then 'ifup eth1' it will cause the
routing configuration there to be last one executed.  Or the other way
around with eth0.  It is order dependent.  Whichever one you do
first/second will cause the order of them to appear in the linear
ordering of the route table.  When you boot it is a race condition
between them as to which happens first.

> in which case the linux box cannot access the Internet, because
> "amade-eth1" seems to take precedence over the router as a gateway to
> the Internet, which of course will not work.

Hint: Don't include invalid network configuration in your file.

Hint: Interfaces are not required to have a gateway.  Normally you
have one per host even if the host has dozens of network interfaces.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: