歡迎您光臨本站 註冊首頁

xen3.4.0中設置vlan的問題

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

xen3.4.0中設置vlan的問題

我在Domain0中設置了vlan,起了兩個domain U連到這個vlan上, 現在兩個domain u 之間能夠Ping通,但domain u ping 不通domain 0也ping 不通外網,請問是我的設置有問題么,麻煩知道了大蝦告知一二,多謝,下面是我的配置:

/etc/xen/scripts/network-multi-vlan
#!/bin/sh
#============================================================================
# Xen vlan bridge start/stop script.
# Xend calls a network script when it starts.
# The script name to use is defined in /etc/xen/xend-config.sxp
# in the network-script field.
#
# This script creates multiple bridges to segregate individual domUs to
# separate VLANs. Customize to fit your needs.
#
# Usage:
#
# network-multi-vlan (start|stop|status)
#
#============================================================================

dir=$(dirname "$0")

##
# To make the tagged interface available to some DomUs, create the default
# bridge. Comment this out to only make vlan-based bridges available.
"$dir/network-bridge" "$@" vifnum=0

##
# Once all normal bridges are active, create any vlan-based briges.
"$dir/network-bridge-vlan" "$@" vlan=2
"$dir/network-bridge-vlan" "$@" vlan=3
"$dir/network-bridge-vlan" "$@" vlan=50

/etc/xen/scripts/network-bridge-vlan
#!/bin/sh
#============================================================================
# Xen vlan bridge start/stop script.
# Xend calls a network script when it starts.
# The script name to use is defined in /etc/xen/xend-config.sxp
# in the network-script field.
#
# This script creates a bridge (default vlanbr${vlan}), creates a device
# (default eth0.${vlan}), and adds it to the bridge. This scrip assumes
# the Dom0 does not have an active interface on the selected vlan; if
# it does the network-bridge script should be used instead.
#
# To use this script, vconfig must be installed.
#
# Usage:
#
# network-bridge-vlan (start|stop|status) {VAR=VAL}*
#
# Vars:
#
# vlan       The vlan to bridge (default 2)
# bridge     The bridge to use (default vlanbr${vlan}).
# netdev     The interface to add to the bridge (default eth0}).
#
# Internal Vars:
# vlandev="${netdev}.${vlan}"
#
# start:
# Creates the bridge
# Adds vlandev to netdev
# Enslaves vlandev to bridge
#
# stop:
# Removes vlandev from the bridge
# Removes vlandev from netdev
# Deletes bridge
#
# status:
# Print vlan, bridge
#
#============================================================================


dir=$(dirname "$0")
. "$dir/xen-script-common.sh"

findCommand "$@"
evalVariables "$@"

vlan=${vlan:-2}
bridge=${bridge:-vlanbr${vlan}}
netdev=${netdev:-eth0}

vlandev="${netdev}.${vlan}"

##
# link_exists interface
#
# Returns 0 if the interface named exists (whether up or down), 1 otherwise.
#
link_exists()
{
    if ip link show "$1" >/dev/null 2>/dev/null
    then
        return 0
    else
        return 1
    fi
}


# Usage: create_bridge bridge
create_bridge () {
    local bridge=$1

    # Don't create the bridge if it already exists.
    if ! brctl show | grep -q ${bridge} ; then
        brctl addbr ${bridge}
        brctl stp ${bridge} off
        brctl setfd ${bridge} 0
    fi
    ip link set ${bridge} up
}

# Usage: add_to_bridge bridge dev
add_to_bridge () {
    local bridge=$1
    local dev=$2
    # Don't add $dev to $bridge if it's already on a bridge.
    if ! brctl show | grep -q ${dev} ; then
        brctl addif ${bridge} ${dev}
    fi
}

# Usage: show_status vlandev bridge
# Print vlan and bridge
show_status () {
    local vlandev=$1
    local bridge=$2
   
    echo '============================================================'
    cat /proc/net/vlan/${vlandev}
    echo ' '
    brctl show ${bridge}
    echo '============================================================'
}

op_start () {
    if [ "${bridge}" = "null" ] ; then
        return
    fi

    if ! link_exists "$netdev"; then
        return
    fi

    if link_exists "$vlandev"; then
        # The device is already up.
        return
    fi

    create_bridge ${bridge}

    ip link set ${netdev} up

    vconfig set_name_type DEV_PLUS_VID_NO_PAD
    vconfig add ${netdev} ${vlan}
    ip link set ${vlandev} address fe:ff:ff:ff:ff:ff
    ip link set ${vlandev} up
    ip link set ${bridge} up

    add_to_bridge2 ${bridge} ${vlandev}
}

op_stop () {
    if [ "${bridge}" = "null" ]; then
        return
    fi
    if ! link_exists "$bridge"; then
        return
    fi

    if link_exists "$vlandev"; then
        ip link set ${vlandev} down

        brctl delif ${bridge} ${vlandev}
        ip link set ${bridge} down

        vconfig rem ${vlandev}
    fi
    brctl delbr ${bridge}
}

# adds $dev to $bridge but waits for $dev to be in running state first
add_to_bridge2() {
    local bridge=$1
    local dev=$2
    local maxtries=10

    echo -n "Waiting for ${dev} to negotiate link."
    for i in `seq ${maxtries}` ; do
        if ifconfig ${dev} | grep -q RUNNING ; then
            break
        else
            echo -n '.'
            sleep 1
        fi
    done

    if [ ${i} -eq ${maxtries} ] ; then echo '(link isnt in running state)' ; fi

    add_to_bridge ${bridge} ${dev}
}

case "$command" in
    start)
        op_start
        ;;
   
    stop)
        op_stop
        ;;

    status)
        show_status ${vlandev} ${bridge}
        ;;

    *)
        echo "Unknown command: $command" >&2
        echo 'Valid commands are: start, stop, status' >&2
        exit 1
esac

/etc/xen/xend-config.sxp
...
(network-script network-multi-vlan)
...

brctl show的結果:
bridge name     bridge id               STP enabled     interfaces
eth0            8000.0024e827d9ea       no              peth0
vlanbr2         8000.feffffffffff       no              eth0.2
                                                        vif2.0
                                                        vif3.0
vlanbr3         8000.feffffffffff       no              eth0.3
vlanbr50                8000.feffffffffff       no              eth0.50

其中兩個domain U就是連到了vlanbr2上面。
《解決方案》

eth0.2  eth0.3什麼意思?
是不是沒有將物理網卡接到vlan2上?
《解決方案》

回復 #2 attiseve 的帖子

eth0.2和eth0.3是在eth0上創建的兩個vlan。
比如你可以這樣:
vconfig add eth0 2
vconfig add eth0 3
這樣你就在eth0上創建了兩個vlan,它們的VID分別為2和3,對應的虛擬設備就是eth0.2和eth0.3。
《解決方案》

你的eth0.2  eth0.3配置IP地址了嗎?
把路由表貼一下
《解決方案》

我也遇到這樣類似的問題,你需要將你的虛擬機的網關設置為eth0.2或eth0.3的IP地址,這樣就可以ping同eth0或者外網了

[火星人 ] xen3.4.0中設置vlan的問題已經有594次圍觀

http://coctec.com/docs/service/show-post-5308.html