Configure an Ethernet interface as a VLAN trunk (Red Hat)
Content |
Specific to |
Red Hat-based distributions |
Tested on |
CentOS (5.5) |
Objective
To configure an Ethernet interface as an IEEE 802.1Q VLAN trunk on a Red Hat-based distribution.
Background
See Configure an Ethernet interface as a VLAN trunk.
Scenario
Suppose that a host requires access to two VLANs, both carried by a trunk connected to physical interface eth0
. The assigned IP addresses for the host are 192.168.2.1/24
on VLAN 2 and 192.168.3.1/24
on VLAN 3.
Method
Add an interface script for each VLAN to /etc/sysconfig/network-scripts/
. This follows the same format as one for a normal Ethernet interface except that:
- it must contain the setting
VLAN=yes
, - the interface name must follow one of the naming conventions supported by
vconfig
(see below), and - the MAC address (HWADDR) need not be specified.
The interface naming convention used and recommended here is of the form ethx.y
, where ethx
is the physical interface name and y
is the VLAN number.
For the scenario described above two interface scripts are needed, one with the pathname /etc/sysconfig/network-scripts/ifcfg-eth0.2
:
VLAN=yes DEVICE=eth0.2 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.2.1 NETMASK=255.255.255.0
and one with the pathname /etc/sysconfig/network-scripts/ifcfg-eth0.3
:
VLAN=yes DEVICE=eth0.3 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.3.1 NETMASK=255.255.255.0
Bring up the interfaces in the normal way using ifup
:
ifup eth0.2 ifup eth0.3
Testing
After invoking ifup
you should be able to inspect the new VLAN interfaces using the ifconfig
command:
ifconfig eth0.2
which should give output of the form:
eth0.2 Link encap:Ethernet HWaddr 00:00:00:00:00:00 inet addr:192.168.2.1 Bcast:12.168.2.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Errors
Invoking ifup has no effect
If ifup
has no apparent effect (no output, no new interface reported by ifconfig
) this could indicate that the specified physical Ethernet device does not exist.
Device does not appear to be present
An error of the form:
Device eth0.2 does not seem to be present, delaying initialization.
could indicate that:
- the
VLAN=yes
setting is missing from the interface script, or - the specified
DEVICE
name does not follow one of the naming conventions supported byvconfig
.
No VLAN support in kernel
An error of the form:
No 802.1Q VLAN support available in kernel for device eth0.2
indicates that the kernel module needed to provide VLAN support has not been loaded. It should load automatically when you invoke ifup
. Determine whether this has happened using the lsmod
command, which lists the kernel modules that are currently loaded. You are looking for one called 8021q
(with no dot between 802
and 1q
):
lsmod | grep 8021q
If the module is not listed then the most likely explanation is that it could not be found. Confirm this by attempting to manually load it using the command modprobe
:
modprobe 8021q
This should give an error of the form:
FATAL: Could not open '/lib/modules/2.6.18-194.el5/kernel/net/8021q/8021q.ko': No such file or directory
The most likely explanation for a failure of this type is that you are running a different kernel from the one that was originally installed but have not provided a matching set of kernel modules. If this is the case then there will be no directory in /lib/modules
with a name that matches the running kernel version.
Alternative possibilities are that the file in question has been deleted somehow, or you are running a custom kernel that does not include 802.1Q support.
Variations
You may encounter interface scripts in which the physical interface name is specified explicitly by means of the PHYSDEV
setting. This is only needed when using a naming convention that does not incorporate the physical interface name, for example:
VLAN=yes VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD PHYSDEV=eth0 DEVICE=vlan2 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.2.1 NETMASK=255.255.255.0
Disadvantages of this approach are that there is more to go wrong, and it does not allow for multiple interfaces with the same VLAN number.