网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

linux绑定网卡命令,linux起网卡命令

linux5——网络命令

##Ctrl+D:在目录下敲击该命令,作用是退出当前用户。

公司主营业务:成都网站建设、成都网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联公司推出井冈山免费做网站回馈大家。

##Ctrl+D:在命令mail、write等命令中敲击该命令,作用是退出当前命令。

1.write

    语法:write 用户名

    功能:给用户发信息,以Ctrl+D保存结束; 即时通信

2.wall(write all)

语法:wall [message]

功能:发广播信息(给所有用户发信息); 回车键结束命令

3.ping

语法:ping [选项] IP地址

功能:测试网络连通性

-c 次数:指定发送次数

-s 字节:指定探测包的大小

4.ifconfig(interface configure)

语法:ifconfig(或者ifconfig 网卡地址 IP地址 )

功能:查看和设置网卡信息     

inet6: IPv6地址目前不生效

5.mail

语法:mail [用户名]

功能:查看或者发送电子邮件   ##输入邮件内容时,删除键为 ctrl+backspace

6.last

语法:last

功能:显示当前与过去登入系统的用户信息

7.lastlog

语法:lastlog

功能:显示所有用户最后登录时间

8.traceroute

语法:traceroute [目标主机]

功能:显示发出数据包的主机到目标主机之间的网关数量

 ## 星号*** 可能是防火墙封掉了ICMP的返回信息,所以得不到数据包返回数据

9.netstat

语法:netstat [选项]  

功能:显示网络相关信息

-a:列出所有网络状态,包括Socket程序

-c 秒数:指定每隔几秒刷新一次网络状态

-n:使用IP地址和端口号显示,不是用域名和服务名

-p:显示PID和程序名

-t:显示使用TCP协议端口的链接状况

-u:显示使用UDP协议端口的链接状况

-l:加显示监听状态的链接

-r:显示路由表

“tuln”选项:查看本机开启的端口,只能查看监听状态的链接。

1) Proto:网络连接的协议,一般就是 TCP 协议或者 UDP 协议。

2) Recv-Q:表示接收到的数据,已经在本地的缓冲中,但是还没有被进程取走。

3) Send-Q:表示从本机发送,对方还没有收到的数据,依然在本地的缓冲中,不具备 ACK 标志的数据包。

4) Local Address:本机的 IP 地址和端口号。

5) ForeignAddress:远程主机的 IP 地址和端口号。

6) State:状态。常见的状态主要有以下几种。

-LISTEN:监听状态,只有 TCP 协议需要监听,而 UDP 协议不需要监听。

-ESTABLISHED:已经建立连接的状态。如果使用"-I"选项,则看不到已经建立连接的状态。

-SYN_SENT:SYN 发起包,就是主动发起连接的数据包。

-SYN_RECV:接收到主动连接的数据包。

-FIN_WAIT1:正在中断的连接。

-FIN_WAIT2:已经中断的连接,但是正在等待对方主机进行确认。

-TIME_WAIT:连接已经中断,但是套接字依然在网络中等待结束。

-CLOSED:套接字没有被使用。

        最常用的是LISTEN和ESTABLISHED

10.numtui

语法:numtui

功能:配置网络——centos7独有的功能

11.mount

语法:mount [-t 文件系统] 设备文件名 挂载点

功能:挂载外接设备

Linux系统双网卡绑定配置教程

系统版本

[root@ ~]# cat /etc/redhat-release

CentOS release 6.8 (Final)

[root@ ~]# uname -r

2.6.32-642.6.1.el6.x86_64

网卡说明

eth0   192.168.1.8(服务器外网卡)

eth1   服务器网卡(内网)

eth2   服务器网卡(内网)

[root@ ~]# /etc/init.d/iptables stop

[root@ ~]#  chkconfig iptables off

关闭selinux

[root@ ~]#setenforce 0

[root@ ~]#sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config

禁用NetworkManager

[root@ ~]# /etc/init.d/NetworkManager stop

Stopping NetworkManager daemon:           [  OK  ]

[root@ ~]# chkconfig NetworkManager off

[root@ ~]# /etc/init.d/network restart

双网卡绑定配置过程

[root@ ~]# cd /etc/sysconfig/network-scripts/

编辑eth1网卡

