centos7多網卡配置bond0 (mode6無需交換機作配置)

一、執行setup命令-->網絡配置-->本例中四塊網卡。linux

二、ifconfig列出四塊網卡。服務器

三、咱們的目標,綁定eth0和eth1兩塊網卡做爲公網網卡,ip設置爲192.168.0.51網絡

四、首先備份兩塊網卡的配置文件負載均衡

mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/bak_network-scripts/ifcfg-eth0_bakssh

mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/bak_network-scripts/ifcfg-eth1_bakoop

五、從新建立ifcfg-eth0網卡配置文件測試

vi /etc/sysconfig/network-scripts/ifcfg-eth0.net

DEVICE=eth0
USERCTL=no
ONBOOT=yes
SLAVE=yes
MASTER=bond0
BOOTPROTO=nonerest

六、重建eth1網卡配置文件server

vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
USERCTL=no
ONBOOT=yes
SLAVE=yes
MASTER=bond0
BOOTPROTO=none

七、建立bond0虛擬網卡配置文件

Vi /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
IPADDR=192.168.0.51
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
GATEWAY=192.168.0.1
IPV6INIT=no
TYPE=Ethernet
#DNS1=192.168.0.1

八、修改配置文件/etc/modprobe.d/dist.conf

vi dist.conf

最後新增以下兩行:

alias bond0 bonding
options bond0 miimon=100 mode=6

mode=6表示作負載均衡無需交換機作配置


九、加載bond0模塊
[root@rac1 modprobe.d]# modprobe bonding
[root@rac1 modprobe.d]# lsmod |grep bond
bonding 127331 0
8021q 25317 1 bonding
ipv6 321422 30 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

十、重啓網絡服務
service network stop

十一、最好也重啓下sshd服務
service sshd restart

