linux-网络管理

网络管理

网卡命名

传统网卡命令机制

传统命名:
以太网eth[0,1,2,…]
wlan[0,1,2,…]

网络接口名称组成格式

基于固件、设备结构、设备类型

  • 由两个字母开头标示固件
    • 以太网网卡以 en 开头
    • 无线网卡以 wl 开头
  • 设备结构
    • o:主板上集成的设备的设备索引号
    • s:扩展槽的索引号
    • x:基于MAC地址的命名
    • ps:基于物理位置拓扑的命名。如enp2s1,表示PCI总线上第2个总线的第1个插槽的设备索引号
RedHat9配置网卡(动态)
#修改配置文件
[root@zyq ~]# cd /etc/sysconfig/network-scripts/
[root@zyq network-scripts]# ls
readme-ifcfg-rh.txt
[root@zyq network-scripts]# vim ifcfg-eth0
[root@zyq network-scripts]# cat ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=eth0
DEVICE=eth0
ONBOOT=yes
[root@zyq network-scripts]#

#编辑/etc/default/grub配置文件,在以GRUB_CMDLINE_LINUX开头的行内rhgb的前面加上net.ifnames=0 biosdevname=0
[root@zyq ~]# vim /etc/default/grub 
[root@zyq ~]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true

#为grub2生成其配置文件
[root@zyq ~]# grub2-mkconfig -o /etc/grub2.cfg 
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...
done
[root@zyq ~]# 

#重启系统
[root@zyq ~]# reboot

网络管理常用命令

ifconfig
在redhat9 需下载命令
[root@zyq ~]# yum -y install net-tools

#下载完成后查看命令路径
[root@zyq ~]# which ifconfig
/usr/sbin/ifconfig
[root@zyq ~]#