[root@ network-scripts]# cat ifcfg-eth1 DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

USERCTL=no

MASTER=bind0

EOF

编辑eth2网卡

[root@ network-scripts]# cat ifcfg-eth2

ONBOOT=yes

BOOTPROTO=none

USERCTL=no

MASTER=bind0

EOF

编辑bind0网卡

[root@ network-scripts]# cat ifcfg-bind0 DEVICE=bind0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=none

IPADDR=10.0.0.8

NETMASK=255.255.255.0

GATEWAY=10.0.0.254

IPV6INIT=no

USERCTL=no

EOF

配置bond参数

[root@ network-scripts]# cat /etc/modprobe.conf alias bind0 bonding

options bind0 miimon=100 mode=6

EOF

加入开机自启动(/etc/rc.local)

[root@ network-scripts]# cat /etc/rc.local ifenslave bind0 eth1 eth2

EOF

重启网络服务

[root@LVS-2 network-scripts]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down interface eth1:                              [  OK  ]

Shutting down interface eth2:                              [  OK  ]

Shutting down loopback interface:                       [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface bind0:  WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.

WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.

Determining if ip address 10.0.0.8 is already in use for device bind0..[  OK  ]

Bringing up interface eth0:  Determining if ip address 192.168.1.8 is already in use for device eth0...                                                     [  OK  ]

Bringing up interface eth1:  RTNETLINK answers: File exists         [  OK  ]

Bringing up interface eth2:  RTNETLINK answers: File exists          [  OK  ]

配置使绑定立即生效

[root@LVS-2 network-scripts]# ifenslave bind0 eth1 eth2

测试联通

[root@LVS-2 network-scripts]# ping 10.0.0.8

PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.

64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.089 ms

64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.046 ms

^C

--- 10.0.0.8 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1921ms

rtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms

此时会发现系统多一个网卡

[root@LVS-2 network-scripts]# ifconfig bind0

bind0

Link encap:Ethernet  HWaddr 00:0C:29:CC:9B:5

inet addr:10.0.0.8  Bcast:10.0.0.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST  MTU:1500 Metric:1

RX packets:151 errors:0 dropped:0 overruns:0 frame:0

TX packets:3 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:11826 (11.5 KiB)  TX bytes:258 (258.0 b)

在linux(redhat)下双网卡负载均衡(lacp)

第一步:创建一个ifcfg-bondX

# touch /etc/sysconfig/network-scripts/ifcfg-bond0  新建一个bond0配置文件

#  cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=static IPADDR=1.1.1.2

NETMASK=255.255.255.0

BROADCAST=1.1.1.255

NETWORK=1.1.1.0

GATEWAY=1.1.1.1

ONBOOT=yes

TYPE=Ethernet

编辑ifcfg-bond0如上

第二步:修改/etc/sysconfig/network-scripts/ifcfg-ethX

这个实验中把网卡1和2绑定,修改/etc/sysconfig/network-scripts/ifcfg-ethX相应网卡配置如下:

#  cat  /etc/sysconfig/network-scripts/ifcfg-eth1

TYPE=Ethernet

DEVICE=eth1

HWADDR=00:d0:f8:40:f1:a0  网卡1mac

BOOTPROTO=none

ONBOOT=yes

USERCTL=no

MASTER=bond0

SLAVE=yes

#  cat  /etc/sysconfig/network-scripts/ifcfg-eth2

TYPE=Ethernet DEVICE=eth2

HWADDR=00:d0:f8:00:0c:0c  网卡2mac

BOOTPROTO=none

ONBOOT=yes

USERCTL=no

MASTER=bond0

SLAVE=yes

第三步:配置/etc/modprobe.conf,添加alias bond0 bonding

#  cat /etc/modprobe.conf alias eth0 e100

alias snd-card-0 snd-intel8x0

options snd-card-0 index=0 

options snd-intel8x0 index=0 

remove snd-intel8x0 { /usr/sbin/alsactl store 0 /dev/null 21 || : ; }; /sbin/modprobe -r --ignore-remove snd-intel8x0 alias eth1 8139too

options 3c501 irq=3 

alias eth2 tulip

上面是三网卡本身的配置如果要绑定和做lacp只要再加上下面两条配置

alias bond0 bonding                绑定

options bond0 miimon=100 mode=4    mode=4是lacp

第四步:配置/etc/rc.d/rc.local,添加需要绑定的网卡

# cat /etc/rc.d/rc.local 

touch /var/lock/subsys/local  配置本身就有这条命令

ifenslave bond0 eth1 eth2    这条命令是添加需要绑定的网卡1和2 

到这里就完成bonding的配置了可以查看一下

第五步:重启网络服务和重启pc

#service network restart    重启网络服务

# shutdown -r now                  重启pc

重启后可以查看bonding情况:网卡1和2 都绑定上了,模式为802.3ad

# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006) 

Bonding Mode: IEEE 802.3ad Dynamic link aggregation

Transmit Hash Policy: layer2 (0) MII Status: up

MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 

802.3ad info

LACP rate: slow

Active Aggregator Info:       

    Aggregator ID: 1       

    Number of ports: 2       

    Actor Key: 9       

    Partner Key: 1

    Partner Mac Address: 00:d0:f8:22:33:ba Slave Interface: eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:d0:f8:40:f1:a0

Aggregator ID: 1

Slave Interface: eth2

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:d0:f8:00:0c:0c

Aggregator ID: 1

接口配置信息:新增了bond0的配置信息,接口bond0和eth1,eth2,绑定后三个接口使用的mac都是同一个:00:D0:F8:40:F1:A0 # ifconfig

bond0    Link encap:Ethernet  HWaddr 00:D0:F8:40:F1:A0           

          inet addr:1.1.1.2  Bcast:1.1.1.255  Mask:255.255.255.0

          inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link

          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1         

          RX packets:128 errors:0 dropped:0 overruns:0 frame:0         

          TX packets:259 errors:0 dropped:0 overruns:0 carrier:0         

          collisions:0 txqueuelen:0 

          RX bytes:15466 (15.1 KiB)  TX bytes:39679 (38.7 KiB)

eth0        Link encap:Ethernet  HWaddr 00:11:11:EB:71:E2 

          inet addr:192.168.180.8  Bcast:192.168.180.15  Mask:255.255.255.240         

          inet6 addr: fe80::211:11ff:feeb:71e2/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1         

          RX packets:311 errors:0 dropped:0 overruns:0 frame:0           

          TX packets:228 errors:0 dropped:0 overruns:0 carrier:0         

          collisions:0 txqueuelen:1000 

          RX bytes:30565 (29.8 KiB)  TX bytes:35958 (35.1 KiB) eth1     

          Link encap:Ethernet  HWaddr 00:D0:F8:40:F1:A0           

          inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link

          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1         

          RX packets:54 errors:0 dropped:0 overruns:0 frame:0           

          TX packets:97 errors:0 dropped:0 overruns:0 carrier:0         

          collisions:0 txqueuelen:1000 

          RX bytes:6696 (6.5 KiB)  TX bytes:13821 (13.4 KiB)         

          Interrupt:209 Base address:0x2e00 

eth2        Link encap:Ethernet  HWaddr 00:D0:F8:40:F1:A0 

          inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link

          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1         

          RX packets:74 errors:0 dropped:0 overruns:0 frame:0         

          TX packets:162 errors:0 dropped:0 overruns:0 carrier:0         

          collisions:0 txqueuelen:1000 

          RX bytes:8770 (8.5 KiB)  TX bytes:25858 (25.2 KiB)         

          Interrupt:201 Base address:0x2f00 

lo            Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0         

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:6283 errors:0 dropped:0 overruns:0 frame:0         

          TX packets:6283 errors:0 dropped:0 overruns:0 carrier:0         

          collisions:0 txqueuelen:0 

          RX bytes:9783674 (9.3 MiB)  TX bytes:9783674 (9.3 MiB)

(二)锐捷交换机配置:

lacp system-priority 100        全局配置lacp优先级

interface GigabitEthernet 0/23

no switchport

lacp port-priority 100          接口的lacp优先级 

port-group 1 mode active      接口下开启lacp 主动模式

interface GigabitEthernet 0/24 

no switchport

lacp port-priority 100 

port-group 1 mode active

interface AggregatePort 1 

no switchport  no ip proxy-arp

ip address 1.1.1.1 255.255.255.0

和linux成功建立lacp后状态信息如下:

Show  lacp summary 

System Id:100, 00d0.f822.33ba

Flags:  S - Device is requesting Slow LACPDUs  F - Device is requesting Fast LACPDUs. A - Device is in active mode.        P - Device is in passive mode. Aggregate port 1:

Local information:

LACP port      Oper    Port    Port

Port      Flags    State      Priority        Key    Number  State ----------------------------------------------------------------------

Gi0/23    SA        bndl        100            0x1    0x17    0x3d

Gi0/24    SA        bndl        100            0x1    0x18    0x3d

Partner information:

                LACP port                  Oper    Port    Port

Port      Flags    Priority      Dev ID      Key    Number  State ---------------------------------------------------------------------

Gi0/23    SA        255      00d0.f840.f1a0  0x9    0x2      0x3d

Gi0/24    SA        255      00d0.f840.f1a0  0x9    0x1      0x3d

State表示状态信息:bndl表示lacp建立成功,sup表示不成功。

建立成功后在交换机上去ping  linux 1.1.1.2

Ruijie#ping 1.1.1.2

Sending 5, 100-byte ICMP Echoes to 1.1.1.2, timeout is 2 seconds:  press Ctrl+C to break !!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms 在linux上ping交换机

[root@localhost ~]# ping 1.1.1.1

PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.

64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.601 ms

64 bytes from 1.1.1.1: icmp_seq=2 ttl=64 time=0.606 ms

64 bytes from 1.1.1.1: icmp_seq=3 ttl=64 time=0.608 ms

64 bytes from 1.1.1.1: icmp_seq=4 ttl=64 time=0.607 ms

--- 1.1.1.1 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3002ms rtt min/avg/max/mdev = 0.601/0.605/0.608/0.024 ms

[root@localhost ~]#

可以ping通,lacp建立正常。

把原传输数据的那个网卡shut down异常测试时,需要等到lacp状态超时才能切换到另一条链路。

Ruijie#sh lacp summary 

System Id:100, 00d0.f822.33ba

Flags:  S - Device is requesting Slow LACPDUs  F - Device is requesting Fast LACPDUs. A - Device is in active mode.        P - Device is in passive mode. Aggregate port 1:

Local information:

                            LACP port      Oper    Port    Port

Port      Flags    State      Priority        Key    Number  State ----------------------------------------------------------------------

Gi0/23    SA        sups        100            0x1    0x17    0x45

Gi0/24    SA        bndl        100            0x1    0x18    0x3d

Partner information:

                LACP port                  Oper    Port    Port

Port      Flags    Priority      Dev ID      Key    Number  State ---------------------------------------------------------------------

Gi0/23    SP        0        0000.0000.0000  0x0    0x0      0x0

Gi0/24    SA        255      00d0.f840.f1a0  0x9    0x1      0x3d

在linux如何对本机内的一个网卡eht0绑定一个IP地址

1、Linux的网络设备配置文件存放在/etc/sysconfig/network-scripts里面,对于以太网的第一个网络设备,配置文件名一般为 ifcfg-eth0 。

2、如果需要为第一个网络设备绑定多一个IP地址,只需要在/etc/sysconfig/network-scripts目录里面创建一个名为ifcfg-eth0:0的文件,内容样例为:

DEVICE="eth0:0"

IPADDR="211.100.10.11"

NETMASK="255.255.255.0"

ONBOOT="yes"

其中的DEVICE为设备的名称eth0即第一个网卡,IPADDR为此设备的IP地址,用户可以在这里设置IP地址,NETMASK为子网掩码,ONBOOT表示在系统启动时自动启动。 如果需要再绑定多一个IP地址,只需要把文件名和文件内的DEVICE中的eth0:x加一即可。

Linux下双网卡绑定七种模式

现在一般的企业都会使用双网卡接入,这样既能添加网络带宽,同时又能做相应的冗余,可以说是好处多多。而一般企业都会使用linux操作系统下自带的网卡绑定模式,当然现在网卡产商也会出一些针对windows操作系统网卡管理软件来做网卡绑定(windows操作系统没有网卡绑定功能 需要第三方支持)。进入正题,linux有七种网卡绑定模式:0. round robin,1.active-backup,2.load balancing (xor), 3.fault-tolerance (broadcast), 4.lacp, 5.transmit load balancing, 6.adaptive load balancing。 第一种:bond0:round robin标准:round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.

特点:(1)所有链路处于负载均衡状态,轮询方式往每条链路发送报文,基于per packet方式发送。服务上ping 一个相同地址:1.1.1.1 双网卡的两个网卡都有流量发出。负载到两条链路上,说明是基于per packet方式 ,进行轮询发送。(2)这模式的特点增加了带宽,同时支持容错能力,当有链路出问题,会把流量切换到正常的链路上。

实际绑定结果: cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: load balancing (round-robin) -----RR的模式 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: 74:ea:3a:6a:54:e3 Slave Interface: eth1 MII Status: up Link Failure Count: 0

应用拓扑:交换机端需要配置聚合口,cisco叫port channel。拓扑图如下:

第二种:bond1:active-backup标准文档定义:Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

模式的特点:一个端口处于主状态 ,一个处于从状态,所有流量都在主链路上处理,从不会有任何流量。当主端口down掉时,从端口接手主状态。

实际绑定结果: root@1:~# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: fault-tolerance (active-backup) —–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: 74:ea:3a:6a:54:e3 Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: d8:5d:4c:71:f9:94

应用拓扑:这种模式接入不需要交换机端支持,随便怎么接入都行。

第三种:bond2:load balancing (xor)标准文档描述:XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

特点:该模式将限定流量,以保证到达特定对端的流量总是从同一个接口上发出。既然目的地是通过MAC地址来决定的,因此该模式在"本地"网络配置下可以工作得很好。如果所有流量是通过单个路由器(比如 "网关"型网络配置,只有一个网关时,源和目标mac都固定了,那么这个算法算出的线路就一直是同一条,那么这种模式就没有多少意义了。),那该模式就不是最好的选择。和balance-rr一样,交换机端口需要能配置为"port channel"。这模式是通过源和目标mac做hash因子来做xor算法来选路的。

实际绑定结果: [root@localhost ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006) Bonding Mode: load balancing (xor) ——配置为xor模式 Transmit Hash Policy: layer2 (0) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:d0:f8:40:f1:a0 Slave Interface: eth2 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:d0:f8:00:0c:0c

应用拓扑:同bond0一样的应用模型。这个模式也需要交换机配置聚合口。

第四种:bond3:fault-tolerance (broadcast)标准文档定义:Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

特点:这种模式的特点是一个报文会复制两份往bond下的两个接口分别发送出去,当有对端交换机失效,我们感觉不到任何downtime,但此法过于浪费资源;不过这种模式有很好的容错机制。此模式适用于金融行业,因为他们需要高可靠性的网络,不允许出现任何问题。

实际绑定结果: root@ubuntu12:~/ram# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: fault-tolerance (broadcast) ——- fault-tolerance 模式 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: 74:ea:3a:6a:54:e3 Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: d8:5d:4c:71:f9:94

应用拓扑:如下:

这种模式适用于如下拓扑,两个接口分别接入两台交换机,并且属于不同的vlan,当一边的网络出现故障不会影响服务器另一边接入的网络正常工作。而且故障过程是0丢包。下面展示了这种模式下ping信息: 64 bytes from 1.1.1.1: icmp_seq=901 ttl=64 time=0.205 ms 64 bytes from 1.1.1.1: icmp_seq=901 ttl=64 time=0.213 ms (DUP!) —dup为重复报文 64 bytes from 1.1.1.1: icmp_seq=902 ttl=64 time=0.245 ms 64 bytes from 1.1.1.1: icmp_seq=902 ttl=64 time=0.254 ms (DUP!) 64 bytes from 1.1.1.1: icmp_seq=903 ttl=64 time=0.216 ms 64 bytes from 1.1.1.1: icmp_seq=903 ttl=64 time=0.226 ms (DUP!) 从这个ping信息可以看到,这种模式的特点是,同一个报文服务器会复制两份分别往两条线路发送,导致回复两份重复报文,这种模式有浪费资源的嫌疑。

第五种:bond4:lacp

标准文档定义:IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification. Pre-requisites: 1. Ethtool support in the base drivers for retrieving.the speed and duplex of each slave. 2. A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode.

特点:802.3ad模式是IEEE标准,因此所有实现了802.3ad的对端都可以很好的互操作。802.3ad 协议包括聚合的自动配置,因此只需要很少的对交换机的手动配置(要指出的是,只有某些设备才能使用802.3ad)。802.3ad标准也要求帧按顺序(一定程度上)传递,因此通常单个连接不会看到包的乱序。802.3ad也有些缺点:标准要求所有设备在聚合操作时,要在同样的速率和双工模式,而且,和除了balance-rr模式外的其它bonding负载均衡模式一样,任何连接都不能使用多于一个接口的带宽。 此外,linux bonding的802.3ad实现通过对端来分发流量(通过MAC地址的XOR值),因此在"网关"型配置下,所有外出(Outgoing)流量将使用同一个设备。进入(Incoming)的流量也可能在同一个设备上终止,这依赖于对端802.3ad实现里的均衡策略。在"本地"型配置下,路两将通过 bond里的设备进行分发。

实际绑定结果: root@:~# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: IEEE 802.3ad Dynamic link aggregation Transmit Hash Policy: layer2 (0) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 802.3ad info LACP rate: slow Aggregator selection policy (ad_select): stable Active Aggregator Info: Aggregator ID: 1 Number of ports: 1 Actor Key: 9 Partner Key: 1 Partner Mac Address: 00:00:00:00:00:00 Slave Interface: eth0 MII Status: up Link Failure Count: 0 Permanent HW addr: 74:ea:3a:6a:54:e3 Aggregator ID: 1 Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: d8:5d:4c:71:f9:94 Aggregator ID: 2

应用拓扑:应用拓扑同bond0,和bond2一样,不过这种模式除了配置port channel之外还要在port channel聚合口下开启LACP功能,成功协商后,两端可以正常通信。否则不能使用。

交换机端配置: interface AggregatePort 1 配置聚合口 interface GigabitEthernet 0/23 port-group 1 mode active 接口下开启lacp 主动模式 interface GigabitEthernet 0/24 port-group 1 mode active

第六种:bond5: transmit load balancing

标准文档定义:Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave. Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave.

特点:balance-tlb模式通过对端均衡外出(outgoing)流量。既然它是根据MAC地址进行均衡,在"网关"型配置(如上文所述)下,该模式会通过单个设备来发送所有流量,然而,在"本地"型网络配置下,该模式以相对智能的方式(不是balance-xor或802.3ad模式里提及的XOR方式)来均衡多个本地网络对端,因此那些数字不幸的MAC地址(比如XOR得到同样值)不会聚集到同一个接口上。 不像802.3ad,该模式的接口可以有不同的速率,而且不需要特别的交换机配置。不利的一面在于,该模式下所有进入的(incoming)流量会到达同一个接口;该模式要求slave接口的网络设备驱动有某种ethtool支持;而且ARP监控不可用。

实际配置结果: cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006) Bonding Mode: transmit load balancing —–TLB模式 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: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:d0:f8:40:f1:a0 Slave Interface: eth2 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:d0:f8:00:0c:0c

