Setting up IP Aliasing on A Linux Machine Mini-HOWTO

Harish Pillay

 h.pillay@ieee.org 

Joy Yokley - Converted document from HTML to DocBook v4.1 (SGML)

JF Project - 擔杮岅栿

JF@linux.or.jp

2001-01-23

Revision History                                                       
Revision 1.2           2001-01-26          Revised by: JEY             
Revision 1.1           2001-01-24          Revised by: JEY             
Revision 1.0           1997-01-13          Revised by: HP              

偙偺暥彂偼丄Linux 儅僔儞忋偱偺 IP 僄僀儕傾僗偺愝掕曽朄偲棙梡曽朄傪娙扨
偵弎傋偨傕偺偱偡丅儅僔儞傪僙僢僩傾僢僾偟偰丄僄僀儕傾僗愝掕偟偨 IP 傾僪
儗僗忋偱儊乕儖傪庴怣偡傞曽朄偵偮偄偰傕愢柧偟偰偄傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

Table of Contents
1. 挊幰偺愝掕
2. 愝掕僐儅儞僪
3. 僩儔僽儖僔儏乕僥傿儞僌丗幙栤偲夝摎
   
    3.1. 幙栤丗儕僽乕僩偟偰傕愝掕偑堐帩偝傟傞傛偆偵偡傞偵偼丠
    3.2. 幙栤丗儅僔儞偵 IP 僄僀儕傾僗傪愝掕偟丄僄僀儕傾僗愝掕偟偨屄乆偺
        IP 傾僪儗僗忋偱儊乕儖傪庴怣偡傞偵偼偳偆偡傟偽偄偄偱偡偐
        (sendmail 傪巊偭偨儅僔儞偱偡)丠
   
4. 幱帿
5. 擔杮岅栿偵偮偄偰

1. 挊幰偺愝掕

 丒 IP 僄僀儕傾僗偼丄kernel 2.0.x 偍傛傃 2.2.x 偱偼昗弨偱桳岠偵側偭偰偄
    傑偡丅 2.4.x 偱偼僐儞僷僀儖帪偺僆僾僔儑儞傪巊偭偰桳岠偵偟偰偔偩偝偄
    ( kernel 2.4.x 偱偼 IP 僄僀儕傾僗偼廳梫帇偝傟偰偍傜偢丄傛傝僷儚僼儖
    側僼傽僀傾乕僂僅乕儖婡擻偵抲偒姺傢偭偰偄傑偡)丅
   
 丒 挊幰偼丄IP 僄僀儕傾僗婡擻傪儘乕僟僽儖儌僕儏乕儖偲偟偰僐儞僷僀儖偟傑
    偟偨丅撉幰偺側偐偵偼丄僇乕僱儖偺嵞峔抸偺嵺偺 "make config" 偺搑拞偱
    丄IP Masq 偺曽傪儌僕儏乕儖偲偟偰僐儞僷僀儖偡傞傛偆巜掕偟偰偟傑偭偰
    偄傞恖偑偄傞偐傕偟傟傑偣傫丅儌僕儏乕儖偵娭偡傞帠暱偼丄(傕偟墈棗壜擻
    側傜) Module HOWTO <http://www.linuxdoc.org/HOWTO/Module-HOWTO/
    index.html> 傪僠僃僢僋偡傞偐丄/usr/src/linux/Documentation/
    modules.txt 偵婰嵹偝傟偨忣曬傪僠僃僢僋偟偰偔偩偝偄丅
   
 丒 挊幰偼丄偡偱偵妱傝摉偰傪庴偗偰偄偨 IP 偵壛偊偰丄偝傜偵 2 偮偺 IP 傾
    僪儗僗傪巊偊傞傛偆偵偟傑偟偨丅
   
 丒 挊幰偼丄D-Link DE620 億働僢僩傾僟僾僞傪巊偭偰偄傑偡 (傾僟僾僞偺庬椶
    偼廳梫偱偼偁傝傑偣傫丅Linux 偱僒億乕僩偝傟偰偄傞僱僢僩儚乕僋傾僟僾
    僞側傜壗偱傕偐傑偄傑偣傫)丅
   
劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

