原始文件:Linux IP Alias mini HOWTO | 譯者:C.W. Huang | 最後修改:1997/01/13
說明如何在 Linux 機器設定 IP 別名,並在不同 IP 別名上接收電子郵件。
make config 時選擇 Modules,詳見 Modules HOWTO)。若編譯進核心可略過:
/sbin/insmod /lib/modules/`uname -r`/ipv4/ip_alias.o
/sbin/ifconfig lo 127.0.0.1 /sbin/ifconfig eth0 up /sbin/ifconfig eth0 172.16.3.1 # 主 IP /sbin/ifconfig eth0:0 172.16.3.10 # 別名 0 /sbin/ifconfig eth0:1 172.16.3.100 # 別名 1
格式:eth0:x(x=0,1,2...)對應不同 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
範例使用 RFC 1918 私有 IP,請替換為實際公網或私網 IP。單張網卡最多支援 256 個別名(/usr/include/linux/net_alias.h 定義)。
ifconfig 輸出lo Link encap:Local Loopback inet addr:127.0.0.1 ... eth0 Link encap:10Mbps Ethernet inet addr:172.16.3.1 ... eth0:0 Link encap:10Mbps Ethernet inet addr:172.16.3.10 ... eth0:1 Link encap:10Mbps Ethernet inet addr:172.16.3.100 ...
/proc/net/aliasesdevice family address eth0:0 2 172.16.3.10 eth0:1 2 172.16.3.100
/proc/net/alias_typestype name n_attach 2 ip 2
將設定加入 /etc/rc.d/rc.local(BSD 或 SysV init 均適用):
# 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 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
/etc/mynames.cw(名稱與位置任意),列出所有別名 IP 的完整網域名稱(無網域名稱可直接填 IP):
# /etc/mynames.cw domain.one.net domain.two.com domain.three.org 4.5.6.7
sendmail.cf,在類別巨集 Fw 定義處加入:
Fw/etc/mynames.cw
/usr/lib/sendmail -bt 進入測試模式,輸入 0 me@4.5.6.7 驗證重寫規則正確解析至本機。