|This is some basic stuff, when setting a Linux box for networking. Sometimes, there is the need to isolate specific traffic from your router to be seen only by your second NIC, sometimes you just don’t want your NIC to stay in the default VLAN because of frequent network loops killing your PC, you don’t want to give another hundred dollars for 2-port demarcation device or you are small ISP and your backbone provider has appointed a range of VLANs for you and your points of interest around the city, so you have to get the tagged traffic on a Slackware Linux box and untag it for your customers. I’ve often used bridging of VLAN tagged traffic over a test PC in my work as a QA.
Reasons can be found enough for a small novel.
So in few words, when you need your network interface to accept tagged traffic, untag it and then send it to your kernel, that’s how it’s done:
bash-4.1# lsmod | grep 802 bash-4.1# modprobe 8021q bash-4.1# lsmod | grep 802 8021q 18128 0 bash-4.1# vconfig add eth3 200 Added VLAN with VID == 200 to IF -:eth3:- bash-4.1# ifconfig eth3.200 10.0.0.1/16 up bash-4.1# ping 10.0.155.50 -I eth3.200 PING 10.0.155.50 (10.0.155.50) 56(84) bytes of data. 64 bytes from 10.0.155.50: icmp_req=1 ttl=63 time=0.286 ms 64 bytes from 10.0.155.50: icmp_req=2 ttl=63 time=0.286 ms 64 bytes from 10.0.155.50: icmp_req=3 ttl=63 time=0.275 ms 64 bytes from 10.0.155.50: icmp_req=4 ttl=63 time=0.281 ms ^C --- 10.0.155.50 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.275/0.282/0.286/0.004 ms bash-4.1#
802.1q is the name of the protocol, the Kernel module is called 8021q. If the module is already loaded, the modprobe line can be omitted. If you want the module loaded at startup, you can add it in /etc/rc.local or /etc/rc.d/rc.modules (your preference). The first will load the module when everything else is already set. The VLAN configuration will be set regardless the module is loaded AFTER the ifconfig and vconfig have done their jobs.
The vconfig line adds the actual VLAN to Ethernet card 3 (change, according to your setup) and the ifconfig is setting IP address and mask (change to your setup or omit), and is enabling the Ethernet card. Finaly, you get one eth3 and one eth3.200:
bash-4.1# ifconfig eth3 eth3 Link encap:Ethernet HWaddr 00:0E:2E:72:96:F7 inet addr:10.0.0.2 Bcast:10.0.255.255 Mask:255.255.0.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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:19 Base address:0xdc00 bash-4.1# ifconfig eth3.200 eth3.200 Link encap:Ethernet HWaddr 00:0E:2E:72:96:F7 inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.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) bash-4.1#
On the same Ethernet card, more VLANs can be enabled by adding them the same way. (no need to load the Kernel module every time, in case you don’t know that) If you need the VLAN removed from your NIC, do the reverse:
bash-4.1# ifconfig eth3.200 down bash-4.1# vconfig rem eth3.200 Removed VLAN -:eth3.200:-
For some reason, there is no decent configuration example for how to make Slackware enable VLAN on specific NIC in boot process. I’ve made a short script and attached it to rc.local. It executes when everything else is already set, but I did not need it earlier in the first place:
#!/bin/bash echo "Setting vlans ..." modprobe 8021q vconfig add eth3 200 ifconfig eth3.200 10.0.0.5/16 up echo "... done"