RHEL6的网络管理与RHEL5的有比较大的改变。
虽然在RHEL5、6中均安装有NetworkManager,在RHEL5中2、3、4、5级别中默认是不启用的。
但在RHEL6中,默认是启用的,NetworkManager会一直监控网卡状态,修改网卡参数立即生效不用重启服务。
[root@rhel5 ~]# chkconfig --list NetworkManager #默认开机不自动启动NetworkManager服务
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@rhel6 ~]# chkconfig --list NetworkManager #默认开机自动启动NetworkManager服务
NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
· <b>IP别名</b>
RHEL5:
[root@rhel5 ~]# /etc/init.d/NetworkManager status
NetworkManager 已停
[root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.90
NETWORK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
[root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:1 #配置IP别名需要添加虚拟网卡eht0:1
DEVICE=eth0:1
IPADDR=192.168.2.90
[root@rhel5 ~]# ip add show eth0
7: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
link/ether 00:0c:29:db:14:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.90/24 brd 192.168.1.255 scope global eth0
inet 192.168.2.90/24 brd 192.168.2.255 scope global eth0:1
RHEL6:
[root@rhel6 ~]# /etc/init.d/NetworkManager status
NetworkManager (pid 2808) is running...
[root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
NM_CONTROLLED=yes
HWADDR=00:0C:29:BF:45:80
IPADDR=192.168.1.119
IPADDR2=192.168.2.119 #配置IP别名可直接在eth0中添加IP地址
DNS1=8.8.8.8 #可直接在/etc/resolv.conf中写入"nameserver 8.8.8.8"
DNS2=8.8.4.4
[root@rhel6 ~]# ip add show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.119/24 brd 192.168.1.255 scope global eth0
inet 192.168.2.119/24 brd 192.168.2.255 scope global eth0
· 多网卡绑定 <b>bonding</b>
RHEL5
[root@rhel5 ~]# cat /etc/modprobe.conf
alias bond0 bonding
options bonding miimon=100 mode=1 #每隔100ms监测一次链路状态,HA模式
[root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
NETMASK=255.255.255.0
MASTER=bond0
SLAVE=yes
[root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
[root@rhel5 ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:DB:14:10
inet addr:192.168.1.90 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fedb:1410/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:1229 errors:0 dropped:0 overruns:0 frame:0
TX packets:589 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:92885 (90.7 KiB) TX bytes:78052 (76.2 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:DB:14:10
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:530 errors:0 dropped:0 overruns:0 frame:0
TX packets:291 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:40654 (39.7 KiB) TX bytes:40137 (39.1 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:DB:14:10
RX packets:714 errors:0 dropped:0 overruns:0 frame:0
TX packets:310 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:53177 (51.9 KiB) TX bytes:39827 (38.8 KiB)
[root@rhel5 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup) #HA模式
Primary Slave: None
Currently Active Slave: eth0 #主网卡:eth0
MII Status: up
MII Polling Interval (ms): 100 #检测时间:100ms
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
Link Failure Count: 0
Permanent HW addr: 00:0c:29:db:14:10
Slave Interface: eth1
Permanent HW addr: 00:0c:29:db:14:1a
RHEL6
[root@rhel6 ~]# cat /etc/modprobe.d/bonding.conf #区别于RHEL5的/etc/modprobe.conf
[root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
NM_CONTROLLED=no
BONDING_OPTS="MODE=0 MIIMON=1000" #1000ms监测一次链路状态,LB模式
[root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
[root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
[root@rhel6 ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:BF:45:80
inet addr:192.168.1.119 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:febf:4580/64 Scope:Link
RX packets:3133 errors:0 dropped:0 overruns:0 frame:0
TX packets:619 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:275036 (268.5 KiB) TX bytes:86282 (84.2 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:BF:45:80
RX packets:2317 errors:0 dropped:0 overruns:0 frame:0
TX packets:309 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:207976 (203.1 KiB) TX bytes:48317 (47.1 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:BF:45:8A
RX packets:816 errors:0 dropped:0 overruns:0 frame:0
TX packets:312 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:67060 (65.4 KiB) TX bytes:38801 (37.8 KiB)
[root@rhel6 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: load balancing (round-robin) #LB模式
MII Polling Interval (ms): 1000 #监测时间1000ms
Up Delay (ms): 0 Down Delay (ms): 0
Speed: 1000 Mbps
Duplex: full Link
Failure Count: 0
Permanent HW addr: 00:0c:29:bf:45:80
Slave queue ID: 0
Duplex: full
Permanent HW addr: 00:0c:29:bf:45:8a
Slave queue ID: 0
以下是摘自<b>Red Hat Enterprise Linux 6 Essentials eBook</b>
1.For example, if two Ethernet interfaces are being channel bonded, both eth0 and eth1 may look like the following example: DEVICE=eth<N>
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
2.cp /etc/sysconfig/network-script/ifcfg-eth0 /etc/sysconfig/network-script/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.1
NETMASK=255.255.255.0
BONDING_OPTS="<bonding parameters separated by spaces>"
3.As root, create a new file named <bonding>.conf in the /etc/modprobe.d/ directory. Note that you can name this file anything you like as long as it ends with a .conf extension. Insert the following line in this new file:
alias bond<N> bonding
4.You can configure each bond individually by manipulating the files located in the /sys/class/net/bond<N>/bonding/ directory. First, the bond you are configuring must be taken down:
# ifconfig bond0 down
As an example, to enable MII monitoring on bond0 with a 1 second interval, you could run (as root):
# echo 1000 > /sys/class/net/bond0/bonding/miimon
To configure bond0 for balance-alb mode, you could run either:
# echo 6 > /sys/class/net/bond0/bonding/mode
...or, using the name of the mode:
# echo balance-alb > /sys/class/net/bond0/bonding/mode
Mode of operation : 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)
切换测试:
1). 切断eth0的连接前,eth1处于Slave状态,通过以下命令可监测链路统计信息,发现eth1无数据的收发(只接收来自eth0的监测报文)
[root@rhel6 ~]# watch 'ip -s link show eth1' #默认每隔2s运行一次'ip -s link show eth1'
Every 2.0s: ip -s link show eth1 Wed Nov 21 02:13:48 2012
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
RX: bytes packets errors dropped overrun mcast
137357 1916 0 0 0 0
TX: bytes packets errors dropped carrier collsns
41562 441 0 0 0 0
2). 切断eth0的连接后,eth1立即自动切换为Active状态(通过客户端ping -t 192.168.1.90 未出现丢包现象),可发现eth1出现了数据的收发
[root@rhel5 ~]# ifdown eth0
[root@rhel5 ~]# ifconfig
RX packets:13276 errors:0 dropped:0 overruns:0 frame:0
TX packets:890 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:874191 (853.7 KiB) TX bytes:96900 (94.6 KiB)
[root@rhel5 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup)
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
Link Failure Count: 0
Permanent HW addr: 00:0c:29:db:14:1a
3). 重新连接上eth0后,eth0不会自动切换到Active状态,且不会有数据的收发
[root@rhel5 ~]# ifup eth0
[root@rhel5 ~]# ifconfig eth0
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:120 (120.0 b) TX bytes:0 (0.0 b)
MII Polling Interval (ms): 1000
Slave Interface: eth0
Permanent HW addr: 00:0c:29:db:14:10
本文转自Vnimos51CTO博客,原文链接:http://blog.51cto.com/vnimos/1065384,如需转载请自行联系原作者