一、使用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 promiscuity 0 minmtu 0 maxmtu 65535

vlan protocol 802.1Q id 100 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

2. 添加 IP

Now add an IPv4 address to the just created vlan link, and activate the link:# ip addr add 192.168.100.1/24 brd 192.168.100.255 dev

enp125s0f0.100

# ip link set dev

enp125s0f0.100

up

3. 关闭设备

To cleanly shutdown the setting before you remove the link, you can do:# ip link set dev

enp125s0f0.100

down

4. 移除设备

Removing a VLAN interface is significantly less convoluted# ip link delete enp125s0f0.100

二、使用vconfig配置

1.安装vlan(vconfig)和加载8021q模块#aptitude install vlan

#modprobe 8021q

或:

#yum install vconfig

#modprobe 8021q

#lsmod |grep -i 8021q

2.使用linux vconfig命令配置vlan#vconfig add enp8s0f1 100

#vconfig add enp8s0f1 200

在enp8s0f1接口上配置两个VLAN#vconfig set_flag enp8s0f1.100 1 1

#vconfig set_flag enp8s0f1.200 1 1

设置VLAN的REORDER_HDR参数,默认就行了。可以使用cat /proc/net/vlan/enp8s0f1.100查看enp8s0f1.100参数

配置网络信息#ifconfig enp8s0f1 0.0.0.0

#ifconfig enp8s0f1.100 192.168.100.50 netmask 255.255.255.0 up

#ifconfig enp8s0f1.200 192.168.200.50 netmask 255.255.255.0 up

删除VLAN命令#vconfig rem enp8s0f1.100

#vconfig rem enp8s0f1.200

3.将VLAN信息写入配置文件#echo "modprobe 8021q">>/etc/rc.local

开机加载8021q模块,或者使用echo"8021q">>/etc/modules

#cp /etc/network/interfaces /etc/network/interfaces.default

#vim /etc/network/interfaces

auto lo enp8s0f1

iface lo inet loopback

iface enp8s0f1.100 inet static

address 192.168.100.50

netmask 255.255.255.0

iface enp8s0f1.200 inet static

address 192.168.200.50

netmask 255.255.255.0

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