应用拓扑:这个模式下bond成员使用各自的mac,而不是上面几种模式是使用bond0接口的mac。

如上图,设备开始时会发送免费arp,以主端口eth1的mac为源,当客户端收到这个arp时就会在arp缓存中记录下这个mac对的ip。而在这个模式下,服务器每个端口在ping操作时,会根据算法算出出口,地址不断变化时他,这时会负载到不同端口。实验中ping1.1.1.3时往eth2发送,源mac为00:D0:F8:00:0C:0C,ping1.1.1.4是往eth1发送,源mac为00:D0:F8:40:F1:A0,以此类推,所以从服务器出去的流量负载到两条线路,但是由于服务发arp时只用00:D0:F8:40:F1:A0,这样客户端缓冲记录的是00:D0:F8:40:F1:A0对的ip,封装时目标mac:00:D0:F8:40:F1:A0。这样进入服务的流量都只往eth1(00:D0:F8:40:F1:A0)走。设备会一直发入snap报文,eth1发送源为00d0.f840.f1a0的snap报文,eth2发送源为00d0.f800.0c0c的snap报文。这个snap报文mac和目标mac一样都是网卡本地mac,源ip和目标ip也一样,这个报文的作用是检测线路是否正常的回环报文。 注:可以通过修改bond0的mac地址来引导他发修改后的源mac的免费arp(MACADDR=00:D0:F8:00:0C:0C)

