Solved

change default gateway, check static routes

Posted on 2010-11-20
12
1,095 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

710 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