一、使用IP命令配置
此前 Arch Linux 用?vconfig?命令設(shè)置 VLANs ,該命令已被?ip?命令取代。下面的范例假定?網(wǎng)口?是?enp125s0f0,名字?是?enp125s0f0.100?,vlan id?是?100。
1. 創(chuàng)建 VLAN 設(shè)備
用下列命令添加 VLAN 網(wǎng)口:
# ip link add link enp125s0f0 name enp125s0f0.100 type vlan id 100
執(zhí)行?ip link?命令確認(rèn) VLAN 已創(chuàng)建。
這個(gè) VLAN 網(wǎng)口就像一個(gè)普通的物理網(wǎng)口,所有流經(jīng)這個(gè)網(wǎng)口的數(shù)據(jù)包將被加上 VLAN tag 并流經(jīng)它關(guān)聯(lián)的物理網(wǎng)口(本例中的?enp125s0f0)。僅配置為相同 VLAN 的設(shè)備可接收這些數(shù)據(jù)包,否則將被丟棄。
?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: <BROADCAST,MULTICAST> 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 <REORDER_HDR> 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. 關(guān)閉設(shè)備
To cleanly shutdown the setting before you remove the link, you can do:
# ip link set dev enp125s0f0.100 down
4. 移除設(shè)備
Removing a VLAN interface is significantly less convoluted
# ip link delete enp125s0f0.100
5. 持久化?
DEVICE=test? ? #名稱(chēng)可以自定義
PHYSDEV=enp125s0f0? ? ? #父接口
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.10.3
NETMASK=255.255.255.0
VLAN=yes
VID=100
MACADDR=02:0e:5e:e0:e4:47
二、使用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接口上配置兩個(gè)VLAN
#vconfig set_flag enp8s0f1.100 1 1
#vconfig set_flag enp8s0f1.200 1 1
設(shè)置VLAN的REORDER_HDR參數(shù),默認(rèn)就行了。
可以使用cat /proc/net/vlan/enp8s0f1.100查看enp8s0f1.100參數(shù)
配置網(wǎng)絡(luò)信息
#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信息寫(xiě)入配置文件
#echo "modprobe 8021q">>/etc/rc.local
開(kāi)機(jī)加載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