第七种:bond6:adaptive load balancing特点:该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receive load balance, rlb),而且不需要任何switch(交换机)的支持。接收负载均衡是通过ARP协商实现的。bonding驱动截获本机发送的ARP应答,并把源硬件地址改写为bond中某个slave的唯一硬件地址,从而使得不同的对端使用不同的硬件地址进行通信。所有端口都会收到对端的arp请求报文,回复arp回时,bond驱动模块会截获所发的arp回复报文,根据算法算到相应端口,这时会把arp回复报文的源mac,send源mac都改成相应端口mac。从抓包情况分析回复报文是第一个从端口1发,第二个从端口2发。以此类推。 (还有一个点:每个端口除发送本端口回复的报文,也同样会发送其他端口回复的报文,mac还是其他端口的mac)这样来自服务器端的接收流量也会被均衡。 当本机发送ARP请求时,bonding驱动把对端的IP信息从ARP包中复制并保存下来。当ARP应答从对端到达时,bonding驱动把它的硬件地址提取出来,并发起一个ARP应答给bond中的某个slave(这个算法和上面一样,比如算到1口,就给发送arp请求,1回复时mac用1的mac)。使用ARP协商进行负载均衡的一个问题是:每次广播 ARP请求时都会使用bond的硬件地址,因此对端学习到这个硬件地址后,接收流量将会全部流向当前的slave。这个问题通过给所有的对端发送更新(ARP应答)来解决,往所有端口发送应答,应答中包含他们独一无二的硬件地址,从而导致流量重新分布。当新的slave加入到bond中时,或者某个未激活的slave重新激活时,接收流量也要重新分布。接收的负载被顺序地分布(round robin)在bond中最高速的slave上 当某个链路被重新接上,或者一个新的slave加入到bond中,接收流量在所有当前激活的slave中全部重新分配,通过使用指定的MAC地址给每个 client发起ARP应答。下面介绍的updelay参数必须被设置为某个大于等于switch(交换机)转发延时的值,从而保证发往对端的ARP应答不会被switch(交换机)阻截。 必要条件: 条件1:ethtool支持获取每个slave的速率; 条件2:底层驱动支持设置某个设备的硬件地址,从而使得总是有个slave(curr_active_slave)使用bond的硬件地址,同时保证每个bond 中的slave都有一个唯一的硬件地址。如果curr_active_slave出故障,它的硬件地址将会被新选出来的 curr_active_slave接管。

