Networking Forums

Networking Forums > Computer Networking > Linux Networking > How to set default gw not by route command in linux?

Reply
Thread Tools Display Modes

How to set default gw not by route command in linux?

 
 
ChaoZhang
Guest
Posts: n/a

 
      11-23-2006, 02:14 PM
My linux pc has two adapters, eth0 is 192.168.1.2 and eth1 is
172.16.2.100. I manually set these ip addresses in ifcfg-eth0 and
ifcfg-eth1 files. I also set 192.168.1.1 and 172.16.2.1 as gateways for
eth0 and eth1. After this, I found the default gw is 172.16.2.1 not
192.168.1.1. I know I can change it through route command. But I think
there must be another way for system to set the default gw is
192.168.1.1. Could you please tell me how to configure it? many thanks!

 
Reply With Quote
 
 
 
 
Bit Twister
Guest
Posts: n/a

 
      11-23-2006, 02:27 PM
On 23 Nov 2006 07:14:48 -0800, ChaoZhang wrote:

With 300+ linux distributions, you may want to read
http://www.catb.org/~esr/faqs/smart-questions.html
because different distributions have different config files.

Some distributions use different files on different releases.

It can be instructive to read the network start/stop scripts to see
what files can be used to do what.
 
Reply With Quote
 
ChaoZhang
Guest
Posts: n/a

 
      11-23-2006, 02:32 PM

"Bit Twister дµÀ£º
"
> On 23 Nov 2006 07:14:48 -0800, ChaoZhang wrote:
>
> With 300+ linux distributions, you may want to read
> http://www.catb.org/~esr/faqs/smart-questions.html
> because different distributions have different config files.
>
> Some distributions use different files on different releases.
>
> It can be instructive to read the network start/stop scripts to see
> what files can be used to do what.


Ok, I'm using Fedora core 5 linux.

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-23-2006, 02:53 PM
On 23 Nov 2006 07:32:39 -0800, ChaoZhang wrote:

> Ok, I'm using Fedora core 5 linux.


then you will want to know about the sysconfig.txt file.

do a
locate sysconfig.txt

look in sysconfig.txt for /etc/sysconfig/network-scripts/route-<interface-name>


You will also want to remove the GATEWAY=value line from the
/etc/sysconfig/network-scripts/ifcfg-ethX config file which is setting
an incorrect default gateway value.


 
Reply With Quote
 
Balwinder S \bsd\ Dheeman
Guest
Posts: n/a

 
      11-23-2006, 03:13 PM
On 11/23/2006 08:44 PM, ChaoZhang wrote:
> My linux pc has two adapters, eth0 is 192.168.1.2 and eth1 is
> 172.16.2.100. I manually set these ip addresses in ifcfg-eth0 and
> ifcfg-eth1 files. I also set 192.168.1.1 and 172.16.2.1 as gateways for
> eth0 and eth1. After this, I found the default gw is 172.16.2.1 not
> 192.168.1.1. I know I can change it through route command. But I think
> there must be another way for system to set the default gw is
> 192.168.1.1. Could you please tell me how to configure it? many thanks!


Try to comment out and, or omit the GW and, or GATEWAY entry from your
ifcfg-eth1 file and send restart command to your network init script;
you need not reboot Linux for these kinds of changes.

Things would have been different, if you have been using DHCP to
configure your interfaces on a dual homed machine; the above is
applicable only for manually configured interfaces.

Hope that helps!
--
Dr Balwinder S "bsd" Dheeman Registered Linux User: #229709
Anu's Linux@HOME Machines: #168573, 170593, 259192
Chandigarh, UT, 160062, India Distros: Ubuntu, Fedora, Knoppix
Home: http://cto.homelinux.net/~bsd/ Visit: http://counter.li.org/
 
Reply With Quote
 
Unruh
Guest
Posts: n/a

 
      11-23-2006, 03:27 PM
"ChaoZhang" <(E-Mail Removed)> writes:

>My linux pc has two adapters, eth0 is 192.168.1.2 and eth1 is
>172.16.2.100. I manually set these ip addresses in ifcfg-eth0 and
>ifcfg-eth1 files. I also set 192.168.1.1 and 172.16.2.1 as gateways for
>eth0 and eth1. After this, I found the default gw is 172.16.2.1 not


Why do you set gateways for both? Gateways are for default routes. You can
only have one default route. The last one set.

>192.168.1.1. I know I can change it through route command. But I think
>there must be another way for system to set the default gw is
>192.168.1.1. Could you please tell me how to configure it? many thanks!


Get rid of the GATEWAY option for the address you do not want.

 
Reply With Quote
 
Floyd L. Davidson
Guest
Posts: n/a

 
      11-23-2006, 07:09 PM
Unruh <unruh-(E-Mail Removed)> wrote:
>"ChaoZhang" <(E-Mail Removed)> writes:
>
>>My linux pc has two adapters, eth0 is 192.168.1.2 and eth1 is
>>172.16.2.100. I manually set these ip addresses in ifcfg-eth0 and
>>ifcfg-eth1 files. I also set 192.168.1.1 and 172.16.2.1 as gateways for
>>eth0 and eth1. After this, I found the default gw is 172.16.2.1 not

>
>Why do you set gateways for both? Gateways are for default routes. You can
>only have one default route. The last one set.


