home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LINUX / HOWTO / mini / ipalias.txt < prev    next >
Text File  |  1997-07-07  |  9KB  |  233 lines

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