Difference between revisions of "Route"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
The [[command]] [[route]] lets you view and modify your computer's network routing table:
+
The [[command]] [[route]] lets you view and modify your computer's network routing table. You can use it when troubleshooting network problems or when you have more than one network card.
  
 +
= Overview =
 +
If you just call route, you get a list of routing rules, like this:
 +
# route
 +
Kernel IP routing table
 +
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
 +
<font color=blue>192.168.0.0    *              255.255.255.0  U    0      0        0 eth1</font>
 +
link-local      *              255.255.0.0    U    0      0        0 eth1
 +
loopback        *              255.0.0.0      U    0      0        0 lo
 +
<font color=blue>default        192.168.0.1    0.0.0.0        UG    0      0        0 eth1</font>
 +
The first blue line means: If there is any IP package for an IP address 192.168.0.*, just send it over network device ''eth1''. The second blue line means: Every IP package that has not been handled yet, send over network device ''eth1'' to the default gateway 192.168.0.1.
 +
 +
= Adding a rule =
 +
 +
== Gateway ==
 +
For a pc with typical network access, to add a gateway issue
 +
route add default gw ''192.168.1.1''
 +
(where ''192.168.1.1'' is the address of your gateway)
 +
 +
== Adding a network ==
 +
To tell your Linux to send packages for the network 192.168.0.0[[subnet mask|/]]24 to the network device eth3:
 +
route add -net 192.168.0.0 netmask 255.255.255.0 eth3
 +
The same with a default gateway of 192.168.0.1:
 +
route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 eth3
 +
 +
= Removing a rule =
 
  # route -n
 
  # route -n
 
  Kernel IP routing table
 
  Kernel IP routing table
Line 19: Line 44:
  
 
= See also =
 
= See also =
* [http://man-wiki.net/index.php/8:route route man page]
+
* [http://linux.die.net/man/8/route route man page]

Latest revision as of 07:59, 6 December 2013

The command route lets you view and modify your computer's network routing table. You can use it when troubleshooting network problems or when you have more than one network card.

Overview

If you just call route, you get a list of routing rules, like this:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     0      0        0 eth1
link-local      *               255.255.0.0     U     0      0        0 eth1
loopback        *               255.0.0.0       U     0      0        0 lo
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth1

The first blue line means: If there is any IP package for an IP address 192.168.0.*, just send it over network device eth1. The second blue line means: Every IP package that has not been handled yet, send over network device eth1 to the default gateway 192.168.0.1.

Adding a rule

Gateway

For a pc with typical network access, to add a gateway issue

route add default gw 192.168.1.1

(where 192.168.1.1 is the address of your gateway)

Adding a network

To tell your Linux to send packages for the network 192.168.0.0/24 to the network device eth3:

route add -net 192.168.0.0 netmask 255.255.255.0 eth3

The same with a default gateway of 192.168.0.1:

route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 eth3

Removing a rule

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth1
# route delete -net 192.168.0.0 netmask 255.255.255.0 eth0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth1

See also