实际配置结果: root@:/tmp# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: adaptive load balancing 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: 74:ea:3a:6a:54:e3 Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: d8:5d:4c:71:f9:94

应用拓扑:

A是双网卡绑定。 当B 发送一个arp请求到达A时,按正常情况A会回应一个arp回应报文,源mac为bond的mac,源就是bond的ip。但是这个模式下bonding驱动会截获这个arp回应,把源mac改成bond状态 下其中某一个网卡的mac:mac1,这样B收到这个arp回应时就会在arp缓存中记录下ip:1.1.1.1对应的mac为mac1。这样B的过来的流量都走MAC1. 当C 发送一个arp请求到达A时,按正常情况A会回应一个arp回应报文,源mac为bond的mac,源就是bond的ip。但是这个模式下bonding驱动会截获这个arp回应,把源mac改成bond状态 下其中某一个网卡的mac:mac2,这样C收到这个arp回应时就会在arp缓存中记录下ip:1.1.1.1对应的mac为mac2。这样C的过来的流量都走MAC2. 这样就可以做到回来让回来的流量也负载均衡。出方向均衡和MODE=5一致,不同地址会根据xor算法算出不同出口,发不同出口发送相应的arp ,mac是对应网卡的mac。

===================================================

Linux (RedHat, Ubuntu, etc.) Bonding 共提供了六种模式:

名辞解释: 在bonding的领域里, 英文slave interface表示某个实体连线的意思; 因此指令名称为: ifenslave

mode=0 (balance-rr): 采取依序使用的连线的方式,提供了负载均衡及容错的功能

mode=1 (active-backup): 众多的连线中,只有一个是启用的状态,当启用的连线失效(败),则由备援的连线接手,提供容错机制。

mode=2 (balance-xor): 采用xor的演算法来选择传输的连线,其结果是以目的地MAC为基准选择哪一条连线;提供了负载均衡及容错机制。

mode=3 ( broadcast): 把封包送到所有的连线,当有连线失效没有任何downtime,但此法过於浪费连线资源;有容错机制。

mode=4 (802.3ad, LACP): IEEE 802.3ad Dynamic Link Aggregation协定;提供较好的机制,并可搭配802.1Q trunking同时介接不同的VLAN;惟独此法必须与支援802.3ad的交换机介接,并且每个slave的驱动程式都需支援ethtool撷取介面的讯息, 较为豪华,但是提供了相当优良的应用,负载均衡及容错机制。

mode=5 (balance-tlb): Adaptive Transmit load balancing; 无须交换机支援但slave驱动程式需支援ethtool;根据连线介面卡的负载决定traffic如何送出,回覆的traffic则由送出的salve接收。

