centos different subnets problem

Hello i have 2 centos machines but i have a problem with this both machine

my machines has different subnets with their gateway i mean machines ip addresses

and my gateway is :


so i have added this lines to route-eth0 :


so i do not need to write
route add -net netmask dev eth0
but i still need to write :
route add default gw
manually how could i do this automagically
only there is a triick if i write it to network scripts it is loading before route-eth0 so it returns me unknown host or unreachable machine

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just add to your route-eth0:
CahitEyAuthor Commented:
nope i have tryed not workd my netstat -rn must look like this (as seen on code file )

and i have not seen only the last line automagicaly

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface UH        0 0          0 eth0
188.72.xxx.0   U         0 0          0 eth0         UG        0 0          0 eth0

Open in new window

Have you restarted the eth0 ethernet since you changed the file?
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

CahitEyAuthor Commented:
yes exactly :) if i add the line as :

then my netstat table seems like UH        0 0  

and my service network restart is returning unknown gateway :) unfortunately i have to route gateway at the end of all operations
What version of CentOS is it?
CahitEyAuthor Commented:
5.4 latest version also i have tryed for 4.8 and ubuntu that is only working correctly and automagically on fedora 12 all the other linux versions needs to make it manually
On RedHat Enterprise Linux 5.3 (which is meant to be the same base code as CentOS 5.3) my default route is set in /etc/sysconfig/network, which contains the following 4 lines:


so it might be worth seeing if setting the gateway in that file does the trick for you.
CahitEyAuthor Commented:
i have tryed this also
it is ignoring this on all linux dists exept  fedora 12 so fedora is working like a charm just when i set it on network adapter settings
Hmmm - one of those should work - you could put a script in /etc/rc3.d so it sets the route at startup (a bit of a kludge but effective) but that doesn't explain why the other files aren't affecting things.
Do you know about how the /etc/rc?.d directories work?
CahitEyAuthor Commented:
nope :(
Okay, whan you boot into runlevel 3 the scripts in /etc/rc3.d are run.
Scripts starting with an "S" are run at startup and any starting with "K" are run at shutdown.
They are run in order, so a script starting with S01 will runn before a script starting with S99
Most of the scripts are links to scripts in /etc/init.d

If you wanted to start a script right after S10 network was run, what you would create a script in /etc/init.d called something like "myscript",
make it executable with the command:
"chmod 775 /etc/init.d/myscript"
and then make a link to the /etc.rc3.d directory with the command:
"ln -s /etc/init.d/myscript /etc/rc3.d/S11myscript"

By calling it S11myscript you are forcing it to run after S10network.  You could probably get away with calling it S99myscript.

The script will be run automatically at startup with the command:
/etc/rc3.d/S11myscript start

If you boot to runlevel 2 rather than runlevel 3 you would need to make the same link to /etc/rc2.d rather than /etc/rc3.d - a lot of licensing programs create links to /etc/rc2.d, /etc/rc3.d, /etc/rc4.d and /etc/rc5.d to be sure that it will start whatever the runlevel.

Your "myscript" should look something like this:

#!/bin/sh -f
# Start default route
case "$1" in
        echo "Restarting default route..."
        route add default gw
        echo "Starting default route..."
        route add default gw
    echo "usage: $0 {start|stop|restart}"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
By the way, S10myscript would run before S10network because it comes first alphabetically - that's why I chose S11myscript.  

You may need to add the path to the route command into the script as I'm not 100% sure what the PATH will be set to at that point!
You need to add a default gateway for each segment.
using the metric you can adjust the weight through.

Why/how does your eth0 interface have two separate segments that are completely different from the default gateway segment? is no where near the 188..x.x.x/24 network.

The description in your question is missing some detail.
you can use the route add directive as martin_J_par posted.  The problem is that the traffic might not find itself back or the 188.x.x.x Ip will not be the source of the packets sent from your system.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.