Ubuntu 双网卡绑定
环境说明
Ubuntu 16.04 LTS
插件安装
apt-get install ifenslave
配置interfaces
auto lo bond0 eth0 eth1
iface bond0 inet static
address 192.168.4.134
netmask 255.255.255.0
network 192.168.4.0
broadcast 192.168.4.255
gateway 192.168.4.1
up /sbin/ifenslave bond0 eth0
up /sbin/ifenslave bond0 eth1
iface lo inet loopback
iface eth0 inet static
address 192.168.4.135
netmask 255.255.255.0
iface eth1 inet static
address 192.168.4.136
netmask 255.255.255.0
把bond模块加入到/etc/modules
# vim /etc/modules
alias bond0 bonding
options bond0 mode=0 miimon=100 max_bonds=2
说明:
miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。
mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。
mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用。
重启网卡
加入开机启动
# modprobe bonding max_bonds=2
创建一个bond设备,下面简单的步骤即可搞定:
1.首先要保证相应的驱动程序已经加载:
# modprobe bonding #或:modprobe <3c59x|eepro100|pcnet32|tulip|...>
2.其次给绑定bond设备分配IP地址
ifconfig bond0 netmask <子网掩码> broadcast <广播地址 >,例如:
# ifconfig bond0 192.168.1.242 netmask 255.255.255.0 broadcast 172.31.3.255
3.最后将所有要绑定的物理网卡接口添加到bond设备中去
ifenslave bond0 [{-f|--force} bond0 eth0 [ eth1 [eth2]...],例如:
# ifenslave bond0 eth0 eth1 #绑定了eth0 eth1两个网卡设备。--force表示强制进行绑定。
4.创建好bond设备后,就可以像一般的网卡设备一样使用了
# ifconfig bond0 up
# ifconfig bond0 down
5.在不停用bond0的情况下添加接口:
# ifenslave {-d|--detach} bond0 eth0 [eth1 [eth2]...] #--detach表示"附加"的意思
6.改变活动的从设备:
# ifenslave {-c|--change-active} bond0 eth0 #--change-acitve 表示"改变活动的从设备"的意思
7.显示主接口(指bond0)信息:
# ifenslave bond0
8.显示所有接口信息:
# ifenslave {-a|--all-interfaces} #--all-interfaces 表示"所有接口"
Ubuntu下配置网桥:
# apt-get install bridge-utils
# vim /etc/network/interface
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 192.168.1.10
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eno0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# /etc/init.d/networking restart
用libvirt启动虚拟机,虚拟机使用桥接方式配置,vnc连接到虚拟机时,如果vnc没法连接到虚拟机,检查/etc/libvirt/qemu.conf文件vnc_listen="0.0.0.0"是否启用。启用之后,原有的虚拟机需要重启,libvirt也要重启。