zoukankan      html  css  js  c++  java
  • CentOS 6.3 桥接上网

          昨天纠结了一个晚上,终于搞定了,可以上网了。桥接上网注意以下几点:

    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/CentOS
    
    if [ ! -f /etc/redhat-release ]; then
        echo "Just support RedHat/CentOS distribution now."
        exit 1
    fi
    
    # arch must be x86_64
    if [ $(arch) != "x86_64" ]; then
        echo "Your arch is $(arch), but I need x86_64 !"
        exit 1
    fi
    
    # Need root
    
    if [ $UID -ne 0 ]; then
        echo "Need root to run install"
        exit 1
    fi
    
    
    LUOYUNTOP=/opt/LuoYun/
    TOPDIR=${PWD}
    
    DISTRIBUTION=
    
    unalias cp > /dev/null 2>&1
    
    # RPM_LIST
    RPM_LIST="qemu-kvm bridge-utils libvirt"
    # prepare requires
    function 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 <<EOF
    DEVICE="br0"
    ONBOOT=yes
    TYPE=Bridge
    BOOTPROTO=none
    IPADDR=$ip
    NETMASK=$netmask
    GATEWAY=$route
    DELAY=0
    EOF
    
        cat > $NIC_FILE <<EOF
    DEVICE=$nic
    ONBOOT=yes
    BRIDGE=br0
    EOF
    
        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 5
    if cat /etc/redhat-release | grep 5 > /dev/null 2>&1; then
        DISTRIBUTION="RHEL5"
        install_rhel5
        exit 0
    fi
    
    
    # For 6
    if cat /etc/redhat-release | grep 6 > /dev/null 2>&1; then
        DISTRIBUTION="RHEL6"
        install_rhel6
        exit 0
    fi
    
    
    # Could not come here
    echo "Just support redhat/centos 5 or 6 series"
    exit 2
    
  • 相关阅读:
    Android pm命令用法
    SSH没有password安全日志
    使用reserve要再次避免不必要的分配
    找到最大的迭代次数串
    个人存储不同类型的对象有一些想法的碰撞检测
    [Android 4.4.3] 泛泰A870 Mokee4.4.3 20140610 RC2.0 通过刷第三版 by syhost
    zoj 3823 Excavator Contest(结构体)
    【Linux】CentOS系统
    Swift学习——Swift解释特定的基础(七)
    Android JNI开发提高篇
  • 原文地址:https://www.cnblogs.com/dlutxm/p/2785401.html
Copyright © 2011-2022 走看看