基于linux的高级网络配置

时间:2024-04-09 09:56:17

#####高级网络配置####

1.bond  网络

bonding就是把多个物理网络接口绑定到一起,使它们就像一个网络接口那样运行。 通过Bonding技术,可以实现网口冗余,负载均衡,从而达到高可用高可靠的目的。

#选择linux以太网的绑定模式:

模式 0 ( 平衡轮循 ) - 轮循策略 , 所有接口都使用采用轮循方式在所有 Slave 中传输封包 ; 任何 Slave 都可以接收。

模式 1 ( 主动备份 ) - 容错。一次只能使用一个 Slave 接口, 但是如果该接口出现故障 , 另一个Slave 将接替它。

模式 3 ( 广播 ) - 容错。所有封包都通过所有 Slave 接口广播。

实验环境:在真机中virt-manager命令,再添加一块网卡eth1,删除已设置好ip的eth0

virt-manager,添加网卡

基于linux的高级网络配置

添加成功

基于linux的高级网络配置  

监控命令:watch -n 1 cat /proc/net/bonding/bond0

基于linux的高级网络配置

#####添加bond0接口###

nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.117/24  

ifconfig  ##查看bond0是否添加成功

基于linux的高级网络配置

nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 ####为bond0添加网卡(接口)eth0

nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0 ####为bond0添加网卡(接口)eth1

基于linux的高级网络配置

监控下:

基于linux的高级网络配置

ping 172.25.254.250  ###查看网络是否连通

ifconfig eth0 down  ###关闭eth0工作,此时eth1会顶替eth0工作,ping不会断开

基于linux的高级网络配置

ifconfig eth0 up    ###恢复eth0工作,此时eth1在工作,eth0会变成备用,ping也不会断

基于linux的高级网络配置

###删除bond0###
nmcli connection delete bond0    ###删除bond接口恢复环境
nmcli connection delete eth0       ##删除eth0
nmcli connection delete eth1       ##删除eth1

2. team  网络

Team和 bond0 功能类似,Team不需要手动加载相应内核模块,Team有更强的拓展性,支持8块网卡

team的种类:

1.broadcast     广播容错

2.roundrobin    平衡轮循

3.activebackup  主备

4.loadbalance  负载均衡

监控命令:watch -n 1 teamdctl team0 stat

基于linux的高级网络配置

####添加team0接口###

nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.117/24

基于linux的高级网络配置

nmcli connection add con-name eth0 ifname eth0 type team-slave master team0   ##为team0添加网卡(接口)eth0

nmcli connection add con-name eth1 ifname eth1 type team-slave master team0   ##为team0添加网卡(接口)eth1

基于linux的高级网络配置

监控下:

基于linux的高级网络配置

ping 172.25.254.250  ###查看网络是否连通

ifconfig eth0 down  ##关闭eth0工作,此时eth1会顶替eth0工作,ping不会断开

基于linux的高级网络配置

ifconfig eth0 up    ###恢复eth0工作,此时eth1在工作,eth0会变成备用,ping也不会断

基于linux的高级网络配置

#########网桥的搭建(真机中)######

1.cd /etc/sysconfig/network-scripts
  mv ifcfg-br0 ifcfg-enp0s25 /opt    ###将这两个文件作备份

2.nm-connection-editor  删掉除virbro外的所有东西,再重启系统,添加一个网络,设置其ip,我起的名字是xbw

基于linux的高级网络配置

3. cd /etc/sysconfig/network-scripts/
   ls
vim ifcfg-enp1s0
写入:DEVICE=enp1s0(此处我的设备名是enp1s0)
     ONBOOT=yes
     BOOTPROTO=none

     BRIDGE=br0

基于linux的高级网络配置

vim ifcfg-xbw
写入:DEVICE=br0
     ONBOOT=yes
     BOOTPROTO=none
     IPADDR=172.25.254.70
     PREFIX=24

     TYPE=Bridge

基于linux的高级网络配置

  systemctl stop NetworkManager.service

  systemctl restart network

  brctl  show

基于linux的高级网络配置

4.打开虚拟机管理界面进行建立虚拟机,桥接没有的时候只有NTA方式建立虚拟机。

###未设置桥接建立虚拟机###

基于linux的高级网络配置

基于linux的高级网络配置

基于linux的高级网络配置

基于linux的高级网络配置

##在Network  selection只能选择NAT模式

基于linux的高级网络配置


####用网络桥接的方式建立虚拟机##

1.前面的步骤,和选择参数和未建立桥接时一样

2.只是在最后Network  selection选择时,会有桥接建立的选项

基于linux的高级网络配置

######桥接接口的管理###########

虚拟机中
brctl show
brctl addbr br0      ###添加一个桥接接口br0
ifconfig  br0 172.25.254.117/24  ##给br0进行网络配置

brctl show           ###查看桥接情况

基于linux的高级网络配置

ping 172.25.254.250  ###ping不通

基于linux的高级网络配置

brctl addif br0 eth0  ###给br0接口添加一个网卡

brctl show           ##查看是否加上 

基于linux的高级网络配置

ping 172.25.254.250   ##可以ping通

基于linux的高级网络配置

brctl delif br0 eth0  ###将eth0从br0接口删除

brctl  show

基于linux的高级网络配置

ifconfig br0 down     ###关闭br0工作             
brctl delbr br0       ###删除br0接口

ifconfig              ##查看br0是否删除 

基于linux的高级网络配置

1110