1. 普通网络配置
root@MXY-10-155:~#cat /etc/network/interfaces
auto lo
iface loinet loopback
auto em1
iface em1inet static
address10.26.10.155
netmask255.255.255.0
auto em2
iface em2inet static
address120.132.86.155
netmask255.255.255.224
gateway120.132.86.158
2. Vlan配置
1) 环境准备
apt-getinstall vlan
modprobe8021q
echo“8021q”>> /etc/modules
2) 配置文件
auto em1.100
iface em1.100 inet static
address 100.0.100.2
netmask 255.255.255.0
vlan-raw_device em1
3) 交换机打trunk
4) 重启服务器
3. 网络绑定
1) 环境准备
apt-get install ifenslave
echo “bonding” >> /etc/modules
2) 网络配置
vi /etc/network/interfaces
auto bond0
iface bond0 inet static
address 192.168.2.3
netmask 255.255.255.0
gateway 192.168.2.1
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1
可以直接删除原因来的eth0 eth1配置信息
然后重启服务器
4. 网卡绑定+vlan
1) 环境准备
apt-get install vlan ifenslave
echo “8021q” >> /etc/modules
echo “bonding” >> /etc/modules
2) 配置网络
auto lo
iface loinet loopback
auto em1
iface em1inet manual
bond-masterbond0
auto em2
iface em2inet manual
bond-masterbond1
auto em3
iface em3inet manual
bond-masterbond0
auto em4
iface em4inet manual
bond-masterbond1
autobond0
ifacebond0 inet manual
bond-mode4
bond-miimon100
bond-slavesnone
autobond1
ifacebond1 inet manual
bond-mode4
bond-miimon100
bond-slavesnone
autobond0.588
ifacebond0.588 inet static
address10.25.44.6
netmask255.255.255.0
vlan-raw-devicebond0
autobond0.202
ifacebond0.202 inet static
address10.25.63.6
netmask255.255.255.0
vlan-raw-devicebond0
autobond1.7
ifacebond1.7 inet static
address180.96.44.6
netmask255.255.255.0
gateway180.96.44.254
vlan-raw-devicebond1
autobond1.201
ifacebond1.201 inet static
address10.25.64.6
netmask255.255.252.0
vlan-raw-devicebond1
3) 重启MAC更换问题
当重启后,bond0和bond1的mac可能会发生变化,但交换机中arp表刷新时间比较慢,会导致重启后无法连上的问题
解决方法:
a. 人工刷新交换机arp表
b. 开机后主动ping网关,让交换机主动更新arp表
4) 重启后结果确认
bond0 Link encap:Ethernet HWaddrc8:1f:66:ee:7d:0a
inet6 addr:fe80::ca1f:66ff:feee:7d0a/64 Scope:Link
UP BROADCAST RUNNING MASTERMULTICAST MTU:1500 Metric:1
RX packets:8754 errors:0 dropped:0overruns:0 frame:0
TX packets:568 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:948246 (948.2 KB) TX bytes:86797 (86.7 KB)
bond1 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0d
inet6 addr:fe80::ca1f:66ff:feee:7d0d/64 Scope:Link
UP BROADCAST RUNNING MASTERMULTICAST MTU:1500 Metric:1
RX packets:237033 errors:0 dropped:57overruns:0 frame:0
TX packets:652 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16676783 (16.6 MB) TX bytes:74153 (74.1 KB)
bond0.202Link encap:Ethernet HWaddrc8:1f:66:ee:7d:0a
inet addr:10.25.63.6 Bcast:10.25.63.255 Mask:255.255.255.0
inet6 addr:fe80::ca1f:66ff:feee:7d0a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:8 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:648 (648.0 B)
bond0.588Link encap:Ethernet HWaddrc8:1f:66:ee:7d:0a
inet addr:10.25.44.6 Bcast:10.25.44.255 Mask:255.255.255.0
inet6 addr:fe80::ca1f:66ff:feee:7d0a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4918 errors:0 dropped:0overruns:0 frame:0
TX packets:227 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:258756 (258.7 KB) TX bytes:42127 (42.1 KB)
bond1.7 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0d
inet addr:180.96.44.6 Bcast:180.96.44.255 Mask:255.255.255.0
inet6 addr:fe80::ca1f:66ff:feee:7d0d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24541 errors:0 dropped:0overruns:0 frame:0
TX packets:310 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1111020 (1.1 MB) TX bytes:28491 (28.4 KB)
bond1.201Link encap:Ethernet HWaddrc8:1f:66:ee:7d:0d
inet addr:10.25.64.6 Bcast:10.25.67.255 Mask:255.255.252.0
inet6 addr:fe80::ca1f:66ff:feee:7d0d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:8 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:648 (648.0 B)
em1 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0a
UP BROADCAST RUNNING SLAVEMULTICAST MTU:1500 Metric:1
RX packets:2202 errors:0 dropped:0overruns:0 frame:0
TX packets:176 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:271215 (271.2 KB) TX bytes:21992 (21.9 KB)
Interrupt:35
em2 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0d
UP BROADCAST RUNNING SLAVEMULTICAST MTU:1500 Metric:1
RX packets:10238 errors:0 dropped:3overruns:0 frame:0
TX packets:163 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1158641 (1.1 MB) TX bytes:20800 (20.8 KB)
Interrupt:38
em3 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0a
UP BROADCAST RUNNING SLAVEMULTICAST MTU:1500 Metric:1
RX packets:6552 errors:0 dropped:0overruns:0 frame:0
TX packets:392 errors:0 dropped:0 overruns:0carrier:0
collisions:0 txqueuelen:1000
RX bytes:677031 (677.0 KB) TX bytes:64805 (64.8 KB)
Interrupt:34
em4 Link encap:Ethernet HWaddr c8:1f:66:ee:7d:0d
UP BROADCAST RUNNING SLAVEMULTICAST MTU:1500 Metric:1
RX packets:226795 errors:0 dropped:54overruns:0 frame:0
TX packets:489 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15518142 (15.5 MB) TX bytes:53353 (53.3 KB)
Interrupt:36
5. 参考文档
http://blog.sina.com.cn/s/blog_54559518010123u9.html
http://www.beyondvm.com/2014/03/quick-tip-bonding-lacp-and-vlans-in-linux/
http://askubuntu.com/questions/462413/ubuntu-12-04-using-vlans-on-bond0