Linux下可以设置网卡模式

模式0:负载均衡

模式1:主备模式,不提高网络带宽

模式3:多网卡同时发送相同的数据

准备实验环境:

  Redhat 6.4 企业版64位,最小化安装。

给虚拟机添加网卡

此时我虚拟机有2块网卡,但是真正启用工作的只有一块,使用ifconfig也只能看到一块网卡。ifconfig -a可以看到我们加入的另一块网卡,此时这块网卡还没有启用。

[root@51cto network-scripts]# ifconfig -a
eth0 Link encap:Ethernet HWaddr :0C:::AA:8B
inet addr:192.168.80.222 Bcast:192.168.80.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe82:aa8b/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (10.8 KiB) TX bytes: (11.8 KiB) eth1 Link encap:Ethernet HWaddr :0C:::AA:
BROADCAST MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 b) TX bytes: (0.0 b) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 b) TX bytes: (0.0 b)

可见原来的那块网卡IP没变,新加的网卡没有IP。现在将两块网卡绑定成一块网卡,并设置新地址为192.168.80.240。这就要求这两个网卡各自不设置地址,绑定后设置公共地址。

具体流程如下:

①创建绑定网卡的配置文件

[root@51cto network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
[root@51cto network-scripts]# cat ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.80.240
PREFIX=
GATEWAY=192.168.80.1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
BONDING_OPTS="mode=0 miimon=50"
miimon= — Specifies (in milliseconds) how often MII link monitoring occurs. This is useful if high availability is required because MII is used to verify that the NIC is active. To verify that the driver for a particular NIC supports the MII tool, type the following command as root:
ethtool <interface-name> | grep "Link detected:"
In this command, replace <interface-name> with the name of the device interface, such as eth0, not the bond interface. If MII is supported, the command returns:
Link detected: yes
If using a bonded interface for high availability, the module for each NIC must support MII.
Setting the value to 0 (the default), turns this feature off. When configuring this setting, a good starting point for this parameter is 100.
更多参考:Link monitoring
网卡配置文件各个字段含义参考:Interface Configuration
②更改网卡配置文件
[root@51cto network-scripts]# cat ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@51cto network-scripts]# cat ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

③添加驱动支持

[root@51cto modprobe.d]# pwd
/etc/modprobe.d
[root@51cto modprobe.d]# ls
anaconda.conf blacklist.conf dist-alsa.conf dist.conf dist-oss.conf openfwwf.conf
[root@51cto modprobe.d]# vi /etc/modprobe.d/bonding.conf
[root@51cto modprobe.d]# cat bonding.conf
alias bond0 bonding

④重启网络服务

在xshell中测试,192.168.80.222这个绑定前的IP不通了,绑定后的公共IP通

[c:\~]$ ping 192.168.80.222

正在 Ping 192.168.80.222 具有  字节的数据:
请求超时。 192.168.80.222 的 Ping 统计信息:
数据包: 已发送 = ,已接收 = ,丢失 = (% 丢失),
^C
[c:\~]$ ping 192.168.80.240 正在 Ping 192.168.80.240 具有 字节的数据:
来自 192.168.80.240 的回复: 字节= 时间<1ms TTL=
来自 192.168.80.240 的回复: 字节= 时间<1ms TTL= 192.168.80.240 的 Ping 统计信息:
数据包: 已发送 = ,已接收 = ,丢失 = (% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms

查看绑定的配置,显示网卡工作模式为负载均衡

[root@51cto ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 50
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:82:aa:8b
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:82:aa:95
Slave queue ID: 0

验证网卡工作状态是否是负载均衡

物理机上保持ping 192.168.80.240,在虚拟机系统里面每隔几秒钟执行ifconfig查看发送接收数据包变化。

但是这种验证方法太笨

借助watch命令,可以设置间隔多少时间执行一次ifconfig

watch -n  ifconfig

上面验证的是负载均衡模式,如果是主备模式至于需要在ifcfg-bond0配置文件里面吧模式改为0即可

如果需要拔掉虚拟机的网卡,如下设置

Linux高级网络设置——将多个网卡设置成一个网卡的更多相关文章

  1. Linux高级网络设置——给网卡绑定多个IP

    假设这样一种场景: 某运营商的Linux服务器上装配了2家互联网公司的Web服务,每个Web服务分配了一个公网IP地址.但是运营商的Linux服务器只有一块网卡.这就需要在一块网卡上绑定多个IP地址. ...

  2. Linux 高级网络编程

    设置套接字函数: #include<sys/socket.h> int setsockopt(int sockfd, int level, int optname, const void* ...

  3. ubuntu 使用ifupdown 进行高级网络设置

    ifupdown ubuntu 本身支持linux的网络底层设置命令:ifconfig,route,ip 等命令,但为了让网络设置更加简单,Debian 提供了一个标准的高级网络设置工具,包含 ifu ...

  4. Linux CentOS6.x ip设置(网卡设置)

    修改IP永久生效按以下方法vi /etc/sysconfig/network-scripts/ifcfg-eth0(eth0,第一块网卡,如果是第二块则为eth1)按如下修改ip: DEVICE=et ...

  5. CentOS/Linux 网卡设置 IP地址配置

    CentOS/Linux下设置IP地址 1:临时修改:1.1:修改IP地址# ifconfig eth0 192.168.100.100 1.2:修改网关地址# route add default g ...

  6. 【整理】Virtualbox中的网络类型(NAT,桥接等),网卡,IP地址等方面的设置

    之前是把相关的内容,放到: [已解决]实现VirtualBox中的(Guest OS)Mac和主机(Host OS)Win7之间的文件和文件夹共享 中的,现在把关于网络配置方面内容,单独提取出来,专门 ...

  7. Linux下双物理网卡设置成虚拟网卡

    为了提供网络的高可用我们须要将多块网卡绑定设置成一块虚拟的网卡对外提供服务,这样能够防止一块网卡损坏或者防止网线连接故障造成的连接中断. 以下我们使用eth0与eth1来虚拟成为bond0为例:--- ...

  8. linux虚拟机网络设置(本机使用wiff,自己的网)

      一.linux虚拟机网络设置(https://jingyan.baidu.com/album/4e5b3e1957979d91901e24f1.html?picindex=16) 选中虚拟机,点击 ...

  9. LInux:网络连接的设置

    主机名的配置 主机名的配置(配置文件/etc/hostname) 1.使用 hostname 命令临时设置主机名 命令格式:hostname [新主机名] 2.永久设置主机名 命令格式:hostnam ...

随机推荐

  1. SecureCRT 8.1破解方式

    百度网盘下载,里面有破解程序和破解方式. 链接: https://pan.baidu.com/s/1wlhqnn-TE_mcOXOLljP-zg 密码: 3ffj

  2. SQL Server中的加密

    参考文献: 细说SQL Server中的加密 Transparent Data Encryption (TDE) Database Encryption Key (DEK) management SQ ...

  3. Navicat安装及使用

    一.安装Navicat 1.下载安装文件:navicat11.0.17_premium_cs_x86.exe(32位) 2.Oracle 的 Instance Client:instantclient ...

  4. 【MM系列】SAP 采购订单收货后不能修改价格的增强

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 采购订单收货后不能修改价格的 ...

  5. vue项目中导出Excel文件功能的前端代码实现

    在项目中遇到了两种不同情况, 1.get请求导出文件,实现起来相对简单 // 导出数据 exportData() { window.location.href = `/oes-content-mana ...

  6. Spring 多对对实体

    package com.wangshenghua.entity; import java.io.Serializable; import java.util.Set; import javax.per ...

  7. HDMI/DVI 显示器热插拔与检测原理(HPD)

    HDMI(19Pin)/DVI(16 pin)的功能是热插拔检测(HPD),这个信号将作为主机系统是否对HDMI/DVI是否发送TMDS信号的依据.HPD是从显示器输出送往计算机主机的一个检测信号.热 ...

  8. IOS IAP APP内支付 Java服务端代码

    IOS IAP APP内支付 Java服务端代码   场景:作为后台需要为app提供服务,在ios中,app内进行支付购买时需要进行二次验证. 基础:可以参考上一篇转载的博文In-App Purcha ...

  9. Linux_Ubantu下编译c++文件

    1. 编译单个文件 利用cmake进行编译 首先在项目文件夹中创建.cpp文件  利用最简单的 hello world #include<iostream> using namespace ...

  10. WEBservice的浏览器及元素的常用函数及变量整理总结 (selenium )

    由于网页自动化要操作浏览器以及浏览器页面元素,这里笔者就将浏览器及页面元素常用的函数及变量整理总结一下,以供读者在编写网页自动化测试时查阅. from selenium import webdrive ...