vconfig - Linux 下的 802.1q 实现配置工具

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 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
 
 
 
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值