2. 愝掕僐儅儞僪

 1. IP 僄僀儕傾僗偺儌僕儏乕儖傪儘乕僪偟傑偡 (僇乕僱儖偵儌僕儏乕儖傪慻傒
    崬傫偱偄傞応崌丄偙偺庤弴偼晄梫偱偡)丅
   
    劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
    劆/sbin/insmod /lib/modules/`uname -r`/ipv4/ip_alias.o    劆
    劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
 2. 儖乕僾僶僢僋僨僶僀僗偲 eth0 傪愝掕偟丄eth0 僀儞僞乕僼僃僀僗偵懳偟偰
    儊僀儞 IP 傾僪儗僗偐傜弴斣偵偡傋偰偺 IP 傾僪儗僗傪愝掕偟傑偡丅
   
    劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
    劆/sbin/ifconfig lo 127.0.0.1                             劆
    劆/sbin/ifconfig eth0 up                                  劆
    劆/sbin/ifconfig eth0 172.16.3.1                          劆
    劆/sbin/ifconfig eth0:0 172.16.3.10                       劆
    劆/sbin/ifconfig eth0:1 172.16.3.100                      劆
    劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
   
    172.16.3.1 偲偄偆偺偑丄儊僀儞偲側傞 IP 傾僪儗僗偱偁傝丄.10 偲 .100
    偲偑僄僀儕傾僗偱偡丅廳梫側偺偼丄eth0:x (x=0,1,2,...n) 偲偄偆晹暘偵
    偦傟偧傟堘偆 IP 傾僪儗僗傪愝掕偟偰偄傞偲偄偆偙偲偱偡丅儊僀儞 IP 傾
    僪儗僗偼丄僄僀儕傾僗偵偡傞昁梫偼偁傝傑偣傫丅
   
 3. 儖乕僩偺愝掕傪偟傑偡丅傑偢嵟弶偵丄loopback 偱偡丅師偵丄ret丄偦偟偰
    嵟屻偵丄偦傟偧傟偺 IP 傾僪儗僗傪僨僼僅儖僩 (傕偲傕偲妱傝摉偰傜傟偰
    偄偨 IP 偺偙偲) 偐傜弴偵愝掕偟傑偡丅
   
    劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
    劆/sbin/route add -net 127.0.0.0                          劆
    劆/sbin/route add -net 172.16.3.0 dev eth0                劆
    劆/sbin/route add -host 172.16.3.1 dev eth0               劆
    劆/sbin/route add -host 172.16.3.10 dev eth0:0            劆
    劆/sbin/route add -host 172.16.3.100 dev eth0:1           劆
    劆/sbin/route add default gw 172.16.3.200                 劆
    劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
   
    偙傟偱丄廔椆偱偡丅
   
忋婰椺戣偺 IP 傾僪儗僗偵偼丄愢柧偺曋媂忋丄僾儔僀儀乕僩 IP 傾僪儗僗 (RFC
1918) 傪巊偭偰偄傑偡丅幚嵺偵偼丄撉幰帺恎偺惓幃側 IP 傾僪儗僗偐丄傕偟偔
偼帺暘梡偺 IP 傾僪儗僗偵抲偒姺偊偰偔偩偝偄丅

椺戣偱偼丄3 偮偺 IP 傾僪儗僗偟偐愝掕偟偰偄傑偣傫偑丄嵟戝偱 256 偺 IP 傾
僪儗僗傑偱愝掕偱偒傑偡丅偙偺嵟戝抣偼丄/usr/include/linux/net_alias.h 偱
愝掕偱偒傑偡丅偲偼偄偊丄256 偺 IP 傾僪儗僗傪堦枃偺僱僢僩儚乕僋僇乕僪偵
愝掕偡傞恖偼偄側偄偱偟傚偆偗偳 :-)!

埲壓偵丄挊幰偺 /sbin/ifconfig 偺弌椡寢壥傪婰嵹偟傑偡丅

lo        Link encap:Local Loopback                                                
               inet addr:127.0.0.1  Bcast:127.255.255.255  Mask:255.0.0.0          
                         UP BROADCAST LOOPBACK RUNNING  MTU:3584  Metric:1         
                    RX packets:5088 errors:0 dropped:0 overruns:0                  
                    TX packets:5088 errors:0 dropped:0 overruns:0                  
                                                                                   
eth0      Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20                     
                    inet addr:172.16.3.1  Bcast:172.16.3.255  Mask:255.255.255.0   
                    UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1     
                    RX packets:334036 errors:0 dropped:0 overruns:0                
                    TX packets:11605 errors:0 dropped:0 overruns:0                 
                    Interrupt:7 Base address:0x378                                 
                                                                                   
eth0:0    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20                     
                    inet addr:172.16.3.10  Bcast:172.16.3.255  Mask:255.255.255.0  
                    UP BROADCAST RUNNING  MTU:1500  Metric:1                       
                    RX packets:0 errors:0 dropped:0 overruns:0                     
                    TX packets:0 errors:0 dropped:0 overruns:0                     
                                                                                   
eth0:1    Link encap:10Mbps Ethernet  HWaddr 00:8E:B8:83:19:20                     
                    inet addr:172.16.3.100  Bcast:172.16.3.255  Mask:255.255.255.0 
                    UP BROADCAST RUNNING  MTU:1500  Metric:1                       
                    RX packets:1 errors:0 dropped:0 overruns:0                     
                    TX packets:0 errors:0 dropped:0 overruns:0                     