ifconfig #查看当前处于活动状态的所有网络接口
[root@zyq ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.227.129  netmask 255.255.255.0  broadcast 192.168.227.255
        inet6 fe80::20c:29ff:fe83:2549  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:83:25:49  txqueuelen 1000  (Ethernet)
        RX packets 263  bytes 28719 (28.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 220  bytes 22245 (21.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3  bytes 588 (588.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 588 (588.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0





#网卡配置信息含义如下:
UP: 网卡处于活动状态
BROADCAST: 支持广播
RUNNING: 网线已接入
MULTICAST: 支持组播
MTU: 最大传输单元(字节),即此接口一次所能传输的最大封包

inet: 显示IPv4地址行
inet6: 显示IPv6地址行
link/enther: 指设备硬件(MAC)地址
txqueuelen: 传输缓存区长度大小
RX packets: 接收的数据包
TX packets: 发送的数据包
errors: 总的收包的错误数量
dropped: 由于各种原因, 导致拷贝在内存过程中被丢弃
collisions: 网络信号冲突情况, 值不为0则可能存在网络故障
ip
#语法:ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT:
    link:网络接口属性
    addr:协议地址
    route:路由 
    
    
#查看网络接口所有地址
[root@zyq ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:83:25:49 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    altname ens160
[root@zyq ~]#

#显示报文统计信息
[root@zyq ~]# ip -s link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX:  bytes packets errors dropped  missed   mcast           
           588       3      0       0       0       0 
    TX:  bytes packets errors dropped carrier collsns           
           588       3      0       0       0       0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:83:25:49 brd ff:ff:ff:ff:ff:ff
    RX:  bytes packets errors dropped  missed   mcast           
         36521     353      0       0       0       0 
    TX:  bytes packets errors dropped carrier collsns           
         30755     299      0       0       0       0 
    altname enp3s0
    altname ens160
[root@zyq ~]#

#启用或禁用网络接口ip link set DEV {up|down}
[root@zyq ~]#ip link set lo down
[root@zyq ~]#ip link set lo up

#ip addr add ADDRESS dev DEV:添加IP地址
[root@zyq ~]#ip addr show eth0

#ip addr del ADDRESS dev DEV:删除IP地址
[root@zyq ~]#ip addr show eth0

route

Linux主机之间是使用IP进行通信, 假设A主机和B主机同在一个网段内且网卡都处于激活状态, 则A具备和B直接通信的能力, 但如果A主机和B主机处于两个不同的网段, 则A必须通过路由器才能和B通信, 路由器属于IT设备的基础设施, 每一个网段都应该至少有一个网关

#查看当前路由表
[root@zyq ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 eth0
192.168.227.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0
[root@zyq ~]#

#以数字方式显示各主机或端口等相关信息
[root@zyq ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.227.2   0.0.0.0         UG    100    0        0 eth0
192.168.227.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0
[root@zyq ~]#

#增加路由
#语法:route add [-net|-host] target [netmask Nm] [gw Gw]  [[dev] If]


RedHat9配置网卡(静态)
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes           #必须设置为yes
IPADDR=172.168.227.129
NETMASK=255.255.255.0
GATEWAY=172.168.227.2
DNS1=172.168.227.2

#网卡配置说明
#参数                    说明
BOOTPROTO=none          #引导协议,可选值有{static|none|dhcp|bootp}。如果要使用静态地址,使用static或none都可以
NM_CONTROLLED           #NM是NetworkManager的简写,NM是由RHEL研发的在RHEL6中取代network脚本来实现网络管理、配置的服务脚本
    #可选值有{ yes | no }
    #此项是设定此网卡是否接受NM控制。CentOS6建议设为“no”
TYPE                    #接口类型。常见的接口类型有:Ethernet,Bridge
UUID                    #设备的惟一标识
HWADDR                  #硬件地址,要与硬件中的地址保持一致,可省
IPADDR=172.168.227.129    #固定IP地址
PREFIX=24               #子网掩码
NETMASK=255.255.255.0   #子网掩码
GATEWAY=172.168.227.2     #默认网关
DNS1=172.168.227.2        #第一个DNS服务器指向
DNS2                    #第二个DNS服务器指向
DNS3                    #第三个DNS服务器指向
DEVICE=eth0             #关联的设备名称,要与文件名的后半部"INTERFACE_NAME"保持一致  
NAME="eth0"             #连接名称
ONBOOT=yes              #在系统引导时是否自动激活此网络接口,可选值有{ yes | no }
DEFROUTE=yes            #将接口设定为默认路由[yes|no]
USERCTL={yes|no}        #是否允许普通用户控制此接口的启用与禁用
PEERDNS={yes|no}        #是否在BOOTPROTO为dhcp时接受由dhcp服务器指定的DNS地址,此项设为yes时获得的DNS地址将直接覆盖至/etc/resolv.conf文件中

网络检测工具与故障排查

ping

ping命令的目的在于测试另一台主机是否可达, 如果ping不到某台主机,就说明对方主机已经出现了问题, 但是不排除由于链路中的防火墙、ping被丢弃等原因造成ping不通的情况

#ping命令常用选项:
    -c 指定ping的次数
[root@zyq ~]# ping -c 3 www.baidu.com
PING www.a.shifen.com (182.61.200.6) 56(84) bytes of data.
64 bytes from localhost (182.61.200.6): icmp_seq=1 ttl=128 time=163 ms
64 bytes from localhost (182.61.200.6): icmp_seq=2 ttl=128 time=35.5 ms
64 bytes from localhost (182.61.200.6): icmp_seq=3 ttl=128 time=243 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 35.543/147.465/243.497/85.637 ms
[root@zyq ~]#


    -i 指定ping包的发送间隔
    -w 如果ping没有回应, 则在指定超时时间后退出
host与nslookup

host nslookup用于查询DNS记录

#查找系统是否存在此命令
which host
#若不存在,查看需下载包名,随后yum下载即可
yum provides *bin/host #接命令

[root@zyq ~]# host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 182.61.200.6
www.a.shifen.com has address 182.61.200.7
[root@zyq ~]# nslookup www.baidu.com
Server:		192.168.227.2
Address:	192.168.227.2#53

Non-authoritative answer:
www.baidu.com	canonical name = www.a.shifen.com.
Name:	www.a.shifen.com
Address: 182.61.200.6
Name:	www.a.shifen.com
Address: 182.61.200.7

netstat

netstat用于查看网络状态

#显示路由表
[root@zyq ~]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 eth0
192.168.227.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
[root@zyq ~]#

#以数字方式显示路由表
[root@zyq ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.227.2   0.0.0.0         UG        0 0          0 eth0
192.168.227.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
[root@zyq ~]#

#显示建立的TCP链接
[root@zyq ~]# netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0     68 zyq:ssh                 192.168.227.1:59320     ESTABLISHED
[root@zyq ~]#

#显示建立的UDP链接
[root@zyq ~]# netstat -u
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 zyq:bootpc              192.168.227.254:bootps  ESTABLISHED
[root@zyq ~]#


网络进阶管理

链路聚合

将多块网卡连接起来,当一块网卡损坏,网络依旧可以正常运行

可以有效的防止因为网卡损坏带来的损失

同时也可以提高网络访问速度

网卡的链路聚合方式:
  • bond:最多可以添加两块网卡
  • team:最多可以添加八块网卡
bond的常用的2种模式:
  • bond0(balance-rr)
    • bond0用于负载轮询(2个网单独都是100MB,聚合为1个网络传输带宽为200MB)
  • bond1(active-backup)
    • bond1用于高可用,其中一条线若断线,其他线路将会自动备援
                            --> eth0  ----\
    app  --发送数据到--> bond0          <---> switch 
                            --> eth1  ----/

链路聚合配置

配置bond聚合链路
配置bond0
新添加一块网卡
[root@zyq ~]#: nmcli device 
DEVICE  TYPE      STATE      CONNECTION         
ens160  ethernet  connected  ens160             
ens192  ethernet  connected  Wired connection 1 
lo      loopback  unmanaged  --  

[root@zyq ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:dc:6a:51 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.227.150/24 brd 192.168.227.255 scope global dynamic noprefixroute ens160
       valid_lft 1773sec preferred_lft 1773sec
    inet6 fe80::20c:29ff:fedc:6a51/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:dc:6a:5b brd ff:ff:ff:ff:ff:ff
    altname enp11s0
    inet 192.168.227.151/24 brd 192.168.227.255 scope global dynamic noprefixroute ens192
       valid_lft 1773sec preferred_lft 1773sec
    inet6 fe80::feb8:69a6:a815:3704/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
       
创建bond0 模式为balance-rr
[root@zyq ~]#: nmcli connection add type bond mode balance-rr con-name bond0 ifname bond0 ipv4.method manual ipv4.addresses 192.168.227.149/24 ipv4.gateway 192.168.227.2 ipv4.dns 192.168.227.2
Connection 'bond0' (70b36ca4-0bd1-44f9-8217-12b7f103d2c6) successfully added.

添加物理网卡连接至bond0
[root@zyq ~]#: nmcli  connection add type bond-slave con-name bond-slave0 ifname ens160 master bond0
Connection 'bond-slave0' (255862cf-54a1-4e47-b726-dab2be83f810) successfully added.
[root@zyq ~]#: nmcli  connection add type bond-slave con-name bond-slave1 ifname ens192 master bond0
Connection 'bond-slave1' (65dca1a7-3ba5-4f33-afee-5aa053905f97) successfully added.
[root@zyq ~]# nmcli conn down "Wired connection 1"
Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@zyq ~]# nmcli conn down "Wired connection 2"
Connection 'Wired connection 2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

查看bond配置信息
[root@zyq ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v5.14.0-162.6.1.el9_1.0.1.x86_64

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:dc:6a:5b
Slave queue ID: 0

关闭ens160网卡, 测试bond0是否正常
[root@zyq ~]# nmcli connection
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
bond0               ab4aba0a-fc54-46d1-87f0-3e3cce0f89bd  bond     >
bond-slave1         7f193378-d169-41ef-927b-ed9dd1c63e4f  ethernet >
bond-slave0         68086b3c-5857-46dc-ae03-5fab24df345b  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet >
[root@zyq ~]# nmcli connection down bond-slave1
Connection 'bond-slave1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)

[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
bond0               ab4aba0a-fc54-46d1-87f0-3e3cce0f89bd  bond     >
bond-slave0         68086b3c-5857-46dc-ae03-5fab24df345b  ethernet >
bond-slave1         7f193378-d169-41ef-927b-ed9dd1c63e4f  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet 


配置bond1

[root@zyq ~]# nmcli connection delete bond0
Connection 'bond0' (ab4aba0a-fc54-46d1-87f0-3e3cce0f89bd) successfully deleted.
[root@zyq ~]# nmcli connection delete bond-slave0
Connection 'bond-slave0' (68086b3c-5857-46dc-ae03-5fab24df345b) successfully deleted.
[root@zyq ~]# nmcli connection delete bond-slave1
Connection 'bond-slave1' (7f193378-d169-41ef-927b-ed9dd1c63e4f) successfully deleted.
[root@zyq ~]# nmcli connection
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet 

创建
[root@zyq ~]# nmcli connection add type bond mode balance-rr con-name bond1 ifname bond1 ipv4.method manual ipv4.addresses 192.168.227.149/24 ipv4.gateway 192.168.227.2 ipv4.dns 192.168.227.2
Connection 'bond1' (10f387ba-ed92-4185-9378-abe17853894a) successfully added.
[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
bond1               10f387ba-ed92-4185-9378-abe17853894a  bond     >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet 

将物理网卡添加至bond1
[root@zyq ~]# nmcli  connection add type bond-slave con-name bond-slave0 ifname ens160 master bond1
Connection 'bond-slave0' (dec9f82b-b478-481c-ae18-9db13a532d17) successfully added.
[root@zyq ~]# nmcli  connection add type bond-slave con-name bond-slave1 ifname ens160 master bond1
Connection 'bond-slave1' (44c868e0-37b4-4d18-ad0a-9996efefb9ad) successfully added.

查看
[root@zyq ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-162.6.1.el9_1.0.1.x86_64

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:dc:6a:5b
Slave queue ID: 0

启动bond1
[root@zyq ~]# nmcli connection up bond1
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)

停止ens160物理网卡设备
[root@localhost ~]# nmcli device disconnect ens160
Device 'ens160' successfully disconnected.
物理网卡设备会进行自动切换
[root@zyq ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-162.6.1.el9_1.0.1.x86_64

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:dc:6a:5b
Slave queue ID: 0

断开并删除物理网卡
[root@zyq ~]# nmcli connection down bond-slave1
[root@zyq ~]# nmcli connection down bond-slave0
[root@zyq ~]# nmcli connection down bond1
Connection 'bond1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[root@zyq ~]# nmcli connection down bond1
Connection 'bond1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[root@zyq ~]# nmcli connection delete bond1
Connection 'bond1' (10f387ba-ed92-4185-9378-abe17853894a) successfully deleted.
[root@zyq ~]# nmcli connection delete bond-slave0
Connection 'bond-slave0' (dec9f82b-b478-481c-ae18-9db13a532d17) successfully deleted.
[root@zyq ~]# nmcli connection delete bond-slave1
Connection 'bond-slave1' (dac705d4-ec5e-4c72-8483-bb76600cab29) successfully deleted.
配置team聚合链路

使用teaming实现聚合链路,能够提供网卡绑定之后的网络吞吐性能,并且提供网卡的故障切换处理能力。
Team是基于一个小型内核驱动实现聚合链路,在用户层提供teamd命令实现链路管理。

teamd可以实现以下模式的聚合链路

broadcast 广播容错
roundrobin 负载轮询
activebackup 主备(必考)
loadbalance 负载均衡
lacp 需要交换机支持lacp协议

[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet >

创建team0
[root@zyq ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' ipv4.addresses 192.
168.227.149/24 ipv4.gateway 192.168.227.2 ipv4.dns 192.168.227.2 ipv4.method manual
Connection 'team0' (12ae94df-8eb9-4715-8c1d-69ef8dabf003) successfully added.
[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
team0               12ae94df-8eb9-4715-8c1d-69ef8dabf003  team     >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet >

添加物理网卡连接至team0
[root@zyq ~]# nmcli connection add type team-slave con-name team0-port1 ifname ens160  master team0
Connection 'team0-port1' (1935f605-487c-44b6-88cf-5352b072fcf3) successfully added.
[root@zyq ~]# nmcli connection add type team-slave con-name team0-port2 ifname ens192 master team0
Connection 'team0-port2' (8fdcaf3b-2e20-48e0-bdaa-c9faa4890003) successfully added.
[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
team0               12ae94df-8eb9-4715-8c1d-69ef8dabf003  team     >
team0-port2         8fdcaf3b-2e20-48e0-bdaa-c9faa4890003  ethernet >
team0-port1         1935f605-487c-44b6-88cf-5352b072fcf3  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet >

检查team0状态
[root@zyq ~]# ping -I team0 192.168.227.149
PING 192.168.227.149 (192.168.227.149) from 192.168.227.149 team0: 56(84) bytes of data.
64 bytes from 192.168.227.149: icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from 192.168.227.149: icmp_seq=2 ttl=64 time=0.057 ms
^C
--- 192.168.227.149 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.035/0.046/0.057/0.011 ms
[root@zyq ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens192
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens192
  
断掉后检测
[root@zyq ~]# nmcli dev disconnect ens160
[root@zyq ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens192
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens192

动态修改team模式

导出配置进行修改 (man teamd.conf)
[root@zyq ~]# teamdctl team0 config dump > /tmp/team.conf~
[root@zyq ~]# cat /tmp/team.conf~ 
{
    "device": "team0",
    "mcast_rejoin": {
        "count": 1
    },
    "notify_peers": {
        "count": 1
    },
    "ports": {
        "ens192": {
            "link_watch": {
                "name": "ethtool"
            }
        }
    },
    "runner": {
        "name": "activebackup"
    }
}

以最新修改的配置选项修改team0属性
[root@zyq ~]# nmcli con mod team0 team.config /tmp/team.conf~ 

修改之后需要重启team0
[root@zyq ~]# nmcli connection down team0
[root@zyq ~]# nmcli connection up team0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/25)

[root@zyq ~]# nmcli conn
NAME                UUID                                  TYPE     >
team0               12ae94df-8eb9-4715-8c1d-69ef8dabf003  team     >
team0-port1         1935f605-487c-44b6-88cf-5352b072fcf3  ethernet >
team0-port2         8fdcaf3b-2e20-48e0-bdaa-c9faa4890003  ethernet >
ens160              b4c3cfea-c8f9-3eea-a44c-a01296f4704e  ethernet >
Wired connection 1  953e9f3f-5568-36da-a694-097f80fdb03c  ethernet >
Wired connection 2  541c79b2-b230-3b36-ad72-767867638362  ethernet >
  • 21
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值