This translation is older than the original page and might be outdated. See what has changed.

别名

原“config alias”别名配置方法已弃用,新别名配置方法已合并到interface中。下文依然用Alias节来称呼它

Alias 节可用于进一步定义interfaces的IPv4和IPv6地址。 它还允许像在主interface上使用DHCP而在alias中使用静态IPv6地址这样的组合, 例如在wan上部署IPv6,同时保持正常的internet连接。 每个interface可以有多个alias依附它。

为每个IP创建一个'interface'节, 但是alias interfaces(别名接口)不能是桥接类型。.

  • 对于非桥接interfaces (physdev , 即物理接口) ,ifname 设置为 <interface-of-network-for-same-phydev相同物理接口的网络接口>
  • 如果interface是桥接的,设置ifname为br-base-interface, 其中base-interface是主IP配置节的名称(例如对于默认的lan interface配置, 第一个alias将使用ifname br-lan).
  • 更为推荐另一种通用的,避免总是列出相同设备的方法,是设置ifname为@base-interface, 这样即使wan interface的类型不是bridge,也可以间接引用wan interface使用的物理设备

以下是bridged interface的最小alias定义(对于没有vlan的场景):

config interface lan
        option device 'eth0'  #也可以使用option ifname 'eth0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
 
config interface lan1
       option device '@lan'   #或者使用 'br-lan',也可以使用option ifname '@lan'
       option proto 'dhcp'

config interface lan2

     option device '@lan'   #或者使用 'br-lan',也可以使用option ifname '@lan'
     option proto 'static'
     option ipaddr '10.0.0.1'
     option netmask '255.255.255.0'

</code>

非桥接接口:

config interface lan
        option device 'eth0'    #也可以使用option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
 
config interface lan1
       option device 'eth0'    #也可以使用option ifname 'eth0'
       option proto 'dhcp'

config interface lan2

     option device 'eth0'    #也可以使用option ifname 'eth0'
     option proto 'static'
     option ipaddr '10.0.0.1'
     option netmask '255.255.255.0'

</code>

要查看接口列表,你可以执行ubus list network.interface.* ,而查看特定interface(是UCI名称而不是物理接口)的ip,执行ifstatus <interface> (例如 ifstatus lan2).

名称 类型 是否必须 默认 描述
interface string 是 (none) 已废弃,指定此alias所属parent (or master) interface的logical interface name; 必须引用一个已定义的interface节
ifname string 是 (none) 指定此alias所属parent (or master) interface的@logical interface name; 必须引用一个已定义的interface节
device string 是 (none) 指定此alias所属节或设备名称
proto string 是 (none) 指定 alias 接口协议
ipaddr ip address 是, 若未设置ip6addr (none) aliasIP地址
netmask netmask 是, 若未设置ip6addr (none) alias子网掩码
gateway ip address 否 (none) 默认网关
broadcast ip address 否 (none) 广播地址 (如果没有设置,则自动生成)
ip6addr ipv6 address 是, 若未设置ipaddr (none) IPv6地址 (CIDR标记)
ip6gw ipv6 address 否 (none) IPv6默认网关
dns list of ip addresses 否 (none) DNS服务器
layer integer 否 3 为stacked协议选择要附件的interface (tun over bridge over eth, ppp over eth or similar).
3: attach to layer 3 interface (tun*, ppp* if parent is layer 3 else fallback to 2)
2: attach to layer 2 interface (br-* if parent is bridge else fallback to layer 1)
1: attach to layer 1 interface (eth*, wlan*)

请检查这是否仍然是正确的:在编写这个的时候, aliases允许的protocol类型只有static.

  • Last modified: 2023/01/12 07:20
  • by shorile