Lofland bLOG

Change the Gateway (Default Router) on SUN

Filed under Unix Notes on Thursday, May 11th, 2006 @ 3:22pm by Christen

The default route is carried in a file called /etc/defaultrouter which is read at boot time. In order to avoid having to reboot, you can also add a default route manually and delete the old one.

Here are the steps I took to change the default route on a host recently:

#first do a traceroute for later comparison

traceroute knownhost.anothersub.net

#This command will show you the current default route
netstat -rn

#just for the record, take a look at what the route is now, if any
cat /etc/defaultrouter

#This sets the new default route for the next reboot
echo “10.0.0.1″ > /etc/defaultrouter

#Again, just checking to be sure it worked!
cat /etc/defaultrouter

#Now we add the new default route to the current routing table
#If you are going to reboot, you do not need to do this step
route add default 10.0.0.1

#and we take out the old one
#If you are going to reboot, you do not need to do this step
route delete default 192.168.0.1

#Now we check that the new route is in and the old one is gone
netstat -rn

#and we do one last traceroute and compare it to the first one to see that our work had some affect
traceroute knownhost.anothersub.net

I usually log all of this, just for the record.

NOTE that you can do this while connected remotely via SSH. It will not drop your connection, although it doesn’t hurt to have a console connection open and logged in case you change it to a non-working gateway and need to quickly putit back!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress