Solved

change default gateway, check static routes

Posted on 2010-11-20
12
1,091 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:pcrequest
  • 8
  • 3
12 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 100 total points
ID: 34180006
netstat -r
or
netstat -rn
for numeric output.

wmp
0
 
LVL 1

Assisted Solution

by:pcrequest
pcrequest earned 0 total points
ID: 34180017
ROUTE tells me exactly what I need.

How do I change default gateway?  How do I delete a static route?
0
 
LVL 1

Assisted Solution

by:pcrequest
pcrequest earned 0 total points
ID: 34180320
helpful: http://www.labtestproject.com/linnet/routing.html

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

emacs network

http://www.codecoffee.com/tipsforlinux/articles/12.html 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 10.10.0.5 netmask 255.255.0.0 gw 10.2.0.1 eth0
0
 
LVL 1

Assisted Solution

by:pcrequest
pcrequest earned 0 total points
ID: 34180337
/etc/init.d/network restart

worked nicely
0
 
LVL 6

Assisted Solution

by:tty2
tty2 earned 400 total points
ID: 34180805
route
route -n
route del default
route add default gw 1.2.3.4
0
 
LVL 1

Author Comment

by:pcrequest
ID: 34184482
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 192.168.0.1.  It keeps reverting to 192.168.0.3.


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

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=zulu.tridecap.com

GATEWAY=192.168.0.1



[x@ ~]# cat /proc/version

Linux version 2.6.18-194.17.1.el5 (mockbuild@builder10.centos.org) (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

#!/bin/sh

#

# 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

0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 1

Author Comment

by:pcrequest
ID: 34184489
Admin, I tried closing this too soon.  Can you reset to to open please, and cancel the point distribution?
0
 
LVL 6

Assisted Solution

by:tty2
tty2 earned 400 total points
ID: 34187384
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 192.168.0.3 /etc/*
0
 
LVL 1

Assisted Solution

by:pcrequest
pcrequest earned 0 total points
ID: 34198389
tty2

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:  http://www.cyberciti.biz/faq/rhel-centos-fedoracore-linux-network-card-configuration/
0
 
LVL 6

Expert Comment

by:tty2
ID: 34203167
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.
0
 
LVL 1

Accepted Solution

by:
pcrequest earned 0 total points
ID: 34209852
it was there in the gui, so i edited in the gui.  rebooted to test persistence.  done.
0
 
LVL 1

Author Closing Comment

by:pcrequest
ID: 34228835
i fixed the problem by editing default gateway in the gui.  i had to plug kvm in.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now