Linux下的高级网络配置

阅读: 评论:0

Linux下的高级网络配置

Linux下的高级网络配置

Linux下的高级网络配置

1.链路聚合接口-bond

我们之前配置网卡时,每个ip都只有一个相对应的网卡。但如果网卡忽然坏掉,网络就会随之断开。此时我们就需要多添加一块网卡,让它作为“替补”,当第一块网卡坏掉的瞬间,它去代替第一块网卡继续工作,保证网络不会断开

配置bond:

- step1 在虚拟机中添加一块网卡
打开u虚拟机管理器- - ->>>-选择需要设定的虚拟机- - ->>>点击“灯泡”样式的图标- - ->>>点击添加- - ->>>选择网卡- - ->>>选择virtio- - ->>>apply应用- - ->>>打开虚拟机

ifconfig 										##可查看到多了一个eth1网卡




- step2 删除之前设定的eth0网络(如果没有设定可自动忽略)

nmcli connection show
nmcli connection delete System eth0			##删除eth0
nmcli connection show							##查看到eth0已经被删除


- step3 为了更加清楚的看到实验效果,打开监控界面

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


- step4 配置网络

nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.70.50/24	##添加bond
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0		##添加eth0到bond
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0		##添加eth1到bond




- step5 测试

ifconfig eth0 down	##关闭eth0时eth1立刻接替eth0的工作仍然能ping通172.25.70.250
ifconfig eth0 up	##打开eth0,但此时工作的是eth1
ifconfig eth1 down	##关闭eth1,此时eth0接替eth1继续工作



2.链路聚合接口-team

该接口与bond接口功能类似,但该接口可以支持八块网卡,不需要手动加载相应内核模块
该接口比bond接口多一个模式。loadbalance负载均衡模式:该模式判断不同网卡的负载,给负载最少的网卡发送数据包

配置team:

- step1 删除刚刚实验中添加的bond和eth0 eth1

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


- step2 为了更加清楚的看到实验效果,打开监控界面

ping 172.25.70.250
watch -n 1 teamdctl team0 state


- step3 配置网络

nmcli connecion add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.70.50/24		##添加team
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0		##添加eth0
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0		##添加eth1




- step4 测试

ifconfig eth0 down		##关闭eth0时,eth1立刻接替eth0的工作。仍然能ping通172.25.70.250
ifconfig eth0 up		##打开eth0,但此时工作的是eth1
ifconfig eth1 down		##关闭eth1,此时eth0接替eth1继续工作



3.网络桥接的配置

桥接的作用:连接两个不同直接通信的接口

实验步骤:
step1 在真机中删除所有网卡

cd /etc/sysconfig/network-scripts/
ls									##删除除了ifcfg-lo以外的所有ifcfg-的文件
vim ifcfg-wlp2s0					##配置物理网卡
DEVICE=wlp2s0
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.25.70.250
NETMASK=255.255.255.0
systemctl restart network			##重启网络

测试:
桥接安装虚拟机要比没有桥接快





安装完成后没有桥接时的网卡:Virtual network ‘default’:NAT

kvm虚拟化功能,内核控制网卡。虚拟机信息要发出去经过以下过程:
虚拟主机内核- - ->>>虚拟主机接口- - ->>>真实主机内核—>>>真实主机接口


设置物理网卡wlp2s0:

vim ifcfg-wlp2s0
DEVICE=wlp2s0
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0

设置br0:

vim ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.36
NETMASK=255.255.255.0
TYPE=Bridge       
systemctl restart network   

测试:
设置桥接后安装虚拟机的速度变快
安装完成后有桥接时的网卡:

选择Send Key F2,输入ifconfig,可以看到桥接成功之后会分配新建的虚拟机一个和真机ip处于相同网段的ip

4.网络桥接的管理命令

在虚拟机中:
首先把配好的eth0删掉

nmcli connection show
nmcli connection delete System eth0

- 添加br0:

brctl addbr br0				##添加br0
brcrl show					##查看br0情况
ifconfig br0 172.25.70.50/24
ping 172.25.70.250			##ping不通
brctl addif br0 eth0		##把br0和eth0连接
brctl show
ping 172.25.70.250			##可ping通

- 删除br0:

ifconfig br0 down			##关闭br0
brctl show					##查看br0情况
brctl delif br0 eth0		##把br0和eth0连接断开
brctl show
brctl delbr br0				##删除br0

本文发布于:2024-02-04 06:57:06,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170701591053387.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:高级   网络   Linux
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23