傑偨丄/proc/net/aliases 偼丄師偺傛偆側傕偺偱偡丅

劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
劆device         family    address                                    劆
劆eth0:0           2      172.16.3.10                                 劆
劆eth0:1           2      172.16.3.100                                劆
劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊

偦偟偰丄/proc/net/alias_tupes 偑丄埲壓偱偡丅

type    name            n_attach                                       
2       ip              2                                              

傕偪傠傫丄/proc/net 埲壓偺弌椡偼丄庤摦偱曇廤偟偨偺偱偼側偔丄ifconfig 僐
儅儞僪偵傛偭偰惗惉偝傟偨傕偺偱偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

3. 僩儔僽儖僔儏乕僥傿儞僌丗幙栤偲夝摎

3.1. 幙栤丗儕僽乕僩偟偰傕愝掕偑堐帩偝傟傞傛偆偵偡傞偵偼丠

夝摎丗BSD 僗僞僀儖偺 init 傪巊偭偰偄傞応崌偱傕丄 SysV 僗僞僀儖 (椺偊偽
丄RedHat ) 偺 init 偺応崌傕丄偄偢傟傕 /etc/rc.d/rc.local 偵愝掕傪婰弎偡
傟偽丄愝掕偑堐帩偝傟傑偡丅埲壓偵丄SysV init 僔僗僥儉 (RedHat 3.0.3 偲
4.0 ) 偺挊幰偺愝掕傪婰嵹偟傑偡丅

挊幰偺 /etc/rc.d/rc.local丗(娭楢晹暘偩偗偱偡)

劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
劆#setting up IP alias interfaces                                     劆
劆echo "Setting 172.16.3.1, 172.16.3.10, 172.16.3.100 IP Aliases ..." 劆
劆/sbin/ifconfig lo 127.0.0.1                                         劆
劆/sbin/ifconfig eth0 up                                              劆
劆/sbin/ifconfig eth0 172.16.3.1                                      劆
劆/sbin/ifconfig eth0:0 172.16.3.10                                   劆
劆/sbin/ifconfig eth0:1 172.16.3.100                                  劆
劆#setting up the routes                                              劆
劆echo "Setting IP routes ..."                                        劆
劆/sbin/route add -net 127.0.0.0                                      劆
劆/sbin/route add -net 172.16.3.0 dev eth0                            劆
劆/sbin/route add -host 172.16.3.1 eth0                               劆
劆/sbin/route add -host 172.16.3.10 eth0:0                            劆
劆/sbin/route add -host 172.16.3.100 eth0:1                           劆
劆/sbin/route add default gw 172.16.3.200                             劆
劆#                                                                   劆
劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

3.2. 幙栤丗儅僔儞偵 IP 僄僀儕傾僗傪愝掕偟丄僄僀儕傾僗愝掕偟偨屄乆偺 IP
傾僪儗僗忋偱儊乕儖傪庴怣偡傞偵偼偳偆偡傟偽偄偄偱偡偐 (sendmail 傪巊偭偨
儅僔儞偱偡)丠

夝摎丗椺偊偽丄/etc/mynames.cw 偲偄偭偨僼傽僀儖傪嶌惉偟傑偡(婛偵嶌惉嵪傒
側傜丄偦傟傪巊偭偰壓偝偄)丅僼傽僀儖柤偼丄偙偺柤慜偺捠傝偱側偔偰傕偐傑偄
傑偣傫偟丄昁偢偟傕 /etc 僨傿儗僋僩儕偵偁傞昁梫傕偁傝傑偣傫丅

偦偺僼傽僀儖偺拞偵丄僄僀儕傾僗愝掕偟偨 IP 傾僪儗僗偺惓幃側僪儊僀儞柤傪
彂偒崬傒傑偡丅僄僀儕傾僗愝掕偟偨 IP 傾僪儗僗偑僪儊僀儞柤傪帩偭偰偄側偄
応崌偼丄IP 傾僪儗僗帺懱傪彂偒崬傫偱傕偐傑偄傑偣傫丅

/etc/mynames.cw 偼丄師偺傛偆側傕偺偵側傞偲巚偄傑偡丅

# /etc/mynames.cw - include all aliases for your machine here; # is a comment 
domain.one.net                                                                
domain.two.com                                                                
domain.three.org                                                              
4.5.6.7                                                                       

sendmail.cf 偵偼丄僼傽僀儖丒僋儔僗丒儅僋儘 (file class macro) 傪愝掕偟
偰偄傞晹暘偑偁傞偺偱丄偦偙偵埲壓偺撪梕傪捛壛偟傑偡丅

劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
劆                                                                    劆
劆##################                                                  劆
劆#   local info   #                                                  劆
劆##################                                                  劆
劆                                                                    劆
劆                                                                    劆
劆# file containing names of hosts for which we receive email         劆
劆Fw/etc/mynames.cw                                                   劆
劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊

偙傟偱戝忎晇側偼偢偱偡丅sendmail 傪僥僗僩儌乕僪偱婲摦偟偰丄怴偟偄愝掕偑
忋庤偔摦偔偐妋偐傔偰偔偩偝偄丅椺偊偽丄埲壓偺傛偆偵偟傑偡丅

劇劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
劆ganymede$ /usr/lib/sendmail -bt                                                 劆
劆ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)                         劆
劆Enter < ruleset> < address>                                                     劆
劆> 0 me@4.5.6.7                                                                  劆
劆rewrite: ruleset  0   input: me @ 4 . 5 . 6 . 7                                 劆
劆rewrite: ruleset 98   input: me @ 4 . 5 . 6 . 7                                 劆
劆rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 7                                 劆
劆rewrite: ruleset 97   input: me @ 4 . 5 . 6 . 7                                 劆
劆rewrite: ruleset  3   input: me @ 4 . 5 . 6 . 7                                 劆
劆rewrite: ruleset 96   input: me < @ 4 . 5 . 6 . 7 >                             劆
劆rewrite: ruleset 96 returns: me < @ 4 . 5 . 6 . 7 . >                           劆
劆rewrite: ruleset  3 returns: me < @ 4 . 5 . 6 . 7 . >                           劆
劆rewrite: ruleset  0   input: me < @ 4 . 5 . 6 . 7 . >                           劆
劆rewrite: ruleset 98   input: me < @ 4 . 5 . 6 . 7 . >                           劆
劆rewrite: ruleset 98 returns: me < @ 4 . 5 . 6 . 7 . >                           劆
劆rewrite: ruleset  0 returns: $# local $: me                                     劆
劆rewrite: ruleset 97 returns: $# local $: me                                     劆
劆rewrite: ruleset  0 returns: $# local $: me                                     劆
劆> 0 me@4.5.6.8                                                                  劆
劆rewrite: ruleset  0   input: me @ 4 . 5 . 6 . 8                                 劆
劆rewrite: ruleset 98   input: me @ 4 . 5 . 6 . 8                                 劆
劆rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 8                                 劆
劆rewrite: ruleset 97   input: me @ 4 . 5 . 6 . 8                                 劆
劆rewrite: ruleset  3   input: me @ 4 . 5 . 6 . 8                                 劆
劆rewrite: ruleset 96   input: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset 96 returns: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset  3 returns: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset  0   input: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset 98   input: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset 98 returns: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset 95   input: < > me < @ 4 . 5 . 6 . 8 >                         劆
劆rewrite: ruleset 95 returns: me < @ 4 . 5 . 6 . 8 >                             劆
劆rewrite: ruleset  0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 > 劆
劆rewrite: ruleset 97 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 > 劆
劆rewrite: ruleset  0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 > 劆
劆>                                                                               劆
劋劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊

me@4.5.6.7 傪僥僗僩偟偨嵺丄儊乕儖偼儘乕僇儖儅僔儞偵攝怣偝傟丄
me@4.5.6.8 傪僥僗僩偟偨嵺偼丄SMTP 儊乕儔偵搉偝傟傑偟偨丅偙傟偼丄惓偟偄
摦嶌偱偡丅

偙傟偱丄愝掕偼偡傋偰廔椆偱偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

4. 幱帿

Linux 偲 IP 僄僀儕傾僗偺奐敪偵娭傢偭偨偡傋偰偺恖乆偵姶幱偟傑偡丅偦偟偰
丄巹偺媈栤傪夝寛偟偰偔傟偨 Juan Ciarlante 偵偼摿偵姶幱偟偰偄傑偡丅

僄乕僗丒僾儘僌儔儅偨偪偵塰岝偁傟両

偙偺暥彂偵偮偄偰偺姶憐傗採埬丄偛堄尒偼丄<h.pillay@ieee.org> 傑偱儊乕儖
偱偍抦傜偣偔偩偝偄丅

傛傠偟偔偍婅偄偟傑偡丅

僱僢僩儚乕僉儞僌偵娭偡傞徻偟偄忣曬偼丄Networking-Overview-HOWTO <http:/
/www.linuxdoc.org/HOWTO/Networking-Overview-HOWTO.html> (擔杮岅栿
<http://www.linux.or.jp/JF/JFdocs/Networking-Overview-HOWTO.html>) 傪偛
棗偔偩偝偄丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒

5. 擔杮岅栿偵偮偄偰

東 媑曱岾                           
栿 榊     (1997/05/24)              
丗                                  
峏 愮扷桾                           
怴 巌     (2001/09/15)              
丗                                  
峑 Seiji                            
惓 Kaneko                           
丗                                  

岆栿丒岆怉丒僐儊儞僩摍偼丄<JF@linux.or.jp> 傑偱偍婅偄偟傑偡丅