mode=6 (balance-alb): 包含了mode 5所有功能及需求,再加上接收traffic时的负载均衡.

linux绑定bond的七种模式

目前网卡绑定mode共有七种(0~6)bond0、bond1、bond2、bond3、bond4、bond5、bond6

常用的有三种:

mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。

mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。

mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。

Linux网口绑定:

通过网口绑定(bond)技术,可以很容易实现网口冗余,负载均衡,从而达到高可用高可靠的目的。前提约定:

2个物理网口分别是:eth0,eth1

绑定后的虚拟口是:bond0

服务器IP是:10.10.10.1

第一步,配置设定文件:

[root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-bond0  

DEVICE=bond0  

BOOTPROTO=none  

ONBOOT=yes  

IPADDR=10.10.10.1  

NETMASK=255.255.255.0  

NETWORK=192.168.0.0 

[root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-eth0  

DEVICE=eth0  

BOOTPROTO=none  

MASTER=bond0  

SLAVE=yes 

[root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-eth1  

DEVICE=eth1  

BOOTPROTO=none  

MASTER=bond0  

SLAVE=yes  

第二步,修改modprobe相关设定文件,并加载bonding模块:

1.在这里,我们直接创建一个加载bonding的专属设定文件/etc/modprobe.d/bonding.conf  

[root@woo ~]# vi /etc/modprobe.d/bonding.conf  

alias bond0 bonding  

options bonding mode=0 miimon=200 

2.加载模块(重启系统后就不用手动再加载了)  

[root@woo ~]# modprobe bonding 

3.确认模块是否加载成功:  

[root@woo ~]# lsmod | grep bonding  

bonding 100065 0  

第三步,重启一下网络,然后确认一下状况:

[root@db01 ~]# service network restart  

Shutting down interface bond0:  [  OK  ]  

Shutting down loopback interface:  [  OK  ]  

Bringing up loopback interface:  [  OK  ]  

Bringing up interface bond0:  [  OK  ] 

[root@db01 ~]#  cat /proc/net/bonding/bond0  

Ethernet Channel Bonding Driver: v3.4.0-1 (October 7, 2008) 

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  

Speed: 1000 Mbps  

Duplex: full  

Link Failure Count: 0  

Permanent HW addr: 40:f2:e9:db:c9:c2 

Slave Interface: eth1  

MII Status: up  

Speed: 1000 Mbps  

Duplex: full  

Link Failure Count: 0  

Permanent HW addr: 40:f2:e9:db:c9:c3  

[root@db01 ~]#  ifconfig | grep HWaddr  

bond0     Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

eth0      Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

eth1      Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

从上面的确认信息中,我们可以看到3个重要信息:

1.现在的bonding模式是active-backup

2.现在Active状态的网口是eth0

3.bond0,eth1的物理地址和处于active状态下的eth0的物理地址相同,这样是为了避免上位交换机发生混乱。

任意拔掉一根网线,然后再访问你的服务器,看网络是否还是通的。

第四步,系统启动自动绑定、增加默认网关:

[root@woo ~]# vi /etc/rc.d/rc.local  

#追加  

ifenslave bond0 eth0 eth1  

route add default gw 10.10.10.1 


分享标题:linux绑定网卡命令,linux起网卡命令
文章来源:http://bjjierui.cn/article/hojhoc.html

其他资讯