Solved

change default gateway, check static routes

Posted on 2010-11-20
12
1,090 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 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

9 Experts available now in Live!

Get 1:1 Help Now