home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / IP-Alias < prev    next >
Text File  |  1998-10-14  |  8KB  |  246 lines

  1.  
  2.    
  3.      _________________________________________________________________
  4.    
  5.       This page was last updated January 13th 1997.
  6.       
  7.            MINI HOW-TO ON SETTING UP IP ALIASING ON A LINUX MACHINE
  8.                                        
  9.   _GNU Copyleft 1996/1997 Harish Pillay (h.pillay@ieee.org)_
  10.   
  11.     Primary site: http://home.pacific.net.sg/~harish/linuxipalias.html
  12.     
  13.    Synopsis:
  14.    
  15.    This is a cook book recipe on how to set up and run IP aliasing on a
  16.    Linux box. In addition, there are instructions on how to also set up
  17.    the machine to receive e-mail on the aliased IP #s.
  18.    
  19.    My setup:
  20.      * Latest kernel (2.0.27 - from
  21.        ftp.funet.fi:/pub/Linux/kernel/src/v2.0) - has worked since
  22.        1.3.7x.
  23.      * IP Alias compiled as a loadable module. You would have indicated
  24.        in the "make config" command to make your kernel, that you want
  25.        the IP Masq to be compiled as a (M)odule. Check the Modules HOW-TO
  26.        (if that exists) or check the info in
  27.        /usr/src/linux/Documentation/modules.txt.
  28.      * I have to support 2 additional IPs over and above the IP already
  29.        allocated to me.
  30.      * A D-Link DE620 pocket adapter (not important, works with any Linux
  31.        supported network adapter).
  32.        
  33.    Commands:
  34.      * First load the IP Alias module (you can skip this step if you
  35.        compiled the module into the kernel):
  36.  
  37. /sbin/insmod /lib/modules/`uname -r`/ipv4/ip_alias.o
  38.      * Second, setup the loopback, eth0 and all the IP #s beginning with
  39.        the main IP # for the eth0 interface:
  40.        
  41.  
  42. /sbin/ifconfig lo 127.0.0.1
  43. /sbin/ifconfig eth0 up
  44. /sbin/ifconfig eth0 172.16.3.1
  45. /sbin/ifconfig eth0:0 172.16.3.10
  46. /sbin/ifconfig eth0:1 172.16.3.100
  47.    172.16.3.1 is the main IP #, while .10 and .100 are the aliases. The
  48.        magic is the eth0:x where x=0,1,2,...n for the different IP #s.
  49.        The main IP # does not need to be aliased.
  50.        
  51.      * Third, setup the routes. First route the loopback, then the net
  52.        and, finally, the various IP #s starting with the default
  53.        (originally allocated) one:
  54.        
  55.  
  56. /sbin/route add -net 127.0.0.0
  57. /sbin/route add -net 172.16.3.0 dev eth0
  58. /sbin/route add -host 172.16.3.1 dev eth0
  59. /sbin/route add -host 172.16.3.10 dev eth0:0
  60. /sbin/route add -host 172.16.3.100 dev eth0:1
  61. /sbin/route add default gw 172.16.3.200
  62.  
  63.    That's it.
  64.    
  65.    In the example IP # above, I am using the Private IP #s (RFC 1918) for
  66.    illustrative purposes. Substitute them with your own official or
  67.    private IP #s.
  68.    
  69.    The example shows only 3 IP #s. The max is defined to be 256 in
  70.    /usr/include/linux/net_alias.h. 256 IP #s on ONE card is a lot :-)!
  71.    
  72.    Here's what my /sbin/ifconfig looks like:
  73.    
  74.  
  75.  
  76. lo        Link encap:Local Loopback
  77.           inet addr:127.0.0.1  Bcast:127.255.255.255  Mask:255.0.0.0
  78.           UP BROADCAST LOOPBACK RUNNING  MTU:3584  Metric:1
  79.           RX packets:5088 errors:0 dropped:0 overruns:0
  80.           TX packets:5088 errors:0 dropped:0 overruns:0
  81.  
  82. eth0      Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  83.           inet addr:172.16.3.1  Bcast:172.16.3.255  Mask:255.255.255.0
  84.           UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
  85.           RX packets:334036 errors:0 dropped:0 overruns:0
  86.           TX packets:11605 errors:0 dropped:0 overruns:0
  87.           Interrupt:7 Base address:0x378
  88.  
  89. eth0:0    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  90.           inet addr:172.16.3.10  Bcast:172.16.3.255  Mask:255.255.255.0
  91.           UP BROADCAST RUNNING  MTU:1500  Metric:1
  92.           RX packets:0 errors:0 dropped:0 overruns:0
  93.           TX packets:0 errors:0 dropped:0 overruns:0
  94.  
  95. eth0:1    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  96.           inet addr:172.16.3.100  Bcast:172.16.3.255  Mask:255.255.255.0
  97.           UP BROADCAST RUNNING  MTU:1500  Metric:1
  98.           RX packets:1 errors:0 dropped:0 overruns:0
  99.           TX packets:0 errors:0 dropped:0 overruns:0
  100.  
  101.    And /proc/net/aliases:
  102.  
  103. device           family address
  104. eth0:0           2      172.16.3.10
  105. eth0:1           2      172.16.3.100
  106.  
  107.    
  108.    
  109.    And /proc/net/alias_types:
  110.  
  111. type    name            n_attach
  112. 2       ip              2
  113.  
  114.    
  115.    
  116.    Of course, the stuff in /proc/net was created by the ifconfig command
  117.    and not by hand!
  118.    
  119.    _Question: How can I keep the settings through a reboot?_
  120.    
  121.    _Answer:_ Whether you are using BSD-style or SysV-style (Redhat for
  122.    example) init, you can always include it in /etc/rc.d/rc.local. Here's
  123.    what I have on my SysV init system (Redhat 3.0.3 and 4.0):
  124.    
  125.      * My /etc/rc.d/rc.local: (edited to show the relevant portions)
  126.        
  127.  
  128. #setting up IP alias interfaces
  129. echo "Setting 172.16.3.1, 172.16.3.10, 172.16.3.100 IP Aliases ..."
  130. /sbin/ifconfig lo 127.0.0.1
  131. /sbin/ifconfig eth0 up
  132. /sbin/ifconfig eth0 172.16.3.1
  133. /sbin/ifconfig eth0:0 172.16.3.10
  134. /sbin/ifconfig eth0:1 172.16.3.100
  135. #setting up the routes
  136. echo "Setting IP routes ..."
  137. /sbin/route add -net 127.0.0.0
  138. /sbin/route add -net 172.16.3.0 dev eth0
  139. /sbin/route add -host 172.16.3.1 eth0
  140. /sbin/route add -host 172.16.3.10 eth0:0
  141. /sbin/route add -host 172.16.3.100 eth0:1
  142. /sbin/route add default gw 172.16.3.200
  143. #
  144.  
  145.    _Question: How do I set up the IP aliased machine to receive e-mail on
  146.    the various aliased IP #s (on a machine using sendmail)?_
  147.    
  148.      * _Answer:_ Create (if not already existing) a file called for
  149.        example, /etc/mynames.cw. It does not have to be this exact name
  150.        nor in the /etc directory.
  151.        
  152.      * In that file, place the official domain names of the aliased IP
  153.        #s. If these aliased IP #s do not have a domain name, then you can
  154.        place the IP # itself.
  155.        
  156.  
  157. /etc/mynames.cw:
  158. ----------------
  159. # /etc/mynames.cw - include all aliases for your machine here; # is a comment.
  160. domain.one.net
  161. domain.two.com
  162. domain.three.org
  163. 4.5.6.7
  164.      * In your sendmail.cf file, where it defines a file class macro Fw,
  165.        add the following:
  166.  
  167. .
  168. .
  169. .
  170. ##################
  171. #   local info   #
  172. ##################
  173. .
  174. .
  175. # file containing names of hosts for which we receive email
  176. Fw/etc/mynames.cw
  177. .
  178. .
  179. .
  180.      * That should do it. Test out the new setting by invoking sendmail
  181.        in test mode for example:
  182.        
  183.  
  184. ganymede$ /usr/lib/sendmail -bt
  185. ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
  186. Enter
  187. > 0 me@4.5.6.7
  188. rewrite: ruleset  0   input: me @ 4 . 5 . 6 . 7
  189. rewrite: ruleset 98   input: me @ 4 . 5 . 6 . 7
  190. rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 7
  191. rewrite: ruleset 97   input: me @ 4 . 5 . 6 . 7
  192. rewrite: ruleset  3   input: me @ 4 . 5 . 6 . 7
  193. rewrite: ruleset 96   input: me
  194. rewrite: ruleset 96 returns: me
  195. rewrite: ruleset  3 returns: me
  196. rewrite: ruleset  0   input: me
  197. rewrite: ruleset 98   input: me
  198. rewrite: ruleset 98 returns: me
  199. rewrite: ruleset  0 returns: $# local $: me
  200. rewrite: ruleset 97 returns: $# local $: me
  201. rewrite: ruleset  0 returns: $# local $: me
  202. > 0 me@4.5.6.8
  203. rewrite: ruleset  0   input: me @ 4 . 5 . 6 . 8
  204. rewrite: ruleset 98   input: me @ 4 . 5 . 6 . 8
  205. rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 8
  206. rewrite: ruleset 97   input: me @ 4 . 5 . 6 . 8
  207. rewrite: ruleset  3   input: me @ 4 . 5 . 6 . 8
  208. rewrite: ruleset 96   input: me
  209. rewrite: ruleset 96 returns: me
  210. rewrite: ruleset  3 returns: me
  211. rewrite: ruleset  0   input: me
  212. rewrite: ruleset 98   input: me
  213. rewrite: ruleset 98 returns: me
  214. rewrite: ruleset 95   input:  me
  215. rewrite: ruleset 95 returns: me
  216. rewrite: ruleset  0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me
  217. rewrite: ruleset 97 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me
  218. rewrite: ruleset  0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me
  219. >
  220.    Notice when I tested me@4.5.6.7, it delivered the mail to the local
  221.        machine, while me@4.5.6.8 was to be handed off to the smtp mailer.
  222.        That is the correct response.
  223.        
  224.      * You are all set now.
  225.        
  226.    Hope the preceding is useful to someone.
  227.    
  228.    Thanks to all those who have done this great work on Linux and IP
  229.    Aliasing. And especially to Juan Jose Ciarlante for clarifying my
  230.    questions.
  231.    
  232.    Kudos to the ace programmers!
  233.    
  234.    If you do find this document useful or have suggestions on
  235.    improvements, do send me an e-mail at h.pillay@ieee.org.
  236.    
  237.    Enjoy.
  238.    
  239.    
  240.      _________________________________________________________________
  241.    
  242.    Questions?
  243.    
  244.    Go back to Harish's Home Page
  245.      _________________________________________________________________
  246.