Configuring VLANs in Linux
This section uses RHEL 7.2 as an example. For details about the configuration on other OSs, see the OS documentation provided by the OS vendors.
To configure VLANs in RHEL 7.2 that has NIC drivers installed, perform the following steps:
The setting takes effect only once. After the OS is restarted, the previous VLAN configuration will be restored.
- Run the following command to load the 802.1q module:
[root@localhost ~]# modprobe 8021q
- Run the ifconfig -a command to locate the MZ520 ports.
- Run the ip link add link enp4s0f[num] enp4s0f[num].[vlan id num] type vlan id [num] to add a VLAN to a port. For example, to add VLAN 100 and VLAN 200 to the enp4s0f0 network port, run the following commands:
[root@localhost ~]# ip link add link enp4s0f0 enp4s0f0.100 type vlan id 100 [root@localhost ~]# ip link add link enp4s0f0 enp4s0f0.200 type vlan id 200
- Run the ip addr add [ip address] dev enp4s0f[num].[vlan id num] command to configure the IP address of the VLAN, that is, the IP address of port enp4s0f[num].
[root@localhost ~]# ip addr add 192.168.100.90/24 dev enp4s0f0.100 [root@localhost ~]# ip addr add 192.168.100.91/24 dev enp4s0f0.200
IP addresses that belong to different VLANs must be configured on different network segments.
To make the VLAN configuration take effect permanently, install the NIC driver and perform the following steps:
- Add the VLAN information to the configuration file.
#echo "modprobe 8021q">>/etc/rc.local
- Run the following command to load the 802.1q module:
[root@localhost ~]# modprobe 8021q
- Add the VLAN ID to the port and configure the VLAN IP address.For example, to add VLAN 100 to network port enp4s0f0 and configure the VLAN IP address, run the following command:
# vim /etc/sysconfig/network-scripts/ifcfg-enp4s0f0.100 DEVICE=enp4s0f0.100 BOOTPROTO=none USERCTL=no IPADDR=172.168.100.19 NETMASK=255.255.255.0 GATEWAY=172.168.100.1 VLAN=yes ONBOOT=yes
- Run the following command to restart the network application:
#/etc/init.d/network restart