home *** CD-ROM | disk | FTP | other *** search
/ Plex 2 / Plex2.mdf / u_linux / route.use < prev    next >
Internet Message Format  |  1994-06-02  |  7KB

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