About Linux FAQ

Browse More FAQs:

Linux Set Up Routing with ip Command

Posted by Vivek on Thursday January 17, 08 @12:25 pm

Q. Can you explain ip command to setup routing? How do I use the ip command to configure the routing table of the Linux kernel?

A.. ip command can be used for the following tasks :
=> Show / manipulate routing

=> Show / manipulate devices

=> Policy routing

=> Tunnels

Task: View / Display Routing Table

Type the following command:
$ ip route show
Output:

10.0.31.18 dev ppp0  proto kernel  scope link  src 10.1.3.103
192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.1
192.168.1.0/24 dev ra0  proto kernel  scope link  src 192.168.1.106
169.254.0.0/16 dev eth0  scope link  metric 1000
10.0.0.0/8 dev ppp0  scope link
default via 192.168.1.1 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:

192.168.1.0/24 dev ra0  proto kernel  scope link  src 192.168.1.106

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 192.168.1.1 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 192.168.1.0 directly through the device eth0:, enter:
# ip route add 192.168.1.0/24 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 192.168.1.254

Task: Delete route from table

Type the following command
# ip route delete 192.168.1.0/24 dev eth0

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 or Red Hat Linux systems

Recommended readings:

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , , ~ Last updated on: January 17, 2008

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.