Linux双网卡绑定实现
生活随笔
收集整理的這篇文章主要介紹了
Linux双网卡绑定实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
概述: 通過網卡綁定,處理網卡單點故障,實驗的操作系統是Redhat Linux Enterprise 5.3. 綁定的前提條件:芯片組型號相同,而且網卡應該具備自己獨立的BIOS芯片。 網卡綁定時有四種模式,其中常用的是模式0和模式1: 模式0(輪循模式):負載均衡工作模式,他能提供兩倍的帶寬 ,這種情況下出現一塊網卡失效,僅僅會是服務器出口帶寬下降,也不會影響網絡使用. 模式1(主備模式):當一個網絡接口失效時(例如主交換機掉電等),不會出現網絡中斷,系統會按照cat /etc/rc.local里指定網卡的順序工作,機器仍能對外服務,起到了失效保護的功能 案例: 模式1 1.?modprobe bonding?//調用模塊bonding modinfo bonding??? //查看內核中加載的模塊相關參數 內容: filename:?/lib/modules/2.6.25.19/kernel/drivers/net/bonding/bonding.ko ? 2.編輯虛擬網絡接口配置文件,指定網卡IP 注意:不要指定單個網卡的IP 地址、子網掩碼或網卡 ID。將上述信息指定到虛擬適配器(bonding)中即可。 cd /etc/sysconfig/network-scripts/ vim ifcfg-eth0 //模塊別名 內容: DEVICE=eth0?//設備 ? BOOTPROTO=dhcp?//自動獲取地址 ? ONBOOT=yes???//啟動激活 ? vim ifcfg-eth1 內容: DEVICE=eth1? BOOTPROTO=dhcp? ONBOOT=yes? cp ifcfg-eth0 ifcfg-bond0 vim ifcfg-bond0 //編輯額外的網卡 內容: DEVICE=bond0? BOOTPROTO=none? IPADDR=192.168.2.101 ? NETMASK=255.255.255.0 ? ONBOOT=yes? 3.vim /etc/modprobe.conf?//編輯模塊配置文件,以使系統在啟動時加載bonding模塊,對外虛擬網絡接口設備為 bond0 內容加入二行: alias?bond0?bonding???//內核模塊 ? options?bond0??miimon=100?//鏈路監測?mode=1?//工作模式 ? 4.vim /etc/rc.local 內容加入一行: ifenslave?bond0?eth0?eth1 ? 配置完畢,重新啟動電腦? 1.Xshell:\> ping 192.168.2.101 Pinging?192.168.2.101?with?32?bytes?of?data: ? ? ? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? ? ? Ping?statistics?for?192.168.2.101: ? ????Packets:?Sent?=?4,?Received?=?4,?Lost?=?0?(0%?loss), ? Approximate?round?trip?times?in?milli-seconds: ? ????Minimum?=?0ms,?Maximum?=?0ms,?Average?=?0ms? 2.ifconfig? //查看網卡信息 bond0?????Link?encap:Ethernet?HWaddr?00:0C:29:9E:49:28? ? ??????????inet?addr:192.168.2.101?Bcast:192.168.2.255?Mask:25 ? 5.255.255.0 ? ??????????inet6?addr:?fe80::20c:29ff:fe9e:4928/64?Scope:Link ? ??????????UP?BROADCAST?RUNNING?MASTER?MULTICAST?MTU:1500?Metric:1 ? ??????????RX?packets:87?errors:0?dropped:0?overruns:0?frame:0 ? ??????????TX?packets:122?errors:0?dropped:0?overruns:0?carrier:0 ? ??????????collisions:0?txqueuelen:0? ? ??????????RX?bytes:13696?(13.3?KiB)?TX?bytes:24910?(24.3?KiB) ? ? ? eth0??????Link?encap:Ethernet?HWaddr?00:0C:29:9E:49:28? ? ??????????UP?BROADCAST?RUNNING?SLAVE?MULTICAST?MTU:1500?Metric:1 ? ??????????RX?packets:73?errors:0?dropped:0?overruns:0?frame:0 ? ??????????TX?packets:98?errors:0?dropped:0?overruns:0?carrier:0 ? ??????????collisions:0?txqueuelen:1000? ? ??????????RX?bytes:10395?(10.1?KiB)?TX?bytes:19299?(18.8?KiB) ? ??????????Interrupt:19?Base?address:0x2000? ? ? ? eth1??????Link?encap:Ethernet?HWaddr?00:0C:29:9E:49:28? ? ??????????UP?BROADCAST?RUNNING?SLAVE?MULTICAST?MTU:1500?Metric:1 ? ??????????RX?packets:14?errors:0?dropped:0?overruns:0?frame:0 ? ??????????TX?packets:24?errors:0?dropped:0?overruns:0?carrier:0 ? ??????????collisions:0?txqueuelen:1000 ? ??????????RX?bytes:3301?(3.2?KiB)?TX?bytes:5611?(5.4?KiB) ? 3.cat /proc/net/bonding/bond0?//查看內核信息 Bonding?Mode:?fault-tolerance?(active-backup) ? Primary?Slave:?None ? Currently?Active?Slave:?eth0 ? MII?Status:?up ? MII?Polling?Interval?(ms):?100 ? Up?Delay?(ms):?0 ? Down?Delay?(ms):?0 ? ? ? Slave?Interface:?eth0 ? MII?Status:?up ? Link?Failure?Count:?0 ? Permanent?HW?addr:?00:0c:29:9e:49:28 ? ? ? Slave?Interface:?eth1 ? MII?Status:?up ? Link?Failure?Count:?0 ? Permanent?HW?addr:?00:0c:29:9e:49:32 ? 斷開網卡eth0后: 1.Xshell:\> ping 192.168.2.101 -t Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Request?timed?out. ? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? 2.cat /proc/net/bonding/bond0? Bonding?Mode:?fault-tolerance?(active-backup) ? Primary?Slave:?None ? Currently?Active?Slave:?eth1 ? MII?Status:?up ? MII?Polling?Interval?(ms):?100 ? Up?Delay?(ms):?0 ? Down?Delay?(ms):?0 ? ? ? Slave?Interface:?eth0 ? MII?Status:?down ? Link?Failure?Count:?1 ? Permanent?HW?addr:?00:0c:29:9e:49:28 ? ? ? Slave?Interface:?eth1 ? MII?Status:?up ? Link?Failure?Count:?0 ? Permanent?HW?addr:?00:0c:29:9e:49:32 ? 斷開網卡eth1后: Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64?Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64?Request?timed?out. ?Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64?Reply?from?192.168.2.101:?bytes=32?time<1ms?TTL=64? 模式0 注意:只需修改模塊配置文件就可以,其它配置與模式1一樣 1.vim /etc/modprobe.conf?//編輯模塊配置文件 文件內容修改一行: options?bond0?miimon=100?mode=0? 配置完畢,重新啟動電腦? 斷開網卡eth0后: Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Request timed out. Request timed out. Request timed out. 斷開網卡eth1后: Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Request timed out. Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
轉載于:https://blog.51cto.com/yz406/962510
總結
以上是生活随笔為你收集整理的Linux双网卡绑定实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android开发(13) 尝试在流布局
- 下一篇: 五十岁的女人梦到自己怀孕是什么意思