≡ Menu

Linux Set Up Routing with ip Command

Can you explain the ip command to setup routing on Linux based systems? How do I use the ip command to configure the routing table of the Linux kernel?

The ip command can be used for the following tasks on Linux:

=> Show / manipulate routing

=> Show / manipulate devices

=> Policy routing

=> Tunnels

Task: View / Display Routing Table

Type the following command:
$ ip route show
$ ip route list
Sample Outputs: dev ppp0  proto kernel  scope link  src dev eth0  proto kernel  scope link  src dev ra0  proto kernel  scope link  src dev eth0  scope link  metric 1000 dev ppp0  scope link 
default via dev ra0  metric 100

Each entry is nothing but an entry in the routing table (Linux kernel routing table). For example. following line represents the route for the local network. All network packets to a system in the same network are sent directly through the device ra0: dev ra0  proto kernel  scope link  src

Our default route is set via ra0 interface i.e. all network packets that cannot be sent according to the previous entries of the routing table are sent through the gateway defined in this entry i.e is our default gateway.

Task: Set a Route to the Locally Connected Network eth0

Type the following command to sent all packets to the local network directly through the device eth0:, enter:
# ip route add dev eth0

Task: Set a default route

All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway
# ip route add default via

Task: Delete route from table

Type the following command
# ip route delete dev eth0

How do I verify routing configurations?

Use the ping/host commands to make sure you can reach to your gateway:
ping Your-Gateway-Ip-Here
ping Your-DNS-Server-IP-Here
ping www.cyberciti.biz
host www.cyberciti.biz

How do I save routing information to a configuration file?

All routing settings made with the ip tool (route command) are lost when you reboot Linux server. See our previous article about configuring static routes in Debian/Ubuntu or Red Hat Linux systems.

Recommended readings:
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 4 comments… add one }
  • manas February 21, 2011, 7:46 am

    i m having a linux pc and having 7 window based pc….
    i want a complete routing through linux pc…..
    so can anyone help me out

  • Jose Tapia June 21, 2012, 8:11 am

    Very useful info, direct to the mean :D thanks

  • higkoo January 23, 2013, 7:33 am

    How to save the ‘ip route table’ in config file,so that it won’t lose after network restart ?

    For example:
    # ip route show table lvs
    default via dev eth1 proto kernel
    # service network restart
    Shutting down interface eth1: [ OK ]
    Shutting down loopback interface: [ OK ]
    Bringing up loopback interface: [ OK ]
    Bringing up interface eth1: [ OK ]
    # ip route show table lvs

    How to save it?

  • innocent mwina June 8, 2015, 11:00 am

    ihave liked the procedures,are soo good and great.thanks

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , ,