linux设置ip的vlan,使用IP和vconfig配置vlan子接口

一、使用IP命令配置

此前 Arch Linux 用 vconfig 命令设置 VLANs ,该命令已被 ip 命令取代。下面的范例假定 网口 是 enp125s0f0,名字 是 enp125s0f0.100 ,vlan id 是 100。

1. 创建 VLAN 设备

用下列命令添加 VLAN 网口:# ip link add link enp125s0f0 name enp125s0f0.100 type vlan id 100

执行 ip link 命令确认 VLAN 已创建。

这个 VLAN 网口就像一个普通的物理网口,所有流经这个网口的数据包将被加上 VLAN tag 并流经它关联的物理网口(本例中的 enp125s0f0)。仅配置为相同 VLAN 的设备可接收这些数据包,否则将被丢弃。

Using a name like enp125s0f0.100 is just convention and not enforced; you can alternatively use enp125s0f0_100 or something descriptive like IPTV. To see the VLAN ID on an interface, in case you used an unconventional name:# ip -d link show enp125s0f0.100

The -d flag shows full details on an interface:# ip -d link show enp125s0f0.100

7: enp125s0f0.100@enp125s0f0: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether 8c:e5:ef:97:50:c8 brd ff:ff:ff:ff:ff:ff

你可能感兴趣的:(linux设置ip的vlan)