vconfig - Linux 下的 802.1q 實現組態工具
著作權聲明:可以任意轉載,轉載時請務必以超連結形式標明文章原始出處和作者資訊及本聲明。
http://windtear.net/archives/2005/07/18/000720.html http://windtear.net/archives/2005/07/18/000720.html
研究過 /sbin/ifup 的話 會發現 ifup 指令碼有 vconfig 和 VLAN 支援的判斷(當時搞 ifup 的 bridge 支援也patch過這個指令碼 2005-04-08 19:01 hBridge - Linux Ethernet bridging)# Ethernet 802.1Q VLAN supportif [ -x /sbin/vconfig -a "${VLAN}" = "yes" ]; then if echo ${DEVICE} | LANG=C egrep -v '(:)' | LANG=C egrep -q 'eth[0-9][0-9]*/.[0-9][0-9]?[0-9]?[0-9]?' ; then if [ ! -d /proc/net/vlan ]; then if modprobe 8021q >/dev/null 2>&1 ; then /sbin/vconfig set_name_type DEV_PLUS_VID_NO_PAD >/dev/null 2>&1 || { echo $"Could not set 802.1Q VLAN parameters." } else echo $"No 802.1Q VLAN support available in kernel for device ${DEVICE}" exit 1 fi fi VID="`echo ${DEVICE} | / LANG=C egrep 'eth[0-9]+/.[0-9][0-9]?[0-9]?[0-9]?$' | / LANG=C sed 's/^[a-z0-9]*/.//g;s/^0*//'`" PHYSDEV="`echo ${DEVICE} | / LANG=C egrep 'eth[0-9]+/.[0-9][0-9]?[0-9]?[0-9]?$' | / LANG=C sed 's//.[a-z0-9]*$//g'`" is_available ${PHYSDEV} || { if [ "$?" = "1" ] ; then echo $"$alias device ${DEVICE} does not seem to be present, delaying initialization." exit 1 else exit 0 fi } # Link on Physical device needs to be up but no ip required check_device_down ${PHYSDEV} && { ip -o link set dev ${PHYSDEV} up } if [ ! -f /proc/net/vlan/${DEVICE} ]; then /sbin/vconfig add ${PHYSDEV} ${VID} || { (logger -p daemon.info -t ifup / $"ERROR: could not add vlan ${VID} as ${DEVICE} on dev ${PHYSDEV}" &)& echo $"ERROR: could not add vlan ${VID} as ${DEVICE} on dev ${PHYSDEV}" exit 1 } fi if [ -f /proc/net/vlan/${DEVICE} ]; then case "$REORDER_HDR" in yes|1) /sbin/vconfig set_flag ${DEVICE} 1 1 || { (logger -p daemon.info -t ifup / "WARNING: vconfig not able to enable REORDER_HDR on ${DEVICE}" &)& } ;; no|0) /sbin/vconfig set_flag ${DEVICE} 1 0 || { (logger -p daemon.info -t ifup / $"WARNING: vconfig not able to disable REORDER_HDR on ${DEVICE}" &)& } ;; esac fi fifivconfig 就是 Linux 下 802.1Q VLAN 實現組態工具Name : vconfig Relocations: (not relocatable)Version : 1.6 Vendor: Red Hat, Inc.Release : 2 Build Date: Sat 01 Feb 2003 06:20:05 AM CSTInstall Date: Tue 01 Jun 2004 04:55:57 PM CST Build Host: porky.devel.redhat.comGroup : System Environment/Base Source RPM: vconfig-1.6-2.src.rpmSize : 170822 License: LGPLSignature : DSA/SHA1, Mon 24 Feb 2003 02:05:29 PM CST, Key ID 219180cddb42a60ePackager : Red Hat, Inc. URL : http://www.candelatech.com/~greear/vlan.htmlSummary : Linux 802.1q VLAN configuration utility.Description :The vconfig program configures and adjusts 802.1q VLAN parameters./sbin/vconfig/usr/share/doc/vconfig-1.6/usr/share/doc/vconfig-1.6/CHANGELOG/usr/share/doc/vconfig-1.6/README/usr/share/doc/vconfig-1.6/contrib/usr/share/doc/vconfig-1.6/contrib/CVS/usr/share/doc/vconfig-1.6/contrib/CVS/Entries/usr/share/doc/vconfig-1.6/contrib/CVS/Repository/usr/share/doc/vconfig-1.6/contrib/CVS/Root/usr/share/doc/vconfig-1.6/contrib/README/usr/share/doc/vconfig-1.6/contrib/vlan_2.2-full.patch/usr/share/doc/vconfig-1.6/contrib/vlan_2.2-module.patch/usr/share/doc/vconfig-1.6/vlan.html/usr/share/doc/vconfig-1.6/vlan_test.pl/usr/share/man/man8/vconfig.8.gz% vconfigExpecting argc to be 3-5, inclusive. Was: 1Usage: add [interface-name] [vlan_id] rem [vlan-name] set_flag [interface-name] [flag-num] [0 | 1] set_egress_map [vlan-name] [skb_priority] [vlan_qos] set_ingress_map [vlan-name] [skb_priority] [vlan_qos] set_name_type [name-type]* The [interface-name] is the name of the ethernet card that hosts the VLAN you are talking about.* The vlan_id is the identifier (0-4095) of the VLAN you are operating on.* skb_priority is the priority in the socket buffer (sk_buff).* vlan_qos is the 3 bit priority in the VLAN header* name-type: VLAN_PLUS_VID (vlan0005), VLAN_PLUS_VID_NO_PAD (vlan5), DEV_PLUS_VID (eth0.0005), DEV_PLUS_VID_NO_PAD (eth0.5)* bind-type: PER_DEVICE # Allows vlan 5 on eth0 and eth1 to be unique. PER_KERNEL # Forces vlan 5 to be unique across all devices.* FLAGS: 1 REORDER_HDR When this is set, the VLAN device will move the ethernet header around to make it look exactly like a real ethernet device. This may help programs such as DHCPd which read the raw ethernet packet and make assumptions about the location of bytes. If you don't need it, don't turn it on, because there will be at least a small performance degradation. Default is OFF.-----> 在eth0介面配置兩個vlan 如果沒有載入模組會自動載入8021q模組vconfig add eth0 11vconfig add eth0 21-----> 設定參數 REORDER_HDR (預設就是)vconfig set_flag eth0.11 1 1vconfig set_flag eth0.21 1 1-----> 查看一下cat /proc/net/vlan/eth0.11cat /proc/net/vlan/eth0.21-----> 改介面啟動設定檔cd /etc/sysconfig/network-scripts/cp ifcfg-eth0 ifcfg-eth0.11perl -pi -e 's/DEVICE=eth0/DEVICE=eth0.11/g' ifcfg-eth0.11cp ifcfg-eth0 ifcfg-eth0.21perl -pi -e 's/DEVICE=eth0/DEVICE=eth0.21/g' ifcfg-eth0.21perl -pi -e 's/IPADDR=/#IPADDR=/g' ifcfg-eth0perl -pi -e 's/NETMASK=/#NETMASK=/g' ifcfg-eth0......-----> 手工切換 這時需要更改交換器配置ifdown eth0;ifup eth0;ifup eth0.11;ifup eth0.21-----> 設定下次啟動自動載入 8021q 模組echo VLAN=yes >> /etc/sysconfig/network
|