home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / MINI / IP_ALIAS < prev    next >
Encoding:
Text File  |  1996-08-18  |  4.7 KB  |  135 lines

  1.  
  2.           Mini How-to on Setting Up IP Aliasing On A Linux Machine
  3.  
  4. My setup:
  5.  
  6.    * Latest kernel (2.0.12 - from ftp.funet.fi:/pub/Linux/kernel/src/v2.0).
  7.    * IP Alias compiled as a loadable module .
  8.    * I have to support 2 additional IPs over and above the IP already
  9.      allocated to me.
  10.    * A D-Link DE620 pocket adapter (not important, works with any Linux
  11.      supported network adapter).
  12.  
  13. Commands:
  14.  
  15.    * First load the IP Alias module:
  16.  
  17.      /sbin/insmod /lib/modules/`uname -r`/ipv4/ip_alias.o
  18.  
  19.    * Second, setup the loopback, eth0 and all the IP #s beginning with the
  20.      main IP # for the eth0 interface:
  21.  
  22.      /sbin/ifconfig lo 127.0.0.0
  23.      /sbin/ifconfig eth0 up
  24.      /sbin/ifconfig eth0 172.16.3.1
  25.      /sbin/ifconfig eth0:0 172.16.3.10
  26.      /sbin/ifconfig eth0:1 172.16.3.100
  27.  
  28.      172.16.3.1 is the main IP #, while .10 and .100 are the aliases. The
  29.      magic is the eth0:x where x=0,1,2,...n for the different IP #s. The
  30.      main IP # does not need to be aliased.
  31.  
  32.    * Third, setup the routes. First route the loopback, then the net and,
  33.      finally, the various IP #s starting with the default (originally
  34.      allocated) one:
  35.  
  36.      /sbin/route add -net 127.0.0.0
  37.      /sbin/route add -net 172.16.3.0 dev eth0
  38.      /sbin/route add -host 172.16.3.1 dev eth0
  39.      /sbin/route add -host 172.16.3.10 dev eth0:0
  40.      /sbin/route add -host 172.16.3.100 dev eth0:1
  41.      /sbin/route add default gw 172.16.3.200
  42.  
  43. That's it.
  44.  
  45. In the example IP # above, I am using the Private IP #s (RFC 1918) for
  46. illustrative purposes. Substitute them with your own official or private IP
  47. #s.
  48.  
  49. The example shows only 3 IP #s. The max is defined to be 256 in
  50. /usr/include/linux/net_alias.h. 256 IP #s on ONE card is a lot :-)!
  51.  
  52. Here's what my /sbin/ifconfig looks like:
  53.  
  54. lo        Link encap:Local Loopback
  55.           inet addr:127.0.0.0  Bcast:127.255.255.255  Mask:255.0.0.0
  56.           UP BROADCAST LOOPBACK RUNNING  MTU:3584  Metric:1
  57.           RX packets:5088 errors:0 dropped:0 overruns:0
  58.           TX packets:5088 errors:0 dropped:0 overruns:0
  59.  
  60. eth0      Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  61.           inet addr:172.16.3.1  Bcast:172.16.3.255  Mask:255.255.255.0
  62.           UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
  63.           RX packets:334036 errors:0 dropped:0 overruns:0
  64.           TX packets:11605 errors:0 dropped:0 overruns:0
  65.           Interrupt:7 Base address:0x378
  66.  
  67. eth0:0    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  68.           inet addr:172.16.3.10  Bcast:172.16.3.255  Mask:255.255.255.0
  69.           UP BROADCAST RUNNING  MTU:1500  Metric:1
  70.           RX packets:0 errors:0 dropped:0 overruns:0
  71.           TX packets:0 errors:0 dropped:0 overruns:0
  72.  
  73. eth0:1    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20
  74.           inet addr:172.16.3.100  Bcast:172.16.3.255  Mask:255.255.255.0
  75.           UP BROADCAST RUNNING  MTU:1500  Metric:1
  76.           RX packets:1 errors:0 dropped:0 overruns:0
  77.           TX packets:0 errors:0 dropped:0 overruns:0
  78.  
  79. And /proc/net/aliases:
  80.  
  81. device           family address
  82. eth0:0           2      172.16.3.10
  83. eth0:1           2      172.16.3.100
  84.  
  85. And /proc/net/alias_types:
  86.  
  87. type    name            n_attach
  88. 2       ip              2
  89.  
  90. Of course, the stuff in /proc/net were created by the ifconfig command and
  91. not by hand!
  92.  
  93. Question: How can I keep the IP alias settings through a reboot?
  94.  
  95. Answer: Whether you are using BSD-style or SysV-style (Redhat for example)
  96. init, you can always include it in /etc/rc.d/rc.local. Here's what I have on
  97. my SysV init system (Redhat 3.0.3):
  98.  
  99.    * My /etc/rc.d/rc.local: (edited to show the relevant portions)
  100.  
  101.      #setting up IP alias interfaces
  102.      echo "Setting 172.16.3.1, 172.16.3.10, 172.16.3.100 IP Aliases ..."
  103.      /sbin/ifconfig lo 127.0.0.1
  104.      /sbin/ifconfig eth0 up
  105.      /sbin/ifconfig eth0 172.16.3.1
  106.      /sbin/ifconfig eth0:0 172.16.3.10
  107.      /sbin/ifconfig eth0:1 172.16.3.100
  108.      #setting up the routes
  109.      echo "Setting IP routes ..."
  110.      /sbin/route add -net 127.0.0.0
  111.      /sbin/route add -net 172.16.3.0 dev eth0
  112.      /sbin/route add -host 172.16.3.1 eth0
  113.      /sbin/route add -host 172.16.3.10 eth0:0
  114.      /sbin/route add -host 172.16.3.100 eth0:1
  115.      /sbin/route add default gw 172.16.3.200
  116.      #
  117.  
  118.    * Hope the preceding is useful to someone.
  119.  
  120. Thanks to all those who have done this great work on Linux and IP Aliasing.
  121. And especially to Juan Jose Ciarlante for clarifying my questions.
  122.  
  123. Kudos to the ace programmers!
  124.  
  125. If you do find this document useful or have suggestions on improvements, do
  126. send me an e-mail at h.pillay@ieee.org.
  127.  
  128. Enjoy.
  129.  
  130. ----------------------------------------------------------------------------
  131. Questions?
  132.  
  133. Go back to Harish's Home Page at http://home.pacific.net.sg/~harish
  134. ----------------------------------------------------------------------------
  135.