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. 【长期更新】Python使用随想笔记

    Q1:python函数传参是传值还是传引用? A:Python参数传递采用的肯定是"传对象引用"的方式.这种方式相当于传值和传引用的一种综合.python不允许程序员选择采用传值还 ...

  2. 【VS开发】【数据库开发】libevent简单入门和介绍

    libevent是一个基于事件触发的网络库,memcached底层也是使用libevent库,今天学习下. 总体来说,libevent有下面一些特点和优势: * 统一数据源, 统一I/O事件,信号和定 ...

  3. 1、5 写注册的后台并写前台html&密码加密&id 随机

    1 public void save(Student student) { // TODO Auto-generated method stub student.setSid(UUID.randomU ...

  4. Linux系统目录的学习

    1.在公司中linux 都是没有界面 2.系统路径    2.1 /表示根目录    2.2 ~表示/root    2.3etc:存放系统配置文件    2.4 home  除了root 以外所有用 ...

  5. jquery入口函数的测试

    /*编写一个自定义的jquery框架*/ (function (window,undefined) { var njquery=function (selector ,) { return new j ...

  6. Power BI学习

    常见用途: 1.连接数据 2.转换和清洗该数据,以创建数据模型 3.创建视觉对象,如提供数据的可视化表示形式的图表或图形 4.在一个或者多个报表页上创建作为视觉对象集合的报表 5.使用Power BI ...

  7. Java中自增(++)和赋值(=)运算效率比较

    前言   将一个int型数组x[]从初值0变成1.有两种做法: // 只考虑后自增 int length = x.length; for (int i = 0; i < length; i++) ...

  8. springboot 集成fastDfs

    pom.xml 引入依赖 <dependency> <groupId>com.github.tobato</groupId> <artifactId>f ...

  9. HTTP抓包

    1 概述 wireshark:全平台抓包工具,需要图形化界面,十分强大: httpry:http抓包插件,功能一般,操作简单: tcpdump:强大的抓包插件,支持多种网络协议. 2 httpry ( ...

  10. 【Transact-SQL】让人快遗忘的游标

    原文:[Transact-SQL]让人快遗忘的游标 最初学SQL Server的时候,当学到游标的时候,突然有了一种亲切感,因为这种通过一个while循环,一条一条的处理数据的方式,很像学过的过程式语 ...