Linux setup default gateway with route command

by on August 2, 2006 · 31 comments· LAST UPDATED August 16, 2007

in , ,

Q. How do I setup default gateway with a route command?

A. route command show and/or manipulate the IP routing table under Linux and UNIX oses.

Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program. When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.

Display default route

Following three-command display the current routing table:
# route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 ra0
default         dsl-router         UG    0      0        0 ra0

$ /sbin/route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   *        U     0      0        0 eth0     *          U     0      0        0 eth0
default         UG    0      0        0 eth0

You can use -n option, to display numerical addresses instead of trying to determine symbolic host names (via dns or /etc/hosts file). This is useful if you are trying to determine why the route to your nameserver has vanished.$ /sbin/route -nOutput:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 venet0     U     0      0        0 venet0         UG    0      0        0 venet0

Please note that a destionation entry (or default) is the default gatway. In above example is a default gatway.

Add / setup a new route

The syntax is as follows:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}


  • IP-ADDRESS: Specify router IP address
  • INTERFACE-NAME: Specify interface name such as eth0

For example if your router IP address is type the following command as the root user:
# route add default gw eth0OR use hostname such as dsl-router:# route add default gw dsl-router eth0

Setting route using GUI tools/command under Linux

If you find above command hard to use, consider using GUI tools. If your are using Red Hat/CentOS/Fedora core Linux type following command:# redhat-config-networkOR If you are using other Linux distribution use command:# network-admin

See also

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 31 comments… read them below or add one }

1 John Olivares March 6, 2008 at 8:30 pm

Great site thanks


2 Veeru November 16, 2011 at 7:37 am

Good one! Very usefull info


3 Ken April 15, 2008 at 11:57 pm

Running BT3 on an eeePC, I’ve been finding that I have to run:

# route add -net dev ath0

to get my wireless to connect to the internet.


4 m@m August 27, 2008 at 7:08 am

usefull commands..



5 Dan smooth operator October 1, 2008 at 12:42 pm

Short, distinct and very good!


6 Forum January 22, 2009 at 2:15 pm

It was really useful!!


7 velayutham February 3, 2009 at 4:25 pm

It was usefull at the urgent time


8 winifredO February 25, 2009 at 11:24 am

so inetresting and useful! thanks


9 robert April 13, 2009 at 5:32 am

Thanks for these hints.


10 NannY May 5, 2009 at 7:15 am

Thanks so much
Very Helpful!!


11 carlos guerrero May 14, 2009 at 12:34 am

hi very very thanks , for you posted i realy helpme very much!!!!


12 mc.god July 16, 2009 at 8:22 pm

Very useful hint as a fast reminder, thank you ^^


13 Al September 20, 2009 at 7:29 pm

great work fellows.good to go,Thank you for tips and tricks


14 admtsh December 30, 2009 at 3:35 am

Thank you!
very nice examples!


15 Quek April 1, 2010 at 5:03 am

Thank you very much, is a good and effective guide.


16 sundaram August 6, 2010 at 1:34 pm

when i used the command, i got the following error:

# route add default gw eth4
SIOCADDRT: No such process

could you please guide me?


17 Chris Happel September 13, 2010 at 2:48 pm

I was getting that, too. Turns out I was putting in the wrong interface. Use the ‘route’ command without any parameters, and confirm that the network is really attached to interface eth4. My problem now is that the server keeps ‘forgetting’ my default gateway, even though it’s in my /etc/network/interfaces file:

auto eth0
iface eth0 inet static

What gives?


18 niks December 28, 2010 at 5:29 am

useful commands…..thnks a ton


19 Alessandro April 21, 2011 at 3:27 pm

great tutorial … very usefull… thanks…


20 wri7913 June 28, 2011 at 1:11 am

Works on Natty 11.04 on ASUS G73sw laptop. Thanks for script! Ubuntu Devs should have already noticed and fixed this issue. Shame on them.


21 stevo November 4, 2011 at 8:36 am

Cool stuff guys…precise and straight


22 Jose Tapia November 13, 2011 at 4:05 am

Very good tutorial thank you! you rocks buddy :D


23 Christian November 14, 2011 at 11:15 am

Me a gustado mucho, gracias.


24 Sri April 17, 2012 at 7:59 am

Thanks a lot, very useful…

Saved be a lot of time and effort!!


25 Apu April 28, 2012 at 8:15 am

Hi All friends

Im going to Configure a Linux Gateway server for my LAN. It will locate in between router and my LAN.

I used 192.168.0.x private ip range for my LAN PCs. and im expecting to configure firewall, nat, proxy on that gateway server

who can guide me to do that.

Im new for linux and im interesting Linux



26 krishna August 21, 2012 at 10:31 am

hi ..
i helped me a lot


27 Mighty October 15, 2013 at 5:34 am

What is the difference between you example using this command:
# route add default gw eth0

And inserting the gateway in the file below?
# vi /etc/sysconfig/network


28 bA37 December 17, 2013 at 4:11 am

helped me a lot, thanks a lot dude…:)


29 Kapil Awadhwal April 24, 2014 at 11:50 am

Thanks for the short & good explaination…


30 AIL September 10, 2014 at 1:54 pm

Thank you for the info. Worked like a charm on RHEL 5.8 x64 server.
Question: are changes made with route command persistent? or do they revert on network restart or server restart?


31 Sudhi October 29, 2014 at 9:45 am

very useful commands thank you.


Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: