Linux基础——高级网络控制

一、bond网络接口(虚拟机)

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

实验:

virt-manager

给虚拟机添加一个网卡,在虚拟机中ifconfig:eth0、eth1

首先此实验需要打开3个shell

shell 1:

添加bond网络接口

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

mode                 ##网卡阵列类型

active-backup   ##主备式,一个网卡工作,另一网卡备用

无网卡的情况下不能连接其他主机:

ping 172.25.254.61

shell 2:

查看bond接口信息

cat /proc/net/bonding/bond0

设置监控命令

watch -n 1 cat /proc/net/bonding/bond0

shell 1:

为bond接口添加真实设备

nmcli  connection add con-name eth1 ifname eth0 type bond-slave master bond0
nmcli  connection add con-name eth2 ifname eth1 type bond-slave master bond0

bond-slave    ##实现网卡阵列服务

master           ##指定接口 bond0

在shell2中监控:

当前接口是eth0网卡在服务,假设当eth0网卡坏掉时,eth1网卡接替eth0网卡服务:

ifconfig eth1 down

ifconfig eth1 up

注:当再次把eth1网卡启用时,eth1网卡不会马上取代eth2网卡,而是当eth2网卡坏掉时才取代

一般来说,2个网卡同时坏掉的几率非常小


shell 3:

添加网卡后查看是否能连接其他主机

注:在网卡交替时,网络连接不断开


删除bond网络接口及网卡

nmcli connection delete bond0
nmcli connection delete eth0
nmcli connection delete eth1

二、team网络接口(虚拟机)

      Team和 bond0 功能类似

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

      Team有更强的拓展性

      支持 8块网卡

实验:

shell 1:

添加team网络接口

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

runner:team   ##接口工作模式

无网卡的情况下不能连接其他主机:

shell 2:

查看team网络接口信息

设置监控命令

watch -n 1 teamdctl team0 stat

shell 1:

为team0网络接口添加真实设备

nmcli  connection add con-name eth0 ifname eth0 type team-slave master team0
nmcli  connection add con-name eth1 ifname eth1 type team-slave master team0

在shell2中监控:

当前接口是eth0网卡在服务,假设当eth0网卡坏掉时,eth1网卡接替eth0网卡服务:

ifconfig eth0 down
当再次把eth1网卡启用时,eth1网卡不会马上取代eth2网卡,而是当eth2网卡坏掉时才取代
ifconfig eth0 up

shell 3:

有网卡的情况下能够连接其他主机:

ping 172.25.254.61

注:在网卡交替时,网络连接不断开


删除team网络接口及网卡

nmcli connection delete team0
nmcli connection delete eth0
nmcli connection delete eth1

三、配置网络桥接(真机)

       网络桥接用网络桥实现共享上网主机和客户机除了利用软件外,还可以用系统自带的网络桥建立连接用双网卡的机器做主机
实验:连接虚拟网卡和真实网卡

备份网络配置文件

[root@foundation61 ~]# cd /etc/sysconfig/network-scripts/
[root@foundation61 ~]# mv ifcfg-br0 ifcfg-enp4s0f1 /opt

建立新的IP

nm-connection-editor

1、把除了Bridge中的virbr0和virbr1其他的网络都删了

2、添加enp4s0f1设备,照常建立一个id

重启网络

[root@foundation61 network-scripts]# systemctl restart network

建立网桥前

virt-manager

新建一个虚拟机

选择第二项

添加镜像

在“Network selection“选项有"Virtual network 'default':NAT"正常建立虚拟机

建立网桥

编辑网络配置


重启网络配置并查看网桥

建立网桥后

virt-manager

新建虚拟机

在“Network selection“选项有"Bridge br0:Host device enp4s0f1"网桥建立虚拟机


      连接虚拟网卡和真实网卡后建立的虚拟机比正常建立的虚拟机网络速度更快读取速度更快

做完实验后将备份的网络配置取代实验修改的网络配置,重启重置配置


四、临时桥接接口管理(虚拟机)

1、建立桥接接口网络br0

建立桥接接口

brctl addbr br0

查看主机桥接信息

brctl show

查看网卡信息

ifconfig

给桥接接口IP

ifconfig br0 172.25.254.100/24
ifconfig br0

尝试连接其他主机:不通

桥接物理网卡

brctl addif br0 eth0
brctl show

尝试连接其他主机:通

2、删除桥接接口网络br0

删除桥接接口的网卡信息

关闭桥接接口

ifconfig br0 down
ifconfig


删除桥接接口

brctl delbr br0 
brctl show


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值