아래의 예제는 eth0 하위에 VLAN을 두개 만드는 예이다.
Configure an interface for use with multiple VLANs in CentOS
Most network administrators are likely familiar with Virtual Local Area Network’s or VLANs. VLANs allow several different networks to coexist on the same physical switch. Let’s say you have two physical networks, one used for Internet traffic and an internal network used specifically for backup traffic. In a non-VLANd environment, this setup would require two physical switches (one for the Internet and one of the backup network) and dual network cards on each host you wish to connect to both VLANs.
Using VLANs, one could setup a switch with multiple networks. Typically a host would require one network interface for each network, or VLAN you wanted to connect it to. In this article, I will describe how to configure a single network interface in CentOS to connect to multiple VLANs coming from a switch.
* Configuring your switch for VLANing is beyond the scope of this article and will not be covered here. I would recommend checking the documentation provided by your hardware vendor for instructions on configuring your VLANs from a switch level.
Requirements
In order to configure your network adapter for VLAN, it is require your network driver supports VLAN. If not, it may be necessary to patch your driver or upgrade your hardware. You will also need to configure the interface on your switch to send tagged traffic (a trunk port) for each VLAN ID you want to connect to to the port that connects to your host.
Using vconfig to setup your VLANs
We have two networks we want to connect to:
VLAN ID 10: Internet traffic
VLAN ID 20: Backup network traffic
Add the VLANs:
vconfig add eth0 10
vconfig add eth0 20
This will create two virtual devices on eth0. You can use ifconfig to see information on the device:
ifconfig eth0.10
ifconfig eth0.20
Now we can use ifconfig to set an IP address on our devices: 물론 아래 명령보다는 ifcfg-eth0.10과 ifcfg-eth0.20 CONFIG 파일을 하나씩 만들어 놔야져..
ifconfig eth0.10 1.2.3.4 netmask 255.255.255.0 broadcast 1.2.3.255 up
ifconfig eth0.20 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255 up
You can also view information on the virtual device / VLAN:
cat /proc/net/vlan/eth0.10
cat /proc/net/vlan/eth0.20
…and finally if you wish to remove the VLAN / bring down the virtual interface:
ifconfig eth0.10 down
vconfig rem eth0.10
ifconfig eth0.20 down
vconfig rem eth0.20