十二、查看bond0狀態:
[root@rac1 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
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: 08:00:27:fc:7e:5b
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:6f:e3:9d
Slave queue ID: 0
[root@rac1 network-scripts]#

1三、查看ifconfig
[root@rac1 network-scripts]# ifconfig
bond0 Link encap:Ethernet HWaddr 08:00:27:FC:7E:5B
inet addr:192.168.0.51 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fefc:7e5b/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:4135 errors:0 dropped:0 overruns:0 frame:0
TX packets:2025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:375692 (366.8 KiB) TX bytes:261792 (255.6 KiB)

eth0 Link encap:Ethernet HWaddr 08:00:27:FC:7E:5B
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:3394 errors:0 dropped:0 overruns:0 frame:0
TX packets:1640 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:304735 (297.5 KiB) TX bytes:219122 (213.9 KiB)

eth1 Link encap:Ethernet HWaddr 08:00:27:FC:7E:5B
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:742 errors:0 dropped:0 overruns:0 frame:0
TX packets:387 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:71017 (69.3 KiB) TX bytes:43378 (42.3 KiB)

eth2 Link encap:Ethernet HWaddr 08:00:27:18:29:48
inet addr:192.168.0.7 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe18:2948/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:862 errors:0 dropped:0 overruns:0 frame:0
TX packets:113 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77480 (75.6 KiB) TX bytes:12978 (12.6 KiB)

eth3 Link encap:Ethernet HWaddr 08:00:27:59:1E:79
inet addr:192.168.0.99 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe59:1e79/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:768 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:73511 (71.7 KiB) TX bytes:2732 (2.6 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:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:728 (728.0 b) TX bytes:728 (728.0 b)

[root@rac1 network-scripts]#
注意eth0和eth1是不該該有ip顯示的。

1四、若是cat /proc/net/bonding/bond0
[root@rac1 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
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: 08:00:27:fc:7e:5b
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 08:00:27:6f:e3:9d
Slave queue ID: 0
[root@rac1 network-scripts]#
注意:
Link Failure Count: 1
而且:
ifconfig -a
顯示的綁定的兩塊物理網卡eth0和eth1都顯示ip而且跟bond0顯示的ip同樣,是由於啓動了NetworkManager服務。
執行:
service NetworkManager stop
chkconfig NetworkManager off
中止並關閉自啓動。


本次新測試了使用NetworkManager的狀況下,不管怎麼設置都沒有辦法上外網。

環境以下:

一臺dns服務器,ip是192.168.2.88

其並未安裝和使用NetworkManager服務

其/etc/resolv.conf配置以下:

[root@mydns selinux]# cat /etc/resolv.conf
options attempts:2
options timeout:1
search asiainfo.com
nameserver 192.168.2.88

nameserver 8.8.8.8
[root@mydns selinux]#
其正向解析和反向解析均沒問題:

[root@mydns selinux]# nslookup rac1
Server: 192.168.2.88
Address: 192.168.2.88#53

Name: rac1.asiainfo.com
Address: 192.168.2.51

[root@mydns selinux]# nslookup rac2.asiainfo.com
Server: 192.168.2.88
Address: 192.168.2.88#53

Name: rac2.asiainfo.com
Address: 192.168.2.52

[root@mydns selinux]# nslookup 192.168.2.53
Server: 192.168.2.88
Address: 192.168.2.88#53

53.2.168.192.in-addr.arpa name = rac1-vip.asiainfo.com.

[root@mydns selinux]#
其ip配置以下:
[root@mydns selinux]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:A0:F7:99
inet addr:192.168.2.88 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea0:f799/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3746 errors:0 dropped:0 overruns:0 frame:0
TX packets:2135 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:405220 (395.7 KiB) TX bytes:217002 (211.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:16436 Metric:1
RX packets:43 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4997 (4.8 KiB) TX bytes:4997 (4.8 KiB)

[root@mydns selinux]#
這種狀況下能夠直接訪問外網:

[root@mydns selinux]# ping www.baidu.com
PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108: icmp_seq=1 ttl=57 time=3.28 ms
64 bytes from 180.97.33.108: icmp_seq=2 ttl=57 time=3.75 ms
64 bytes from 180.97.33.108: icmp_seq=3 ttl=57 time=4.51 ms
64 bytes from 180.97.33.108: icmp_seq=4 ttl=57 time=3.88 ms
64 bytes from 180.97.33.108: icmp_seq=5 ttl=57 time=3.87 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4487ms
rtt min/avg/max/mdev = 3.286/3.861/4.513/0.395 ms
[root@mydns selinux]#

可是另外一臺主機rac1在使用NetworkManager服務的狀況下,不管怎麼配置網卡和dns都不能ping通www.baidu.com,並且在此狀況下,沒法寫/etc/resolv.conf文件。
可是能夠正常解析asiainfo.com的主機。

在禁用了NetworkManager服務之後按以下配置,能夠正常解析asiainfo.com的主機,同時也能夠ping通www.baidu.com

下面列出配置:

ip配置狀況:

[root@rac1 ~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 08:00:27:A8:81:CA
inet addr:192.168.2.51 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea8:81ca/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:535 errors:0 dropped:0 overruns:0 frame:0
TX packets:279 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:279986 (273.4 KiB) TX bytes:30411 (29.6 KiB)

eth0 Link encap:Ethernet HWaddr 08:00:27:A8:81:CA
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:449 errors:0 dropped:0 overruns:0 frame:0
TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:274061 (267.6 KiB) TX bytes:15351 (14.9 KiB)

eth1 Link encap:Ethernet HWaddr 08:00:27:A8:81:CA
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:86 errors:0 dropped:0 overruns:0 frame:0
TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5925 (5.7 KiB) TX bytes:15060 (14.7 KiB)

eth2 Link encap:Ethernet HWaddr 08:00:27:62:A1:1A
inet addr:10.0.10.1 Bcast:10.0.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe62:a11a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:85 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5847 (5.7 KiB) TX bytes:818 (818.0 b)

eth3 Link encap:Ethernet HWaddr 08:00:27:2B:09:AF
inet addr:10.0.11.1 Bcast:10.0.11.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe2b:9af/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:85 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5847 (5.7 KiB) TX bytes:818 (818.0 b)

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:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)

[root@rac1 ~]#

網卡bond0:
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.2.51
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
GATEWAY=192.168.2.1
IPV6INIT=no
TYPE=Ethernet

DNS1=8.8.8.8
DNS2=192.168.2.88
[root@rac1 ~]#
網卡eth0:
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
SLAVE=yes
MASTER=bond0
BOOTPROTO=none

DNS1=8.8.8.8
DNS2=192.168.2.88
[root@rac1 ~]#
網卡eth1:
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
SLAVE=yes
MASTER=bond0
BOOTPROTO=none

DNS1=8.8.8.8
DNS2=192.168.2.88
[root@rac1 ~]#
網卡eth2:

[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
HWADDR=08:00:27:62:A1:1A
TYPE=Ethernet
UUID=02e8ed45-fa9f-49ae-a9c4-9b5e6230f663
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=10.0.10.1
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
IPV6INIT=no
USERCTL=no

DNS1=8.8.8.8
DNS2=192.168.2.88

[root@rac1 ~]#

網卡eth3:
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3
DEVICE=eth3
HWADDR=08:00:27:2B:09:AF
TYPE=Ethernet
UUID=71a976b5-cc2b-4c7f-8d95-5ba495d3029a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=10.0.11.1
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
IPV6INIT=no
USERCTL=no

DNS1=8.8.8.8
DNS2=192.168.2.88
[root@rac1 ~]#

[root@rac1 ~]# service NetworkManager status
NetworkManager 已停
[root@rac1 ~]# chkconfig --list|grep NetworkManager
NetworkManager 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉

/etc/resolv.conf配置:
[root@rac1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager


# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
options attempts:2
options timeout:1
search asiainfo.com

nameserver 192.168.2.88
nameserver 8.8.8.8
[root@rac1 ~]#

看dns解析狀況:
[root@rac1 ~]# nslookup rac1.asiainfo.com
Server: 192.168.2.88
Address: 192.168.2.88#53

Name: rac1.asiainfo.com
Address: 192.168.2.51

[root@rac1 ~]# nslookup rac2.asiainfo.com
Server: 192.168.2.88
Address: 192.168.2.88#53

Name: rac2.asiainfo.com
Address: 192.168.2.52

[root@rac1 ~]# nslookup 192.168.2.54
Server: 192.168.2.88
Address: 192.168.2.88#53

54.2.168.192.in-addr.arpa name = rac2-vip.asiainfo.com.

[root@rac1 ~]#
內網dns解析沒問題。
[root@rac1 ~]# nslookup www.baidu.com
Server: 192.168.2.88
Address: 192.168.2.88#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 180.97.33.107
Name: www.a.shifen.com
Address: 180.97.33.108

[root@rac1 ~]# ping www.baidu.comPING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.64 bytes from 180.97.33.108: icmp_seq=1 ttl=57 time=4.23 ms64 bytes from 180.97.33.108: icmp_seq=2 ttl=57 time=6.53 ms64 bytes from 180.97.33.108: icmp_seq=3 ttl=57 time=3.29 ms64 bytes from 180.97.33.108: icmp_seq=4 ttl=57 time=4.02 ms^C--- www.a.shifen.com ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 3531msrtt min/avg/max/mdev = 3.294/4.519/6.532/1.214 ms[root@rac1 ~]# --------------------- 做者:kadwf123 來源:CSDN 原文:https://blog.csdn.net/kadwf123/article/details/78234727/ 版權聲明:本文爲博主原創文章,轉載請附上博文連接!

相關文章
相關標籤/搜索