ubuntu下配置vlan功能--官网vlan how to

31 篇文章 0 订阅
26 篇文章 0 订阅

http://ubuntuforums.org/showthread.php?t=703387

ubuntu官网介绍

  1. 802.1q VLAN HOWTO

    Doing 802.1q trunking to an Ethernet switch is really easy. I describe two methods - a text only one for servers, and a GUI one for desktops.

    The VLAN number that an interface uses always gets appended to the physical interface after a dot, so for instance an interface eth0 using VLAN number 99 would be called eth0.99. The instructions below all assume you want to connect to vlan 99 - change the number as required.

    Server console method
    Install the  vlan package:
    Code:
    sudo apt-get install vlan
    Load the 8021q kernel module:
    Code:
    sudo modprobe 8021q
    Ensure that this module gets loaded after a reboot by adding to /etc/modules:
    Code:
    sudo  sh -c 'grep -q 8021q /etc/modules || echo 8021q >> /etc/modules'
    Configure the interface by editing /etc/network/interfaces:
    Code:
    sudo nano /etc/network/interfaces
    and adding a stanza like this:
    Code:
    auto eth0.99
    iface eth0.99 inet static
    address 192.168.99.1
    netmask 255.255.255.0
    Then bring the interface up:
    Code:
    sudo ifup eth0.99
    Desktop GUI method
    Install the  vlan package using Synaptic: System->Administration->Synaptic Package Manager
    and search for and install the package 8021q.

    The next bit has to be done from the command line.
    Load the 8021q kernel module:
    Code:
    sudo modprobe 8021q
    Ensure that this module gets loaded after a reboot by adding to /etc/modules:
    Code:
    sudo  sh -c 'grep -q 8021q /etc/modules || echo 8021q >> /etc/modules'
    Now we have to create a low-level interface that the network manager can see:
    Code:
    vconfig add eth0 99
    Now we can find eth0.99 in the GUI System->Administration0>Network and configure it how we want.
    Advanced replyAdv Reply  
  2. #2
    sador42 is offline First Cup of Ubuntu
    Join Date
    Feb 2009
    Beans
    1

    Re: 802.1q VLAN HOWTO

    Using the above method, which is the best way to add a PERMANENT route add statement so I can route some traffic over one VLAN and some over another?
    Advanced replyAdv Reply  
  3. #3
    tmeller is offline First Cup of Ubuntu
    Join Date
    Feb 2008
    Beans
    2

    Re: 802.1q VLAN HOWTO

    recently, we needed to configure channel bonding on vlans.
    the internet did not supply us with infos, so we did it as a best-effort.

    This is a howto for debian etch, but should also work on ubuntu 7.x+:

    goal: several vlan-interfaces on top of a bonding trunk

    first step: create the bonding config

    - in /etc/network/interfaces:
    Code:
     #auto bond0
    iface bond0 inet manual
    	pre-up ip link set bond0 up
    	up ifenslave bond0 eth0
    	up ifenslave bond0 eth1
    	post-down ifenslave -d bond0 eth0 eth1
    	post-down modprobe  -r bond0
    second step: define the logical network link (repeat as to your needs)

    - in /etc/network/interfaces:

    Code:
     auto bond0.911
     allow-hotplug bond0.911
     iface bond0.911 inet static
    	address 10.20.50.18
    	netmask 255.255.255.192
    	network 10.20.50.0
    	broadcast 10.20.50.63
    	gateway 10.20.50.2
    	pre-up /etc/network/bondingstate UP bond0 911
    	post-down /etc/network/bondingstate DOWN bond0 911
    third step: glue them together

    - in /etc/network/bondingstate:
    Code:
    # Script /etc/network/bondingstate
    # wird aufgerufen aus /etc/network/interfaces
    # 04.09.2007, no copyright
    #
     
    # Variablen setzen
    
    set -x
    CHANGE_STATE=$1
    TRUNK=$2
    VLANID=$3
    
    case $CHANGE_STATE in
      UP)
        #egrep "$TRUNK" /etc/network/run/ifstate >/dev/null 2>&1
        if [ ! -f /proc/net/bonding/$TRUNK ] ; then
          ifup $TRUNK
          if [ $? -ne 0 ] ; then
            exit 1
          fi
        fi
        vconfig add $TRUNK $VLANID
        ;;
    
      DOWN)
        vconfig rem $TRUNK.$VLANID
        egrep "$TRUNK\.[0-9]+" /etc/network/run/ifstate >/dev/null 2>&1
        if [ $? -ne 0 ] ; then
          if [ -z "$VLANID" ] ; then
            exit 0
          else
            ifdown $TRUNK
          fi
        fi
        ;;
    esac
    What happens:

    'auto bond0.911' starts setting up the interface.
    'pre-up' calls bondingstate
    bondingstate tests whether the bonding module is loaded,
    then starts bonding, if need be.
    'iface bond0' enslaves the physical NICs, then returns success
    bondingstate adds the given vlan ID and returns success
    'auto bond0.911' configures IP-addresses and returns success

    Configuring additional links is but a copy of 'bond0.911'

    On shutdown, 'post-down /etc/network/bondingstate DOWN bond0 911'
    calls bondingstate, which in turn checks in /etc/network/run/ifstate
    whether this is the last vlan interface and if so, shuts down bond0
    bond0's post-down then will remove the kernel module

    There might be routing issues. Beware of the order in /etc/network/interfaces.

    Hope this might be helpful for anyone, anytime

    Have fun,
    your swiss telekom hackers
    best before end: 09/2007
    Last edited by tmeller; May 5th, 2009 at  02:44 PM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值