Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

change default gateway, check static routes

Posted on 2010-11-20
12
Medium Priority
?
1,101 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 400 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

916 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