Linux系统网络高级配置--网桥、网络接口(bond、team)

网络高级配置

本次博文主要介绍网络桥接、bond网络接口、Team网络接口的功能演示。

(一)配置网络桥接

网络桥接的管理命令

brctl       桥接管理命令

show      显示

addbr    添加网桥

delbr     删除网桥

addif      添加网桥连接

delif       删除网桥连接

初始化的时候是没有br0的

[[email protected] ~]# ifconfig

Linux系统网络高级配置--网桥、网络接口(bond、team)

桥接br0

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] ~]# ifconfig

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] ~]# ifconfig br0 172.25.254.124 netmask 255.255.255.0

[[email protected] ~]# ifconfig

Linux系统网络高级配置--网桥、网络接口(bond、team)

图形化界面删除eth0

[[email protected] ~]# nm-connection-editor

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] ~]#brctl addif br0 eth0

[[email protected] ~]#brctl show

Linux系统网络高级配置--网桥、网络接口(bond、team)

删除br0

Linux系统网络高级配置--网桥、网络接口(bond、team)

(二)配置bond网络接口

 Red Hat Enterprise Linux允许管理员使用 bonding内核模块和称为通道绑定接口的特殊网络接口将多个网络接口绑定到一个通道。根据选择的绑定模式,通道绑定使两个或更多网络接口作为一个网络接口,从而增加逮狂和/提供冗余性。

bond 只支持两块网卡

选择Llinux 以太网绑定模式:

模式一:平衡轮循,所有接口都使用采用轮循方式在所有Slave中传输封包;任何Slave都可以接收。

模式二:主动备份,一次只能使用一个Slave接口,但是如果该接口出现故障,另一个Slave将接替它。

模式三:广播,所有封包都通过所有Slave接口广播。

演示举例:

创建bond0

[[email protected] Desktop]# nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.124/24

只留下bond0

[[email protected] Desktop]# nm-connection-editor

Linux系统网络高级配置--网桥、网络接口(bond、team)

添加网卡eth0和eth1

[[email protected] Desktop]# nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0

[[email protected] Desktop]# nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0

监控命令

[[email protected] Desktop]# watch -n 1 cat /proc/net/bonding/bond0

Linux系统网络高级配置--网桥、网络接口(bond、team)

调试命令:

[[email protected] Desktop]# ifconfig eth0 down

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] Desktop]# ifconfig eth0 up

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] Desktop]# ifconfig eth1 down

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] Desktop]# ifconfig eth1 up

Linux系统网络高级配置--网桥、网络接口(bond、team)

删除bond0的网卡

Linux系统网络高级配置--网桥、网络接口(bond、team)

(三)配置Team网络接口

Team的特性:

Team和bond0功能类似

Team不需要手动加载相应内核模块

Team有更强的拓展性

支持8块网卡

Team的种类:

broadcast        广播容错

roundrobin      平衡轮叫

activebackup   主备

loadbalance     负载均衡

创建Team0

[[email protected] Desktop]# nmcli connection add con-name team0 type team ifname team0 config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.124/24

Linux系统网络高级配置--网桥、网络接口(bond、team)

监控命令:

[[email protected] Desktop]# watch -n 1  teamdctl team0 state

增添网卡eth0和eth1:

[[email protected] Desktop]# nmcli connection add con-name eth1 ifname eth1 type team-slave master team0

[[email protected] Desktop]# nmcli connection add con-name eth0 ifname eth0 type team-slave master team0

调试:

[[email protected] Desktop]# ifconfig eth1 down

Linux系统网络高级配置--网桥、网络接口(bond、team)

[[email protected] Desktop]# ifconfig eth0 up

Linux系统网络高级配置--网桥、网络接口(bond、team)


附录:

桥接基础尝试

(一)去掉br0(模拟安装系统后原始的状态

[[email protected] ~]# cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts]# mv ifcfg-br0 ifcfg-enp0s25 /mnt/

[[email protected] network-scripts]vim ifcfg-enp0s25

DEVICE=enp0s25

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.25.254.24

NETWASK=255.255.255.0

[[email protected] network-scripts] reboot

[[email protected] network-scripts]ifconfig

(二)配置网桥,br0

[[email protected] network-scripts]# pwd

/etc/sysconfig/network-scripts

[[email protected] network-scripts]# vim ifcfg-enp0s25 

DEVICE=enp0s25

ONBOOT=yes

BOOTPROTO=none

BRIDGE=br0

[[email protected] network-scripts]# vim ifcfg-br0

DEVICE=br0

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.25.254.24

NETMASK=255.255.255.0

TYPE=Bridge

[[email protected] network-scripts]# systemctl restart network

[[email protected] ~]#  cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts] # mv ifcfg-br0 ifcfg-enp0s25 /mnt/

[[email protected] network-scripts]vim ifcfg-enp0s25

DEVICE=enp0s25

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.25.254.24

NETWASK=255.255.255.0