home *** CD-ROM | disk | FTP | other *** search
/ Plex 2 / Plex2.mdf / u_linux / route.use / text0000.txt < prev   
Encoding:
Text File  |  1994-06-02  |  6.5 KB  |  178 lines

  1. Let's see if I can come up with a general explanation of how to use
  2. "route" under Linux.  I'll give some "cookbook" examples at the end.
  3. For better or worse, this is going to be slightly different than for
  4. other variants of Unix.  That's because as of 0.99pl15, Linux does not
  5. create a route automatically when you enable an interface.  On the
  6. other hand, it does supply an additional option that I haven't seen
  7. elsewhere: the ability to specify an interface name instead of a
  8. gateway.
  9.  
  10. WARNING: this presentation assumes that you are using at least
  11. 0.99pl15, libc 4.5.19 (4.5.8 will *not* give the same results), and
  12. the current version of route.  (If there's any question, you can get a
  13. copy of route from athos.rutgers.edu in /pub/linux.)
  14.  
  15. I suggest a three-stage strategy for doing route:
  16.  
  17. 1) enable all your interfaces, using ifconfig, dip, or whatever.  Make
  18. sure that you specify the correct netmask for them, if your network is
  19. subnetted.
  20.  
  21. 2) set up the network route for each interface.  
  22.  
  23. 2a) For an Ethernet, this is the net or subnet to which it is
  24. attached, e.g.
  25.  
  26.    route add 128.6.0.0 dev eth0
  27.  
  28. or if we set the subnet mask to 255.255.255.0 in the ifconfig (as we
  29. really should)
  30.  
  31.    route add 128.6.157.0 dev eth0
  32.  
  33. 2b) For a point to point link, it is best to think about what traffic
  34. you want to send over the link.  If many cases it will be the default.
  35. In that case you'll do
  36.  
  37.    route add default dev sl0
  38.  
  39. In other cases, you may want to send all traffic for a specific network
  40. (e.g. the network to which the machine at the other end is attached).
  41. In that case use that network, e.g.
  42.  
  43.    route add 128.6.4.0 dev sl0
  44.  
  45. This assumes that net 128.6 is subnetted, with a netmask of 255.255.255.0.
  46. If you haven't mentioned any subnet masks, then you'd want just the main
  47. network number, i.e.
  48.  
  49.    route add 128.6.0.0 dev sl0
  50.  
  51. In the most general case, e.g. if you've got more than one interface,
  52. and want to use routed or gated to adjust routes dynamically, you may
  53. want a fixed route only for the specific host at the other end of the
  54. link.  E.g.
  55.  
  56.    route add 128.6.4.54 dev sl0
  57.  
  58. 3) Now create routes for any destinations not already mentioned.  If
  59. you are running routed or gated, that will handle things for you.
  60. Otherwise, most likely you just need a default route, if you haven't
  61. already defined one.
  62.  
  63. 3a) For Ethernet, a default route should point to a router on your
  64. Ethernet, e.g.
  65.  
  66.    route add default gw 128.6.157.1
  67.  
  68. 3b) For a point to point line, a default route can simply point to the
  69. line itself.  Since there's only one thing at the other end, there's
  70. no need to specify a gateway.  E.g.
  71.  
  72.    route add default dev sl0
  73.  
  74. 3c) If you have more than one interface, and want to route specific
  75. networks to specific interfaces, you can use several route statements
  76. like those in (3a) or (3b), each one mentioning a single network or
  77. host that you want to go a certain way.  Examples:
  78.  
  79. Ethernet:
  80.  
  81.    route add 128.6.5.0 128.6.157.2
  82.  
  83. point to point:
  84.  
  85.    route add 128.6.26.0 dev sl0
  86.  
  87. In the case of Ethernet, you have to send traffic to a specific router
  88. on the Ethernet.  In the case of a point to point line, you just send
  89. it to the line.  (The assumption is that the system at the other end
  90. of the line is a router. The line only goes one place.)
  91.  
  92. This will work correctly if you've defined the correct netmask for all
  93. of your interfaces using ifconfig, and if all subnets on your network
  94. have the same netmask.  This is normally true.  If not, you'll need to
  95. give more attention to the netmasks.
  96.  
  97. ABOUT SUBNET MASKS
  98.  
  99. When you do something like
  100.    
  101.    route add 128.6.0.0 dev sl0
  102.  
  103. this will send all traffic for network 128.6.0.0 out the slip line.
  104. But what is network 128.6.0.0?  Is it every address starting with
  105. 128.6, or just addresses starting with 128.6.0?  I.e. what "subnet
  106. mask" is used?  (Actually, it's considered bad form to use subnet 0,
  107. so there would not be a subnet called 128.6.0.)  The answer is that
  108. the Linux kernel will make some attempt to guess what you mean, but
  109. you may need to specify it.  If the interface you're referring to has
  110. a subnet mask defined by ifconfig, and the destination matches the
  111. interface's address, it will use that subnet mask.  Otherwise it will
  112. use the major network.  That needs some examples:
  113.  
  114. Let's suppose that eth0 has address 128.6.157.5 and netmask
  115. 255.255.255.0.  That would have been set up using
  116.  
  117.    ifconfig eth0 128.6.157.5 netmask 255.255.255.0
  118.  
  119. That netmask means that the network is subnetted, so that anything
  120. starting with 128.6.157 is considered to be on the subnet.  Now
  121. suppose you say
  122.  
  123.    route add 128.6.2.0 gw 128.6.157.2
  124.  
  125. This will send subnet 128.6.2 to gateway 128.6.157.2.  Since the
  126. destination has the same major address (128.6) as the gateway, Linux
  127. uses the netmask for that interface, i.e. 255.255.255.0.  This isn't a
  128. perfect heuristic.  It assumes that all subnets on your network have
  129. the same netmask.  But it's right for most places.  If it isn't for
  130. you, you can specify the subnet mask explicitly:
  131.  
  132.    route add 128.6.2.0 gw 128.6.157.2 netmask 255.255.255.128.
  133.  
  134. If you use a destination on a different major net, Linux has no
  135. way of knowing the subnet.  So it will assume that the whole 
  136. network is meant.  E.g.
  137.  
  138.    route add 18.0.0.0 gw 128.6.157.2
  139.  
  140. This says to send all of net 18 to gateway 128.6.157.2.  Since we
  141. don't know anything about the netmask for net 18, we simply assume the
  142. whole network is meant.  Again, you could specify an explicit subnet
  143. mask if necessary.
  144.  
  145. COOKBOOK EXAMPLES
  146.  
  147. I will give specific instructions for the two most common cases: a
  148. single Ethernet and a single SLIP line.  If you have more than one
  149. interface, you're probably going to need to understand what's going
  150. on.
  151.  
  152. For a single Ethernet, the simplest setup is
  153.  
  154.   ifconfig eth0 128.6.157.3 netmask 255.255.255.0
  155.   route add 128.6.157.0 dev eth0
  156.   route add default gw 128.6.157.1
  157.  
  158. Of course you use your own addresses and mask:
  159.  
  160.      128.6.157.3 is assumed to be the address of your system
  161.      255.255.255.0 is assumed to be the correct subnet mask for your network
  162.      128.6.157.0 is your local subnet (i.e. your address and'ed with your mask)
  163.      128.6.157.1 is asssumed to be the default router for your network
  164.  
  165. Most of this information would be obtained from your network
  166. administrator.
  167.  
  168. For a single SLIP connection, the simplest setup is
  169.  
  170.   use dip to enable the line.  This does the equivalent of ifconfig.
  171.   route add default dev sl0
  172.  
  173. You don't really need to worry about setting up the subnet for SLIP if
  174. that's your only interface.  In more complicated setups, you'll need
  175. to use ifconfig on sl0 to set the netmask.
  176.  
  177.  
  178.