RHEL6子接口及双网卡绑定配置

1.子接口配置

 

 

Linux就是一台路由器,只要开启路由转发功能。CISCO中,我们知道子接口的配置为fa0/0.1,那么在Linux中,子接口如何配置呢?

虚拟主机可以配置多大254个子接口,下面且看子接口的配置:

 

创建子接口配置文件

[root@ns ~]# cd /etc/sysconfig/net

netconsole       network          networking/      network-scripts/

[root@ns ~]# cd /etc/sysconfig/network-scripts/

[root@ns network-scripts]# cp -p ifcfg-eth0 ifcfg-eth0:0

//直接复制父接口配置文件,然后进行修改即可。

 

对配置文件进行修改

DEVICE=eth0:0

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

NM_CONTROLLED=no

//此处改yesno,否则重启网卡后子接口地址将覆盖父接口地址。此处父接口也要修改。

 

BOOTPROTO=none

IPADDR=172.16.30.250

PREFIX=24

GATEWAY=172.16.30.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth0:0"

HWADDR=00:0c:29:03:fc:20

LAST_CONNECT=1431484186

NETMASK=255.255.255.0

USERCTL=no

 

修改父接口配置文件

[root@ns network-scripts]# vim ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

IPADDR=192.168.10.250

PREFIX=24

GATEWAY=192.168.10.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth0"

HWADDR=00:0c:29:03:fc:20

LAST_CONNECT=1431484186

NETMASK=255.255.255.0

USERCTL=no

 

重启网卡之前查看网卡配置情况

[root@ns network-scripts]# ifconfig

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:38 errors:0 dropped:0 overruns:0 frame:0

          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:3769 (3.6 KiB)  TX bytes:3769 (3.6 KiB)

 

重启network服务,再次查看网卡配置情况

[root@ns network-scripts]# service network restart

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]

[root@ns network-scripts]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:03:FC:20 

          inet addr:192.168.10.250  Bcast:192.168.10.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe03:fc20/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:762 errors:0 dropped:0 overruns:0 frame:0

          TX packets:624 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:57615 (56.2 KiB)  TX bytes:61853 (60.4 KiB)

 

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:03:FC:20 

          inet addr:172.16.30.250  Bcast:172.16.30.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

 

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:38 errors:0 dropped:0 overruns:0 frame:0

          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:3769 (3.6 KiB)  TX bytes:3769 (3.6 KiB)

 

 

 

2.双网卡绑定

 

对于要求严格的网络环境,都会提供网络的备份,提供容错、负载等功能。本章我们将介绍在Linux中如何实现网卡的备份。

 

  • 模式分类

mode=0:提供负载均衡和容错能力;

mode=1:主备模式,提供容错能力;

mode=4802.3ad链路汇聚,把两个网卡绑定在一起使用,前提是交换机支持802.3ad协议。

wKiom1VoW4vRXuZAAAFXMgiLB4I569.jpg

 

 

 

2.1.添加网卡

 

注:如安装系统时缺省有两块网卡,并且配置文件都有,可忽略此部分内容,直接看【2.2】内容。

 

关闭虚拟机,点击设置添加网卡

wKioL1VoXR_wE735AAIyYrxSKas356.jpg

点击【编辑虚拟机设置】

 

wKioL1VoXSCBdEC0AAGW4i8ep5U168.jpg

点击【添加】

 

 

wKiom1VoW4yyvZHZAAGw6-4tNls231.jpg

选择【网络适配器】

点击【下一步】

 

wKioL1VoXSGzSlD6AAHX6vLShjo682.jpg

【网络连接】根据自己的需要选择,然后点击【完成】

 

wKiom1VoW42SYuVyAAGzaUMFqJw585.jpg

如上【网络适配器2】添加成功

点击【确定】完成添加

开机。继续网卡配置文件设置

 

查看网卡详细情况

[root@ns network-scripts]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:03:FC:20 

          inet addr:192.168.10.250  Bcast:192.168.10.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe03:fc20/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:2010 errors:0 dropped:0 overruns:0 frame:0

          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:121157 (118.3 KiB)  TX bytes:831 (831.0 b)

 

eth1      Link encap:Ethernet  HWaddr 00:0C:29:03:FC:2A 

          inet addr:192.168.127.128  Bcast:192.168.127.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe03:fc2a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:255 errors:0 dropped:0 overruns:0 frame:0

          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:16425 (16.0 KiB)  TX bytes:2081 (2.0 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:40 errors:0 dropped:0 overruns:0 frame:0

          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:3902 (3.8 KiB)  TX bytes:3902 (3.8 KiB)

如上:eth1,即第二块网卡添加成功。

 

配置文件创建

[root@ns Desktop]# cd /etc/sysconfig/network-scripts/

[root@ns network-scripts]# cp -p ifcfg-eth0 ifcfg-eth1

[root@ns network-scripts]# vim ifcfg-eth1

DEVICE=eth1

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

IPADDR=172.16.30.250

PREFIX=24

GATEWAY=172.16.30.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth1"

HWADDR=00:0C:29:03:FC:2A

LAST_CONNECT=1431484186

NETMASK=255.255.255.0

USERCTL=no

~               

 

 

2.2.双网卡绑定配置

 

双网卡绑定,即把两个网卡看成一个网卡使用,需要有一个组合的配置文件ifcfg-bond0来管理,相当于把两个真是的网卡虚拟成一个网卡来管理(ciscohsrp技术)。所以我们要创建这个文件。

[root@ns network-scripts]# cp -p ifcfg-eth0 ifcfg-bond0

[root@ns network-scripts]# vim ifcfg-bond0

DEVICE=bond0

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

BONDING_OPTS="mode=1 minmon=50"

//采用模式1,负载和容错。Minmon=50为每50毫秒监听一次。

NM_CONTROLLED=no

BOOTPROTO=none

IPADDR=192.168.10.250

PREFIX=24

GATEWAY=192.168.10.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="bond0"

#HWADDR=00:0c:29:03:fc:20

//此文件无需MAC地址,使用的是真实网卡的MAC地址

LAST_CONNECT=1431484186

USERCTL=no

 

Eth0配置文件修改

[root@ns network-scripts]# vim ifcfg-eth0

NETMASK=255.255.255.0

DEVICE=eth0

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

#IPADDR=192.168.10.250

#PREFIX=24

#GATEWAY=192.168.10.1

//IP地址由bond0文件管理

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth0"

HWADDR=00:0c:29:03:fc:20

LAST_CONNECT=1431484186

USERCTL=no

 

Eth1配置文件修改

[root@ns network-scripts]# vim ifcfg-eth1

DEVICE=eth1

TYPE=Ethernet

UUID=ddae15a9-058f-434d-8331-fd68238fca6a

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=YES

#IPADDR=172.16.30.250

#PREFIX=24

#GATEWAY=172.16.30.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth1"

HWADDR=00:0C:29:03:FC:2A

LAST_CONNECT=1431484186

USERCTL=no

 

重启network服务查看

[root@ns network-scripts]# service network restart

Shutting down interface eth0:  /etc/sysconfig/network-scripts/ifdown-eth: line 116: /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:  ./network-functions: line 446: /sys/class/net/bond0/bonding/minmon: No such file or directory

./network-functions: line 446: /sys/class/net/bond0/bonding/minmon: No such file or directory

./network-functions: line 446: /sys/class/net/bond0/bonding/minmon: No such file or directory

                                                           [  OK  ]

Bringing up interface eth1:  RTNETLINK answers: File exists

                                                           [  OK  ]

 

 

[root@ns network-scripts]# ifconfig

bond0     Link encap:Ethernet  HWaddr 00:0C:29:03:FC:20 

          inet addr:192.168.10.250  Bcast:192.168.10.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe03:fc20/64 Scope:Link

          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1

          RX packets:5777 errors:0 dropped:0 overruns:0 frame:0

          TX packets:377 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:364082 (355.5 KiB)  TX bytes:52854 (51.6 KiB)

 

eth0      Link encap:Ethernet  HWaddr 00:0C:29:03:FC:20 

          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1

          RX packets:5778 errors:0 dropped:0 overruns:0 frame:0

          TX packets:378 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:364142 (355.6 KiB)  TX bytes:53088 (51.8 KiB)

 

eth1      Link encap:Ethernet  HWaddr 00:0C:29:03:FC:2A 

          inet6 addr: fe80::20c:29ff:fe03:fc2a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:314 errors:0 dropped:0 overruns:0 frame:0

          TX packets:46 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:19965 (19.4 KiB)  TX bytes:4045 (3.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:64 errors:0 dropped:0 overruns:0 frame:0

          TX packets:64 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:6843 (6.6 KiB)  TX bytes:6843 (6.6 KiB)

 

最后Ping测试,此测试需两块桥接到同一个模式。Ping的同时,断开eth0,会发现断开,但是过一会又连接上了。这就是体现了双网卡绑定的优势。