CentOS 6.3 橋接上網

來源:互聯網
上載者:User

      昨天糾結了一個晚上,終於搞定了,可以上網了。橋接上網注意以下幾點:

1、橋接成功之後,br0 有IP,然後eth0 沒有IP,正常上網就可以了

2、確保  cat /proc/sys/net/ipv4/ip_forward 這個的值是1。 如果發現不是1的話,可以執行命令echo “1”> /proc/sys/net/ipv4/ip_forward 即可

3、執行brctl show命令後,要有br0 並且後面有eth0的資訊

 

我的設定檔(根據你們自己的網路資訊修改):

ifcfg-eth0:

DEVICE=eth0
ONBOOT=yes
BRIDGE=br0

ifcfg-br0:

DEVICE="br0"
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=none
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DELAY=0
DNS1=202.118.66.6 (我一開始沒寫這個上不了網,注意哦)
ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0

 

配置完成之後重啟網路即可: /etc/init.d/network restart

我這有個大牛給了我一個指令碼,直接執行這個install.sh 檔案即可,太牛了~~

#!/bin/sh# Just For RedHat/CentOSif [ ! -f /etc/redhat-release ]; then    echo "Just support RedHat/CentOS distribution now."    exit 1fi# arch must be x86_64if [ $(arch) != "x86_64" ]; then    echo "Your arch is $(arch), but I need x86_64 !"    exit 1fi# Need rootif [ $UID -ne 0 ]; then    echo "Need root to run install"    exit 1fiLUOYUNTOP=/opt/LuoYun/TOPDIR=${PWD}DISTRIBUTION=unalias cp > /dev/null 2>&1# RPM_LISTRPM_LIST="qemu-kvm bridge-utils libvirt"# prepare requiresfunction prepare_env(){    NOT_EXIST_RPMS=""    for RPM in $RPM_LIST; do        if ! rpm -q ${RPM} > /dev/null 2>&1; then            echo "  => ${RPM} not found"            NOT_EXIST_RPMS="${NOT_EXIST_RPMS} ${RPM}"        fi    done    # try install    if [ -n "$NOT_EXIST_RPMS" ]; then        if ! yum install $NOT_EXIST_RPMS; then            exit 1        fi    fi}function load_kvm(){    INTEL_KVM="kvm-intel"    AMD_KVM="kvm-amd"    if grep vmx /proc/cpuinfo  > /dev/null 2>&1; then        modprobe kvm $INTEL_KVM    else        modprobe kvm $AMD_KVM    fi}function setup_br0(){    echo "Setup br0 NIC"    if ifconfig br0 > /dev/null 2>&1; then        echo "  => br0 is already working !"        return    fi    for nic in $(ifconfig -a | grep ^[a-z] | awk '{print $1}'); do        ip=$(ifconfig $nic | grep Mask | awk -F: '{print $2}' | awk '{print $1}')        if [ -n "$ip" ]; then            netmask=$(ifconfig $nic | grep Mask | awk -F: '{print $4}' | awk '{print $1}')            break        fi    done    if [ -z "$ip" ]; then        echo "  => not found you ip address. please setup your bridge network manually."        return    else        echo "  => found your ip: $ip"    fi    route=$(route -n | grep UG | awk '{print $2}')    BR_FILE="/etc/sysconfig/network-scripts/ifcfg-br0"    NIC_FILE="/etc/sysconfig/network-scripts/ifcfg-$nic"    cp ${BR_FILE}{,.bak} > /dev/null 2>&1    cp ${NIC_FILE}{,.bak} > /dev/null 2>&1    cat > $BR_FILE <<EOFDEVICE="br0"ONBOOT=yesTYPE=BridgeBOOTPROTO=noneIPADDR=$ipNETMASK=$netmaskGATEWAY=$routeDELAY=0EOF    cat > $NIC_FILE <<EOFDEVICE=$nicONBOOT=yesBRIDGE=br0EOF    service network restart }function install_lynode(){    echo "Install lynode"    if [[ "X$DISTRIBUTION" != "XRHEL5" && "X$DISTRIBUTION" != "XRHEL6" ]]; then        echo "  => unsupported distribution: $DISTRIBUTION !"        exit 1    fi    mkdir -pv ${LUOYUNTOP}/platform/bin/ \        ${LUOYUNTOP}/platform/node_data/{appliances,instances} \        ${LUOYUNTOP}/platform/etc/luoyun-cloud/ \        ${LUOYUNTOP}/logs            NODEDIR="${TOPDIR}/lynode/${DISTRIBUTION}"    cp ${NODEDIR}/etc/init.d/lynoded /etc/init.d/    cp ${NODEDIR}/opt/LuoYun/platform/etc/luoyun-cloud/lynode.conf ${LUOYUNTOP}/platform/etc/luoyun-cloud/    cp ${NODEDIR}/opt/LuoYun/platform/bin/lynode ${LUOYUNTOP}/platform/bin/    chkconfig --add lynoded    chkconfig --level 2345 lynoded on}function common_install(){    prepare_env    load_kvm    #install_lynode    setup_br0}function install_rhel5(){    echo "Install LuoYun web console on redhat 5 series"    common_install}function install_rhel6(){    echo "Install LuoYun web console on redhat 6 series"    common_install}# For 5if cat /etc/redhat-release | grep 5 > /dev/null 2>&1; then    DISTRIBUTION="RHEL5"    install_rhel5    exit 0fi# For 6if cat /etc/redhat-release | grep 6 > /dev/null 2>&1; then    DISTRIBUTION="RHEL6"    install_rhel6    exit 0fi# Could not come hereecho "Just support redhat/centos 5 or 6 series"exit 2

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.