Solved

change default gateway, check static routes

Posted on 2010-11-20
12
1,092 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

816 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