首页 技术 正文
技术 2022年11月10日
0 收藏 485 点赞 3,226 浏览 3500 个字

Linux下可以设置网卡模式

模式0:负载均衡

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

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

准备实验环境:

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

给虚拟机添加网卡

Linux高级网络设置——将多个网卡设置成一个网卡

Linux高级网络设置——将多个网卡设置成一个网卡

Linux高级网络设置——将多个网卡设置成一个网卡

此时我虚拟机有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: yesIf 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

④重启网络服务

Linux高级网络设置——将多个网卡设置成一个网卡

在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): 0Slave 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: 0Slave 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查看发送接收数据包变化。

Linux高级网络设置——将多个网卡设置成一个网卡

Linux高级网络设置——将多个网卡设置成一个网卡

但是这种验证方法太笨

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

watch -n  ifconfig

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

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

Linux高级网络设置——将多个网卡设置成一个网卡

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289