我们知道,一般来说,一个硬件地址对应与一个IP地址。但在一些情况下,我们可以通过一些方法打破硬件地址与IP地址的一一对应关系。下面就来说一下网卡别名与bonding配置。
网卡别名就是将多个IP地址绑定到一个网络接口上,其命名方式为IFACE:num,如eth0:1等。需要注意的是,网卡别名仅对虚拟主机有效。创建网卡别名有两种方式:
1、ifconfig命令:
Ifconfig IFACE:num IPADDR/netmask up
如:ifconfig eth0:1 10.1.253.1/16 up;需要注意设置后是直接生效的;
2、配置文件
我们可以在/etc/sysconfig/network-scripts/下创建网卡别名的对应配置文件ifcfg-IFACE:num;一般来说,配置文件中需要包含以下几项:
DEVICE=IFACE:num 设备名称
IPADDR=A.B.C.D 指定IP地址
NETMASK=netmask 以class方式设定子网掩码
下面我们来看一下利用配置文件来生成网卡别名:
[root@luolmCentOS6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:1 [root@luolmCentOS6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:1 NAME=eth0:1 IPADDR=10.1.253.1 PREFIX=16 ONBOOT=yes GATWAY=10.1.253.1 DNS1=114.114.114.114 DNS2=8.8.8.8 [root@luolmCentOS6 ~]# service NetworkManager stop Stopping NetworkManager daemon: [ OK ] [root@luolmCentOS6 ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done. Determining if ip address 10.1.253.1 is already in use for device eth0... [ OK ] [root@luolmCentOS6 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:E9:15:6B inet addr:10.1.253.0 Bcast:10.1.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fee9:156b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:23150 errors:0 dropped:0 overruns:0 frame:0 TX packets:1113 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1894402 (1.8 MiB) TX bytes:154281 (150.6 KiB) eth0:1 Link encap:Ethernet HWaddr 00:0C:29:E9:15:6B inet addr:10.1.253.1 Bcast:10.1.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 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:65536 Metric:1 RX packets:12 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:720 (720.0 b) TX bytes:720 (720.0 b)
下面我们来看一下bonding配置:
就是将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP地址是不可能的。通过bonding,虚拟一块网卡对外提供连接,物理网卡的MAC地址被修改为相同的MAC地址;
Bonding常见的有三种工作模式:
Mode 0 (balance-rr)
轮转(Round-robin)策略:从头到尾顺序的在每一个slave接口上面发送数据包。本模式提供负载均衡和容错的能力;
Mode 1 (active-backup)
活动–备份(主备)策略:在绑定中,只有一个slave被激活。当且仅当活动的slave接口失败时才会激活其他slave。为了避免交换机发生混乱此时绑定的MAC地址只有一个外部端口上可见
Mode 3 (broadcast)
广播策略:在所有的slave接口上传送所有的报文。本模式提供容错能力。
在bonding的配置也是通过创建与更改/etc/sysconfig/network-scripts/下的配置文件来实现的。下面我们来看一下如何实现bond0(bond1与bond3的实现模式与bond0基本相同)。
[root@luolmCentOS6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 [root@luolmCentOS6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 [root@luolmCentOS6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 [root@luolmCentOS6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 IPADDR=10.1.253.2 PREFIX=16 GATWAY=10.1.253.2 DNS1=114.114.114.114 DNS2=8.8.8.8 BONDING_OPTS="miimon=100 mode=0" 用来设置链路监测与bond模式 [root@luolmCentOS6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none MASTER=bond0 SLAVE=yes [root@luolmCentOS6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 MASTER=bond0 SLAVE=yes [root@luolmCentOS6 ~]# service network restart Shutting down interface bond0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface bond0: Determining if ip address 10.1.253.2 is already in use for device bond0... [ OK ] [root@luolmCentOS6 ~]# ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:29:E9:15:6B inet addr:10.1.253.2 Bcast:10.1.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fee9:156b/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:6168 errors:0 dropped:0 overruns:0 frame:0 TX packets:425 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:555066 (542.0 KiB) TX bytes:67702 (66.1 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:E9:15:6B UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:10453 errors:0 dropped:0 overruns:0 frame:0 TX packets:425 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:920230 (898.6 KiB) TX bytes:56186 (54.8 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:E9:15:6B UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:7131 errors:0 dropped:0 overruns:0 frame:0 TX packets:903 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:638497 (623.5 KiB) TX bytes:131052 (127.9 KiB) 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:65536 Metric:1 RX packets:29 errors:0 dropped:0 overruns:0 frame:0 TX packets:29 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2280 (2.2 KiB) TX bytes:2280 (2.2 KiB)
在bond工作时,我们可以通过/proc/net/bonding/bond来查看bonding的工作状态。
[root@luolmCentOS6 ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: load balancing (round-robin) 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: 00:0c:29:e9:15:6b 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:e9:15:75 Slave queue ID: 0
原创文章,作者:luoliumeng,如若转载,请注明出处:http://www.178linux.com/43277
评论列表(1条)
写的很详细,赞一个