linux高级网络配置基础team和网桥

来源:互联网 发布:三方博弈矩阵 编辑:程序博客网 时间:2024/06/08 10:43
team   

1.基础:

linux 中, centos7之前都是使用bond机制来实现多网络绑定同一个IP地址,来对网络提供访问,并按不同的模式来负载均衡或者轮回接替管理处理数据。而到了contos7之后,提供了一种强大的工具,nmcli工具命令,使用此工具,将会根据命令参数的配置来重新生成特定的配置文件来供网络接口使用,方便而又灵活。在linux不再使用bond机制定义,而是使用网路组team 机制,把 team 组当作一个设备。


team :也是链路聚合 最多支持8块网卡,Team 不需要手动加载相应内核模块
支持模式:
               broadcast        广播容错
               roundrobin       轮询
              activebackup     主备
               loadbalance      负载均衡
2.配置:

[root@localhost Desktop]# nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.121/24         创建一个team0

[root@localhost Desktop]# teamdctl team0 stat           查看team0的状态


[root@localhost Desktop]# nmcli  connection add con-name eth0 ifname eth0 type team-slave master team0

将eth0添加到team0组中

[root@localhost Desktop]# teamdctl team0 stat


[root@localhost Desktop]# nmcli  connection add con-name ens7 ifname ens7 type team-slave master team0

[root@localhost Desktop]# teamdctl team0 stat

3.测试:

[root@localhost Desktop]# ifconfig eth0 down
[root@localhost Desktop]# ifconfig eth0 up
[root@localhost Desktop]# ifconfig eth1 down


删除team0

[root@localhost Desktop]# nmcli connection delete  team0
[root@localhost Desktop]# nmcli connection delete  eth0
[root@localhost Desktop]# nmcli connection delete  eth1
[root@localhost Desktop]# nmcli connection  show
NAME  UUID  TYPE  DEVICE
#######################################################################################

2.网桥


2.1定义和功能

桥接就是把一台机器上的若干个网络接口“连接”起来。其结果是,其中一个网口收到的报文会被复制给其他网口并发送出去。以使得网口之间的报文能够互相转发。

网桥实现最重要的两点:

        1. MAC学习:学习MAC地址,起初,网桥是没有任何地址与端口的对应关系的,它发送数据,还是得想HUB一样,但是每发送一个数据,它都会关心数据包的来源MAC是从自己的哪个端口来的,由于学习,建立地址-端口的对照表(CAM表)。

        2. 报文转发:每发送一个数据包,网桥都会提取其目的MAC地址,从自己的地址-端口对照表(CAM表)中查找由哪个端口把数据包发送出去。


2.2配置


[kiosk@foundation21 network-scripts]$ cd /etc/sysconfig/network-scripts/

####将其中的ifcfg备份,只剩下ifcfg-lo
[root@foundation21 network-scripts]# vim ifcfg-enp0s25
vim ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.21
NETMASK=255.255.255.0
[root@foundation21 network-scripts]# systemctl stop  NetworkManager.service    如果不关会记录网卡信息
[root@foundation21 network-scripts]# systemctl restart network
[root@foundation21 network-scripts]# systemctl start  NetworkManager.service

3.br0
配置方式
[root@foundation21 network-scripts]# vim ifcfg-enp0s25
DEVICE=enp0s25     ####设备名称    
ONBOOT=yes         ####开启设备自动激活
BOOTPROTO=none       ####网卡工作状态
BRIDGE=br0         ####网卡开启的网桥接口


[root@foundation21 network-scripts]# vim ifcfg-br0

DEVICE=br0
ONBOOT=yes
BOOTPROTE=yes
BOOTPROTO=none
IPADDR=172.25.254.21
NETMASK=255.255.255.0
TYPE=Bridge       ####网络接口类型
 
[root@foundation21 network-scripts]# systemctl stop  NetworkManager.service   ###如果不关会记录网卡信息
[root@foundation21 network-scripts]# systemctl restart network
[root@foundation21 network-scripts]# systemctl start  NetworkManager.service
测试
[root@foundation21 network-scripts]# ifconfig



命令管理方式

[root@foundation21 network-scripts]# systemctl stop  NetworkManager.service

[root@localhost Desktop]# systemctl stop NetworkManager.service

[root@localhost Desktop]# brctl show

[root@localhost Desktop]# brctl addbr br0
[root@localhost Desktop]# brctl addif  br0 eth0
[root@localhost Desktop]# ifconfig eth0 up
[root@localhost Desktop]# ifconfig br0 172.25.254.121 netmask 255.255.255.0
[root@localhost Desktop]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.52540000150a    no        eth0
[root@localhost Desktop]# ping 172.25.254.250
PING 172.25.254.250 (172.25.254.250) 56(84) bytes of data.
64 bytes from 172.25.254.250: icmp_seq=1 ttl=64 time=0.995 ms
64 bytes from 172.25.254.250: icmp_seq=2 ttl=64 time=0.486 ms

64 bytes from 172.25.254.250: icmp_seq=3 ttl=64 time=0.523 ms




删除
[root@localhost Desktop]# ifconfig  br0 down           先关闭br0
[root@localhost Desktop]# brctl delif br0 eth0           将网卡eth0从br0删除
[root@localhost Desktop]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.000000000000    no        
[root@localhost Desktop]# brctl delbr br0                  删除br0         
[root@localhost Desktop]# brctl show

bridge name    bridge id        STP enabled    interfaces


原创粉丝点击