change default gateway, check static routes

I'm running a few versions (from the last few years) of CentOS.  I want to check and adjust if necessary my default gateways.  I have root access via ssh from the same subnet, so i won't lose connection if i bungle the default gateway.  I know enough to check ifconfig, but that tells me everything except the default gateway.

How would I check for static routes?  I'm familiar with windows route print command.  I may need to delete a route.

Assume I'm very clumsy with linux.
Who is Participating?
pcrequestAuthor Commented:
it was there in the gui, so i edited in the gui.  rebooted to test persistence.  done.
netstat -r
netstat -rn
for numeric output.

pcrequestAuthor Commented:
ROUTE tells me exactly what I need.

How do I change default gateway?  How do I delete a static route?
Ultimate Tool Kit for Technology Solution Provider

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 now.

pcrequestAuthor Commented:

OK, I went to /etc/sysconfig/ and did a

emacs network was helpful saving my default route change.

route shows the old gateway.  Do I need to reboot?  Other way to restart eth0 without losing my SSH connection ability?

Then how do I delete a static route?  I don't see a line to make it persistent in /etc/rc.d/rc.local.

So just use this example?

route del -host netmask gw eth0
pcrequestAuthor Commented:
/etc/init.d/network restart

worked nicely
route -n
route del default
route add default gw
pcrequestAuthor Commented:
Actually there is one machine that is being stubborn and I can't get it to take a new gateway.  tty2, your commands work, and give a new gateway.  However, if I /etc/init.d/network restart then it reverts to the old gateway :(  

I want the gateway to be  It keeps reverting to

[x@z ~]# cat /etc/sysconfig/network

[x@ ~]# cat /proc/version
Linux version 2.6.18-194.17.1.el5 ( (gcc version
4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Wed Sep 29 12:51:33 EDT 2010

[x@z ~]# cat /etc/rc.d/rc.local
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

Open in new window

pcrequestAuthor Commented:
Admin, I tried closing this too soon.  Can you reset to to open please, and cancel the point distribution?
However, if I /etc/init.d/network restart then it reverts to the old gateway

How do you define your IP address?
Something overwrites you settings.
1. If you receive IP address from DHCP server, look at configs on this server.
2. If you define IP address manually, try to find in which script  default gateway is overwritten. Say,

grep -R /etc/*
pcrequestAuthor Commented:

Unsure how df was originally defined, but it could have been in a gui. certainly not DHCP.  my grep was still running 24 later so i canceled it.  I'm going to try some of these tomorrow:
GUI is evil. Better use "Method #3: Edit configuration files stored in /etc/sysconfig/network-scripts/" on the link you mentioned.
/etc/init.d/network is a bash script, and you can check step by step what is playing when you run it.
pcrequestAuthor Commented:
i fixed the problem by editing default gateway in the gui.  i had to plug kvm in.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.