文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>vconfig - Linux 下的 802.1q 實現配置工具

vconfig - Linux 下的 802.1q 實現配置工具

时间:2010-08-24  来源:cocos_zhouhao

資料來源 http://windtear.net/archives/2005/07/18/000720.html


vconfig - Linux 下的 802.1q 實現配置工具
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 support
if [ -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
    fi
fi


vconfig 就是 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 CST
Install Date: Tue 01 Jun 2004 04:55:57 PM CST      Build Host: porky.devel.redhat.com
Group       : System Environment/Base       Source RPM: vconfig-1.6-2.src.rpm
Size        : 170822                           License: LGPL
Signature   : DSA/SHA1, Mon 24 Feb 2003 02:05:29 PM CST, Key ID 219180cddb42a60e
Packager    : Red Hat, Inc.
URL         : http://www.candelatech.com/~greear/vlan.html
Summary     : 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

% vconfig
Expecting argc to be 3-5, inclusive.  Was: 1

Usage: 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 11
vconfig add eth0 21

----->   設置參數 REORDER_HDR (默認就是)
vconfig set_flag eth0.11 1 1
vconfig set_flag eth0.21 1 1

----->   查看一下
cat /proc/net/vlan/eth0.11
cat /proc/net/vlan/eth0.21

----->   改接口啟動配置文件
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth0.11
perl -pi -e 's/DEVICE=eth0/DEVICE=eth0.11/g' ifcfg-eth0.11
cp ifcfg-eth0 ifcfg-eth0.21
perl -pi -e 's/DEVICE=eth0/DEVICE=eth0.21/g' ifcfg-eth0.21

perl -pi -e 's/IPADDR=/#IPADDR=/g' ifcfg-eth0
perl -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
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载