用户工具

站点工具


faq:ip_aliasing

/etc/rc.conf 中有关 IP Aliasing 配置语法

在 /etc/rc.conf 中,有新、舊两种配置 IP Aliasing 语法,两者在 FreeBSD 9.x 皆有相同效果。以下例子假设网卡是 em0

舊语法,共 6 句。

ifconfig_em0="inet 192.168.10.10  netmask 255.255.255.0"
ifconfig_em0_alias0="inet 192.168.10.11 netmask 255.255.255.255"
ifconfig_em0_alias1="inet 192.168.10.12 netmask 255.255.255.255"
ifconfig_em0_alias2="inet 192.168.10.13 netmask 255.255.255.255"
ifconfig_em0_alias3="inet 192.168.10.14 netmask 255.255.255.255"
ifconfig_em0_alias4="inet 192.168.10.15 netmask 255.255.255.255"

新语法,只需要 1 句。

ipv4_addrs_em0="192.168.10.10-15/24"

查询 IP Aliasing 是否成功,可以用 ifconfig 命令。

ifconfig

em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=219b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,WOL_MAGIC>
        ether 00:1b:e1:12:0f:f1
        inet 192.168.10.10 netmask 0xffffff00 broadcast 192.168.10.255
        inet 192.168.10.11 netmask 0xffffffff broadcast 192.168.10.11
        inet 192.168.10.12 netmask 0xffffffff broadcast 192.168.10.12
        inet 192.168.10.13 netmask 0xffffffff broadcast 192.168.10.13
        inet 192.168.10.14 netmask 0xffffffff broadcast 192.168.10.14
        inet 192.168.10.15 netmask 0xffffffff broadcast 192.168.10.15

更详细介绍请看 man 5 rc.conf

【注】在10.0-RELEASE中,ipv4_addrs的功能已被整合至ifconfig,推荐继续使用ifconfig的写法,rc.conf(5)对此的描述为:

With the interface in question being ed0, an example could look like:
    ifconfig_ed0_alias2="inet 192.0.2.129/27"
    ifconfig_ed0_alias3="inet 192.0.2.1-5/28"
and so on.
Note that ipv4_addrs_⟨interface⟩ variable was supported for IPv4 CIDR address notation.
It is now deprecated because the functionality was integrated into ifconfig_⟨interface⟩_alias⟨n⟩
though ipv4_addrs_⟨interface⟩ is still supported for backward compatibility.
/data/vhosts/wiki-data/pages/faq/ip_aliasing.txt · 最后更改: 2014/03/25 10:33 由 alphachi