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. JEECG新建用户不用系统用户表的实现

    首先新增组织机构 和 角色: -- 新增 组织机构 INSERT INTO `t_s_depart` VALUES ('dept001', '你所在的机构', '你所在的机构的描述', null, ' ...

  2. iOS-代理设计模式delegate和protocol

    充当代理的步骤: 首先要明确谁请别人代理,谁当别人的代理 1> 请代理三部曲: 1 写一个协议protoc,把自己不方便做的事列出来(@protocol  studentDelegate < ...

  3. Docker 镜像小结---操作指令介绍(七)

    目录 一.搜索镜像 二.下载镜像 三.查看本地镜像 四.显示镜像构建历史 五.删除镜像 六.镜像创建 七.上传镜像 八.给镜像打 tag 九.存出和载入镜像 一.搜索镜像 很多情况下我们可能需要下载某 ...

  4. Flutter easyrefresh示例 上拉加载+下拉刷新

    官方示例,简单改了下,实现功能为主. 代码如下: import 'dart:async'; import 'package:flutter/material.dart'; import 'packag ...

  5. php 阿里云国内短信实例

    调用:先去阿里云申请短信服务 $smsArr = array( "accessKeyId" => "", // key "accessKeySe ...

  6. python线程互斥锁Lock(29)

    在前一篇文章 python线程创建和传参 中我们介绍了关于python线程的一些简单函数使用和线程的参数传递,使用多线程可以同时执行多个任务,提高开发效率,但是在实际开发中往往我们会碰到线程同步问题, ...

  7. C语言程序设计II—第十周教学

    第十周教学总结(29/4-5/5) 教学内容 本周的教学内容为:9.2 学生成绩排序 知识点:结构数组的定义.初始化和数组成员引用:9.3 修改学生成绩 知识点:结构指针指向操作,结构指针作为函数参数 ...

  8. LeetCode 15. 三数之和(3Sum)

    15. 三数之和 15. 3Sum 题目描述 Given an array nums of n integers, are there elements a, b, c in nums such th ...

  9. kubernetes 部署ingress

    kubernetes Ingess 是有2部分组成,Ingress Controller 和Ingress服务组成,常用的Ingress Controller 是ingress-nginx,工作的原理 ...

  10. Python基础系列讲解——时间模块详解大全之time模块

    Python中提供处理时间日期相关的内置模块有time.datetime和calendar. time模块中大多数函数调用了所在平台C library 的同名函数,因此更依赖于操作系统层面,所以tim ...