通过配置文件配置vlan
加载8021q模块
[root@ct7_node02 network-scripts]# modprobe 8021q
[root@ct7_node02 network-scripts]# lsmod | grep 802
8021q 33080 0
garp 14384 1 8021q
mrp 18542 1 8021q
修改配置文件
[root@ct7_node02 network-scripts]# cat ifcfg-eth3
DEVICE=eth3
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
[root@ct7_node02 network-scripts]# cat ifcfg-eth3.220
DEVICE=eth3.220
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.4.220
PREFIX=24
NETWORK=192.168.4.254
VLAN=yes
重启网络服务
[root@ct7_node02 network-scripts]# systemctl stop NetworkManager
[root@ct7_node02 network-scripts]# service network restart
Restarting network (via systemctl): [ OK ]
[root@ct7_node02 network-scripts]#
验证
[root@ct7_node02 network-scripts]# ip a
...
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff
inet6 fe80::7652:1ff:fe01:204/64 scope link
valid_lft forever preferred_lft forever
...
10: eth3.220@eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.220/24 brd 192.168.4.255 scope global eth3.220
valid_lft forever preferred_lft forever
inet6 fe80::7652:1ff:fe01:204/64 scope link
valid_lft forever preferred_lft forever
[root@ct7_node02 network-scripts]# ip -d link show eth3.220
10: eth3.220@eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 74:52:01:01:02:04 brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 220 <REORDER_HDR> addrgenmode eui64
通过命令行配置vlan
要在以太网接口 eth02中创建名为 VLAN8、ID 为 8 的 802.1Q VLAN 接口,请作为 root 运行以下命令:
[root@ct7_node02 network-scripts]# ip link add link eth0 name eth0.8 type vlan id 8
查看vlan
命令:ip -d link show eth0.8
[root@ct7_node02 network-scripts]# ip -d link show eth0.8
11: eth0.8@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 74:52:01:01:02:01 brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 8 <REORDER_HDR> addrgenmode eui64
[root@ct7_node02 network-scripts]# ip a
...
11: eth0.8@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 74:52:01:01:02:01 brd ff:ff:ff:ff:ff:ff
移除 VLAN
[root@ct7_node02 network-scripts]# ip link delete eth0.8