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,如需轉載請自行聯系原作者