centos6網卡別名
網卡別名:
作用;為同一個網卡設備配置的多個不同ip地址
配置要求:
(1)為每個設備別名生成獨立的接口配置文件
(2)需關閉NetworkManager服務
命令:
1)臨時關閉:service network stop
2)開機啟動關閉:chkconfig NetworkManager off
(3)別名網卡命名需在原有網卡名稱基礎上加冒號“:num”,如eth0:10
(4)別名網卡的ip地址必須為靜態指定,不能為動態獲取,原網卡設置為自動獲取和靜態指定
##編輯原網卡
[root@Centos network-scripts]# vim ifcfg-eth0 1 DEVICE=eth0//設備名稱 2 BOOTPROTO=dhcp //IP地址獲取方式(dhcp:動態獲取 none/static:手動指定) 3 ONBOOT=yes//系統啟動的時候網絡接口是否有效(yes/no) 4 TYPE=Ethernet//設備類型(Ethernet:以太網卡)
##編輯別名網卡
[root@Centos network-scripts]# vim ifcfg-eth0:10 //編輯別名網卡,在原網卡名稱后面加上冒號“:num” 如eth0:10 1 DEVICE=eth0:10//設備名必須和文件名相同 2 BOOTPROTO=none//IP地址獲取方式(dhcp:動態獲取 none/static:手動指定) 3 ONBOOT=yes//系統啟動的時候網絡接口是否有效(yes/no) 4 TYPE=Ethernet//設備類型(Ethernet:以太網卡) 5 IPADDR=10.1.18.18//ip地址手動指定 6 PREFIX=16//子網掩碼,長度為16(子網掩碼有兩種指定方式(1)NETMASK=255.255.255.0 (2)PREFIX=16) 7 GATEWAY=10.1.0.1//網關 8 DNS1=8.8.8.8//DNS服務器地址 9 DNS2=114.114.114.114//備用服務器地址
注意:(1)需重啟網絡服務后才能生效(命令:service network restart)
(2)可參考文件/usr/share/doc/initscripts-*/sysconfig.txt(此文件中存放關于網絡配置的各關鍵字解釋)
#cat /usr/share/doc/initscripts-9.03.53/sysconfig.txt [root@Centos initscripts-9.03.53]# cat /usr/share/doc/initscripts-9.03.53/sysconfig.txt | less ======================= Generic options: /etc/sysconfig/* CGROUP_DAEMON= List of control groups that the daemon will be run in. For example, CGROUP_DAEMON="cpu:daemons cpuacct:/" will run it in the daemons group for the CPU controller, and the '/' group for the CPU accounting controller. /etc/sysconfig/authconfig used by authconfig to store information about the system's user information and authentication setup; changes made to this file have no effect until the next time authconfig is run .......
centos6網卡bond
Bonding(網絡接口配置),將多塊網卡綁定同一個IP地址對外進行提供服務,可以實現高可用或者負載均衡,由于直接給兩塊網卡設置同一個ip地址可以的,需要通過bonding(網絡接口配置),虛擬出一塊網卡對外提供連接,物理網卡的被修改為相同的MAC地址。
Bonding的常用工作模式:(實際網卡綁定mode共有七種(0~6)bond0、bond1、bond2、bond3、bond4、bond5、bond6)
Mode 0(Balance -rr)
輪轉(Round-robin)策略:從頭到尾順序的在每一個slave(奴隸)接口上面發送數據包。
作用:提供負載均衡和容錯能力
Mode 1 (active-backup)
活動-備份(主備)策略:在綁定中,只有一個slave被激活,在當前活動的slave接口連接失敗時,才會激活其他slave,為了避免交換機發生混亂此時綁定的MAC地址只有一個外部端口上可見
Mode 3 (broadcast)
廣播策略:在所有的slave接口上傳送所有的報文
作用:提供容錯能力
簡單說明:
mode=0:平衡負載模式,有自動備援,但需要”Switch”支援及設定。
mode=1:自動備援模式,其中一條線若斷線,其他線路將會自動備援。
mode=3:在每個slave接口上傳輸每個數據包,此模式提供了容錯能力
Linux網口綁定:
(1)通過網口綁定(bond)技術,可以很容易實現網口冗余,負載均衡,從而達到高可用高可靠的目的.
2個物理網口分別:eth0,eth1
綁定后的虛擬口:bond0
IP地址:10.1.18.18
(2)miimon是用來進行鏈路監測的。如果miimon=100,那么系統每100ms監測一次鏈路狀態,如果有一條網卡線路不通則轉入另一條線路
查看band0狀態;cat /proc/net/bonding/bond0
關于bonding的詳細配置參考文件
/usr/share/doc/kernel-doc-version/Documentation/networking/bonging.txt
1、設置配置文件
(1)配置bond0文件
[root@Centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 1 DEVICE=bond0 //設備名稱,此名稱為物理網卡依賴的主設備名稱, 2 BOOTPROTO=none //ip地址指定方式,手動 3 IPADDR=10.1.18.18 //ip地址 4 PREFIX=16 //子網掩碼,長度為16,即為255.255.0.0 5 GATEWAY=10.1.0.1 //網關,10.1.0.1 6 DNS=8.8.8.8 //dns服務器地址 7 BONDING_OPTS="miimon=100 mode=1" //指定bond模式,miimon=100:表示每100毫秒系統檢測一次網卡是否正常工作,mode=1表示為bond工作模式
(2)配置物理網卡設置(eth0)
[root@Centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 1 DEVICE=eth0 //設備名 2 BOOTPROTP=none //ip地址指定方式,手動 3 MASTER=bond0 //指定band主人設備名稱 4 SLAVE=yes //開啟奴隸模式(待啟動模式) 5 USERCTL=no //是否開啟普通用戶控制
(3)配置物理網卡設置(eth1)
[root@Centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 1 DEVICE=eth1//設備名 2 BOOTPROTO=none//ip地址手動指定 3 MASTER=bond0//指定band主人設備名稱 4 SLAVE=yes//開啟奴隸模式(待啟動模式) 5 USERCTL=no//是否開啟普通用戶控制
2、重啟配置網絡服務
(1)重啟網絡服務
[root@Centos ~]# service network restart Shutting down interface eth0: /etc/sysconfig/network-scripts/ifdown-eth: line 121: /sys/class/net/bond0/bonding/slaves: No such file or directory [ OK ] Shutting down interface eth1: /etc/sysconfig/network-scripts/ifdown-eth: line 121: /sys/class/net/bond0/bonding/slaves: No such file or directory [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface bond0: Determining if ip address 10.1.18.18 is already in use for device bond0... [ OK ]
(2)使用ifconfig命令查看是否生效
[root@Centos ~]# ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:29:63:89:DC //band0mac地址和其他兩塊網卡一樣, inet addr:10.1.18.18 Bcast:10.1.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe63:89dc/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:62 errors:0 dropped:0 overruns:0 frame:0 TX packets:27 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5734 (5.5 KiB) TX bytes:3492 (3.4 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:63:89:DC UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:75479 errors:0 dropped:0 overruns:0 frame:0 TX packets:3408 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5367766 (5.1 MiB) TX bytes:547222 (534.3 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:63:89:DC UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:352 errors:0 dropped:0 overruns:0 frame:0 TX packets:42 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:38276 (37.3 KiB) TX bytes:3036 (2.9 KiB)
(3)查看文件/proc/net/bonding/bond0,觀察狀態
[root@Centos ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth0//正在工作的網卡,現在為eth0網卡 MII Status: up//狀態:開啟 MII Polling Interval (ms): 100//檢測間隔時間:100毫秒 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0//奴隸接口:eth0 MII Status: up //此狀態up表現為網卡是否連接 Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:63:89:dc//MAC地址 Slave queue ID: 0//奴隸隊列ID Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:63:89:e6 Slave queue ID: 0
3、、用兩臺電腦測試ping,可嘗試去關掉兩塊物理網卡中的其中任意一塊,觀察其ping狀態
原創文章,作者:Lii,如若轉載,請注明出處:http://www.www58058.com/42849
slave是從,而不是奴隸,
寫的很認真,很好,請繼續保持