A gateway is for *any* address that is not on a physically connected
network. There might well be multiple physical networks accessable
via gateways through a single interface. Each of those non-directly
connected physical networks will necessarily have a gateway to forward
from one physical network to the other.

It has *nothing* to do with a default, other than that a default route
has to have a gateway specified.

>>192.168.1.1. I know I can change it through route command. But I think
>>there must be another way for system to set the default gw is
>>192.168.1.1. Could you please tell me how to configure it? many thanks!

>
>Get rid of the GATEWAY option for the address you do not want.


What if he needs that gateway to access a non-directly connected
physical network?

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) (E-Mail Removed)
 
Reply With Quote
 
steve_schefter@hotmail.com
Guest
Posts: n/a

 
      11-24-2006, 03:08 PM
Floyd L. Davidson wrote:
> Unruh <unruh-(E-Mail Removed)> wrote:
> >Why do you set gateways for both? Gateways are for default routes. You can
> >only have one default route. The last one set.

>
> A gateway is for *any* address that is not on a physically connected
> network. There might well be multiple physical networks accessable
> via gateways through a single interface. Each of those non-directly
> connected physical networks will necessarily have a gateway to forward
> from one physical network to the other.


Yes, you might need to get to other networks via a gateway, but
you still can't have multiple gateways. Even if you have multiple
interfaces.

Suppose I had two interfaces, 1.x.x.x and 2.x.x.x and I want to
get to 3.x.x.x, and I have two "gateways", how would IP know
which gateway to forward the datagram to?

> It has *nothing* to do with a default, other than that a default route
> has to have a gateway specified.


If you take a look at network-scripts/network-functions (which
is what reads the ifcfg-ethN files), it uses the address specified
with GATEWAY to do a default route.

As Unruh said, you can have only one default and the last
one will be it.

The only benefit to having multiple GATEWAYs is in case one
interface is down (the script checks this).

Steve

 
Reply With Quote
 
Moe Trin
Guest
Posts: n/a

 
      11-24-2006, 06:55 PM
On Thu, 23 Nov 2006, in the Usenet newsgroup comp.os.linux.networking, in
article <(E-Mail Removed)>, Floyd L. Davidson wrote:

>Unruh <unruh-(E-Mail Removed)> wrote:


>> Why do you set gateways for both? Gateways are for default routes. You can
>> only have one default route. The last one set.


>It has *nothing* to do with a default, other than that a default route
>has to have a gateway specified.


Beg your pardon Floyd, but _EVERY_ Linux distribution uses the keyword
"gateway" to _mean_ the gateway to the default route. I will certainly
agree that this is an incorrect interpretation, but that can't change
many years of mis-use.

>What if he needs that gateway to access a non-directly connected
>physical network?


Then his network is not the typical home setup, which is what most of
the "helper" programs assume. If someone actually does have multiple
networks on a home system (more common now with wireless) then these
simple minded "helper" tools may get it wrong. That's been a problem
since a number of early Linux distributions at least as far back as
the mid-90s. Certainly Red Hat 1.1 (Mothers-Day) from the summer of
1995 had this problem, as did Slackware 3.2 (go check the CHANGELOG
file). Then if you check windoze, microsoft has gotten it wrong since
they invented the Internet (or whatever) in 1995.

Old guy
 
Reply With Quote
 
Moe Trin
Guest
Posts: n/a

 
      11-24-2006, 06:56 PM
On 24 Nov 2006, in the Usenet newsgroup comp.os.linux.networking, in article
<(E-Mail Removed) .com>,
(E-Mail Removed) wrote:

>Yes, you might need to get to other networks via a gateway, but
>you still can't have multiple gateways. Even if you have multiple
>interfaces.


[conover ~]$ /sbin/route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 89948 eth0
192.168.2.0 192.168.1.6 255.255.255.0 UG 0 0 32165 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 388 lo
0.0.0.0 192.168.1.248 0.0.0.0 UG 0 0 2673 eth0
[conover ~]$

And why not?

>Suppose I had two interfaces, 1.x.x.x and 2.x.x.x and I want to
>get to 3.x.x.x, and I have two "gateways", how would IP know
>which gateway to forward the datagram to?


Nomenclature problems - but that would depend on what your routing code is
doing. For an ordinary workstation, you can only have one _usable_ gateway
to a given address. In Linux, if you have two (or more) gateways leading to
the same address, then the last one defined (OR the one with the lowest
metric) wins. But a router with multiple routes to a destination _CAN_ use
any of them - perhaps depending on [perceived] traffic levels.

>The only benefit to having multiple GATEWAYs is in case one
>interface is down (the script checks this).


You mean routing daemons like gated or routed?

Old guy
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Add a route command joe Windows Networking 2 11-14-2006 10:35 PM
Route-Command =?ISO-8859-15?Q?Heinrich_L=F6prich?= Linux Networking 3 08-29-2005 11:28 AM
Using the ROUTE command Peter Windows Networking 2 06-13-2004 11:57 PM
Using the ROUTE command Peter Windows Networking 2 06-13-2004 11:57 PM
ROUTE command =?iso-8859-1?Q?Utopic=AE?= Windows Networking 1 02-25-2004 02:09 PM



1 2 3 4 5 6 7 8 9 10 11