IP别名与多网卡绑定(RHEL5/RHEL6)

简介:
RHEL6的网络管理与RHEL5的有比较大的改变。
虽然在RHEL5、6中均安装有NetworkManager,在RHEL5中2、3、4、5级别中默认是不启用的。
但在RHEL6中,默认是启用的,NetworkManager会一直监控网卡状态,修改网卡参数立即生效不用重启服务。 
 
 
  1. [root@rhel5 ~]# chkconfig --list NetworkManager   #默认开机不自动启动NetworkManager服务
  2. NetworkManager  0:off  1:off  2:off  3:off  4:off  5:off  6:off  
  3. [root@rhel6 ~]# chkconfig --list NetworkManager   #默认开机自动启动NetworkManager服务
  4. NetworkManager  0:off  1:off  2:on   3:on   4:on   5:on   6:off  

· IP别名

 
  1. RHEL5 
  2. [root@rhel5 ~]# /etc/init.d/NetworkManager status 
  3. NetworkManager 已停 
  4.  
  5. [root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
  6. # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) 
  7. DEVICE=eth0 
  8. ONBOOT=yes 
  9. TYPE=Ethernet 
  10. BOOTPROTO=none 
  11. IPADDR=192.168.1.90 
  12. NETWORK=255.255.255.0 
  13. GATEWAY=192.168.1.1 
  14. DNS1=8.8.8.8 
  15. DNS2=8.8.4.4 
  16. [root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:1  #配置IP别名需要添加虚拟网卡eht0:1
  17. # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) 
  18. DEVICE=eth0:1 
  19. ONBOOT=yes 
  20. TYPE=Ethernet 
  21. BOOTPROTO=none 
  22. IPADDR=192.168.2.90 
  23. NETWORK=255.255.255.0 
  24. DNS1=8.8.8.8 
  25. DNS2=8.8.4.4 
  26.  
  27. [root@rhel5 ~]# ip add show eth0 
  28. 7: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue  
  29.     link/ether 00:0c:29:db:14:10 brd ff:ff:ff:ff:ff:ff 
  30.     inet 192.168.1.90/24 brd 192.168.1.255 scope global eth0 
  31.     inet 192.168.2.90/24 brd 192.168.2.255 scope global eth0:1 
  32.  
  33. RHEL6 
  34. [root@rhel6 ~]# /etc/init.d/NetworkManager status 
  35. NetworkManager (pid  2808) is running... 
  36.  
  37. [root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  
  38. DEVICE=eth0 
  39. ONBOOT=yes 
  40. NM_CONTROLLED=yes 
  41. TYPE=Ethernet 
  42. BOOTPROTO=none 
  43. HWADDR=00:0C:29:BF:45:80 
  44. IPADDR=192.168.1.119 
  45. NETWORK=255.255.255.0 
  46. GATEWAY=192.168.1.1 
  47. IPADDR2=192.168.2.119  #配置IP别名可直接在eth0中添加IP地址
  48. NETWORK=255.255.255.0 
  49. DNS1=8.8.8.8                    #可直接在/etc/resolv.conf中写入"nameserver 8.8.8.8" 
  50. DNS2=8.8.4.4             
  51.  
  52. [root@rhel6 ~]# ip add show eth0 
  53. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  54.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  55.     inet 192.168.1.119/24 brd 192.168.1.255 scope global eth0 
  56.     inet 192.168.2.119/24 brd 192.168.2.255 scope global eth0 

· 多网卡绑定 bonding 

  • RHEL5
 
  1. [root@rhel5 ~]# cat /etc/modprobe.conf 
  2. alias bond0 bonding 
  3. options bonding miimon=100 mode=1  #每隔100ms监测一次链路状态,HA模式
  4.  
  5. [root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0  
  6. DEVICE=bond0 
  7. ONBOOT=yes 
  8. TYPE=Ethernet 
  9. BOOTPROTO=none 
  10. IPADDR=192.168.1.90 
  11. NETMASK=255.255.255.0 
  12. [root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
  13. DEVICE=eth0 
  14. ONBOOT=yes 
  15. TYPE=Ethernet 
  16. BOOTPROTO=none 
  17. MASTER=bond0 
  18. SLAVE=yes 
  19. [root@rhel5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
  20. DEVICE=eth1 
  21. ONBOOT=yes 
  22. TYPE=Ethernet 
  23. BOOTPROTO=none 
  24. MASTER=bond0 
  25. SLAVE=yes 
  26.  
  27. [root@rhel5 ~]# ifconfig 
  28. bond0     Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  29.           inet addr:192.168.1.90  Bcast:192.168.1.255  Mask:255.255.255.0 
  30.           inet6 addr: fe80::20c:29ff:fedb:1410/64 Scope:Link 
  31.           UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1 
  32.           RX packets:1229 errors:0 dropped:0 overruns:0 frame:0 
  33.           TX packets:589 errors:0 dropped:0 overruns:0 carrier:0 
  34.           collisions:0 txqueuelen:0  
  35.           RX bytes:92885 (90.7 KiB)  TX bytes:78052 (76.2 KiB
  36.  
  37. eth0      Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  38.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  39.           RX packets:530 errors:0 dropped:0 overruns:0 frame:0 
  40.           TX packets:291 errors:0 dropped:0 overruns:0 carrier:0 
  41.           collisions:0 txqueuelen:0  
  42.           RX bytes:40654 (39.7 KiB)  TX bytes:40137 (39.1 KiB
  43.  
  44. eth1      Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  45.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  46.           RX packets:714 errors:0 dropped:0 overruns:0 frame:0 
  47.           TX packets:310 errors:0 dropped:0 overruns:0 carrier:0 
  48.           collisions:0 txqueuelen:1000  
  49.           RX bytes:53177 (51.9 KiB)  TX bytes:39827 (38.8 KiB
  50.  
  51. [root@rhel5 ~]# cat /proc/net/bonding/bond0
  52. Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
  53.  
  54. Bonding Mode: fault-tolerance (active-backup) #HA模式
  55. Primary Slave: None
  56. Currently Active Slave: eth0 #主网卡:eth0
  57. MII Status: up
  58. MII Polling Interval (ms): 100 #检测时间:100ms
  59. Up Delay (ms): 0
  60. Down Delay (ms): 0
  61.  
  62. Slave Interface: eth0
  63. MII Status: up
  64. Link Failure Count: 0
  65. Permanent HW addr: 00:0c:29:db:14:10
  66.  
  67. Slave Interface: eth1
  68. MII Status: up
  69. Link Failure Count: 0
  70. Permanent HW addr: 00:0c:29:db:14:1a
  • RHEL6
 
  1. [root@rhel6 ~]# cat /etc/modprobe.d/bonding.conf   #区别于RHEL5的/etc/modprobe.conf
  2. alias bond0 bonding 
  3. [root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0     
  4. DEVICE=bond0 
  5. ONBOOT=yes 
  6. BOOTPROTO=none 
  7. NM_CONTROLLED=no 
  8. IPADDR=192.168.1.119 
  9. NETMASK=255.255.255.0 
  10. BONDING_OPTS="MODE=0 MIIMON=1000"  #1000ms监测一次链路状态,LB模式
  11. [root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
  12. DEVICE=eth0 
  13. ONBOOT=yes 
  14. NM_CONTROLLED=no 
  15. TYPE=Ethernet 
  16. BOOTPROTO=none 
  17. MASTER=bond0 
  18. SLAVE=yes 
  19. [root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
  20. DEVICE=eth1 
  21. ONBOOT=yes 
  22. NM_CONTROLLED=no 
  23. TYPE=Ethernet 
  24. BOOTPROTO=none 
  25. MASTER=bond0 
  26. SLAVE=yes 
  27.  
  28. [root@rhel6 ~]# ifconfig 
  29. bond0     Link encap:Ethernet  HWaddr 00:0C:29:BF:45:80   
  30.           inet addr:192.168.1.119  Bcast:192.168.1.255  Mask:255.255.255.0 
  31.           inet6 addr: fe80::20c:29ff:febf:4580/64 Scope:Link 
  32.           UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1 
  33.           RX packets:3133 errors:0 dropped:0 overruns:0 frame:0 
  34.           TX packets:619 errors:0 dropped:0 overruns:0 carrier:0 
  35.           collisions:0 txqueuelen:0  
  36.           RX bytes:275036 (268.5 KiB)  TX bytes:86282 (84.2 KiB
  37.  
  38. eth0      Link encap:Ethernet  HWaddr 00:0C:29:BF:45:80   
  39.           inet addr:192.168.1.119  Bcast:192.168.1.255  Mask:255.255.255.0 
  40.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  41.           RX packets:2317 errors:0 dropped:0 overruns:0 frame:0 
  42.           TX packets:309 errors:0 dropped:0 overruns:0 carrier:0 
  43.           collisions:0 txqueuelen:1000  
  44.           RX bytes:207976 (203.1 KiB)  TX bytes:48317 (47.1 KiB
  45.  
  46. eth1      Link encap:Ethernet  HWaddr 00:0C:29:BF:45:8A   
  47.           inet addr:192.168.1.119  Bcast:192.168.1.255  Mask:255.255.255.0 
  48.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  49.           RX packets:816 errors:0 dropped:0 overruns:0 frame:0 
  50.           TX packets:312 errors:0 dropped:0 overruns:0 carrier:0 
  51.           collisions:0 txqueuelen:1000  
  52.           RX bytes:67060 (65.4 KiB)  TX bytes:38801 (37.8 KiB)
  53. [root@rhel6 ~]# cat /proc/net/bonding/bond0
  54. Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
  55.  
  56. Bonding Mode: load balancing (round-robin) #LB模式
  57. MII Status: up
  58. MII Polling Interval (ms): 1000 #监测时间1000ms
  59. Up Delay (ms): 0 Down Delay (ms): 0
  60.  
  61. Slave Interface: eth0
  62. MII Status: up
  63. Speed: 1000 Mbps
  64. Duplex: full Link
  65. Failure Count: 0
  66. Permanent HW addr: 00:0c:29:bf:45:80
  67. Slave queue ID: 0
  68.  
  69. Slave Interface: eth1
  70. MII Status: up
  71. Speed: 1000 Mbps
  72. Duplex: full
  73. Link Failure Count: 0
  74. Permanent HW addr: 00:0c:29:bf:45:8a
  75. Slave queue ID: 0  

 以下是摘自Red Hat Enterprise Linux 6 Essentials eBook 

 
  1. 1.For example, if two Ethernet interfaces are being channel bonded, both eth0 and eth1 may look like the following example: DEVICE=eth<N>  
  2. BOOTPROTO=none  
  3. ONBOOT=yes  
  4. MASTER=bond0  
  5. SLAVE=yes  
  6. USERCTL=no  
  7.   
  8. 2.cp /etc/sysconfig/network-script/ifcfg-eth0 /etc/sysconfig/network-script/ifcfg-bond0 
  9. DEVICE=bond0  
  10. IPADDR=192.168.1.1  
  11. NETMASK=255.255.255.0  
  12. ONBOOT=yes  
  13. BOOTPROTO=none  
  14. USERCTL=no  
  15. BONDING_OPTS="<bonding parameters separated by spaces>" 
  16.    
  17. 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: 
  18.   alias bond<N> bonding  
  19.   
  20. 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:
  21. # ifconfig bond0 down 
  22. As an example, to enable MII monitoring on bond0 with a 1 second interval, you could run (as root): 
  23.   # echo 1000 > /sys/class/net/bond0/bonding/miimon 
  24. To configure bond0 for balance-alb mode, you could run either: 
  25.   # echo 6 > /sys/class/net/bond0/bonding/mode 
  26. ...or, using the name of the mode: 
  27.   # echo balance-alb > /sys/class/net/bond0/bonding/mode  
  28.   
  29. 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. 1). 切断eth0的连接前,eth1处于Slave状态,通过以下命令可监测链路统计信息,发现eth1无数据的收发(只接收来自eth0的监测报文) 
  2. [root@rhel6 ~]# watch 'ip -s link show eth1'        #默认每隔2s运行一次'ip -s link show eth1' 
  3. Every 2.0s: ip -s link show eth1                                  Wed Nov 21 02:13:48 2012 
  4.  
  5. 3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000 
  6.     link/ether 00:0c:29:db:14:10 brd ff:ff:ff:ff:ff:ff 
  7.     RX: bytes  packets  errors  dropped overrun mcast 
  8.     137357     1916     0       0       0       0 
  9.     TX: bytes  packets  errors  dropped carrier collsns 
  10.     41562      441      0       0       0       0 
  11.  
  12. 2). 切断eth0的连接后,eth1立即自动切换为Active状态(通过客户端ping -t 192.168.1.90 未出现丢包现象),可发现eth1出现了数据的收发 
  13. [root@rhel5 ~]# ifdown eth0 
  14. [root@rhel5 ~]# ifconfig  
  15. bond0     Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  16.           inet addr:192.168.1.90  Bcast:192.168.1.255  Mask:255.255.255.0 
  17.           inet6 addr: fe80::20c:29ff:fedb:1410/64 Scope:Link 
  18.           UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1 
  19.           RX packets:13276 errors:0 dropped:0 overruns:0 frame:0 
  20.           TX packets:890 errors:0 dropped:0 overruns:0 carrier:0 
  21.           collisions:0 txqueuelen:0  
  22.           RX bytes:874191 (853.7 KiB)  TX bytes:96900 (94.6 KiB) 
  23.  
  24. eth1      Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  25.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  26.           RX packets:13276 errors:0 dropped:0 overruns:0 frame:0 
  27.           TX packets:890 errors:0 dropped:0 overruns:0 carrier:0 
  28.           collisions:0 txqueuelen:1000  
  29.           RX bytes:874191 (853.7 KiB)  TX bytes:96900 (94.6 KiB) 
  30.  
  31. [root@rhel5 ~]# cat /proc/net/bonding/bond0  
  32. Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008) 
  33.  
  34. Bonding Mode: fault-tolerance (active-backup) 
  35. Primary Slave: None 
  36. Currently Active Slave: eth1 
  37. MII Status: up 
  38. MII Polling Interval (ms): 100 
  39. Up Delay (ms): 0 
  40. Down Delay (ms): 0 
  41.  
  42. Slave Interface: eth1 
  43. MII Status: up 
  44. Link Failure Count: 0 
  45. Permanent HW addr: 00:0c:29:db:14:1a 
  46.  
  47. 3). 重新连接上eth0后,eth0不会自动切换到Active状态,且不会有数据的收发 
  48. [root@rhel5 ~]# ifup eth0 
  49. [root@rhel5 ~]# ifconfig eth0 
  50. eth0      Link encap:Ethernet  HWaddr 00:0C:29:DB:14:10   
  51.           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1 
  52.           RX packets:2 errors:0 dropped:0 overruns:0 frame:0 
  53.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
  54.           collisions:0 txqueuelen:0  
  55.           RX bytes:120 (120.0 b)  TX bytes:0 (0.0 b) 
  56. [root@rhel5 ~]# cat /proc/net/bonding/bond0  
  57. Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008) 
  58.  
  59. Bonding Mode: fault-tolerance (active-backup) 
  60. Primary Slave: None 
  61. Currently Active Slave: eth1 
  62. MII Status: up 
  63. MII Polling Interval (ms): 1000 
  64. Up Delay (ms): 0 
  65. Down Delay (ms): 0 
  66.  
  67.  
  68. Slave Interface: eth1 
  69. MII Status: up 
  70. Link Failure Count: 0 
  71. Permanent HW addr: 00:0c:29:db:14:1a 
  72.  
  73. Slave Interface: eth0 
  74. MII Status: up 
  75. Link Failure Count: 0 
  76. Permanent HW addr: 00:0c:29:db:14:10 

      本文转自Vnimos51CTO博客,原文链接:http://blog.51cto.com/vnimos/1065384,如需转载请自行联系原作者


相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
Linux 索引 开发工具
CentOS7网卡命名规则
CentOS6之前基于传统的命名方式如:eth1,eth0.... Centos7提供了不同的命名规则,默认是基于固件、拓扑、位置信息来分配。这样做的优点是命名是全自动的、可预知的,缺点是比eth0、wlan0更难读。
1910 0
|
网络协议 开发工具
redhat7.0配置网卡
1.切换到网卡配置目录: cd /etc/sysconfig/network-scripts  2.编辑网卡信息 如 vim ifcfg-enpos3 TYPE=Ethernet #设备类型 BOOTPROTO=static #地址分配模式 NAME=enpos3 #网卡名称 ONBOOT=yes #是否启动 IPADDR=192.
1170 0
|
Linux 网络安全 开发工具
|
Linux 网络协议
CentOS 7 修改网卡名称
方法一:禁用该可预测命名规则 1、对于这一点,你可以在启动时传递“net.ifnames=0 biosdevname=0 ”的内核参数。这是通过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX变量来实现的。
1895 0