配置网卡服务
9.1 配置网卡服务
9.1.1 配置网卡参数
[root@redhat ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=97486c86-6d1e-4e99-9aa2-68d3172098b2
DEVICE=ens160
ONBOOT=yes
HWADDR=00:0C:29:7D:27:BF
IPADDR=192.168.30.10
PREFIX=24
IPV6_PRIVACY=no
[root@redhat ~]# nmcli connection reload ens160
[root@redhat ~]# nmcli connection up ens160
[root@redhat ~]# ping 192.168.30.10
9.1.2 创建网络会话
nmcli是一款基于命令行的网络配置工具
[root@redhat ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens160 97486c86-6d1e-4e99-9aa2-68d3172098b2 ethernet ens160
virbr0 e5fca1ee-7020-4c21-a65b-259d0f993b44 bridge virbr0
[root@redhat ~]# nmcli connection show ens160
9.1.3 绑定两块网卡
1.创建出一个bond网卡
首先使用如下命令创建一个bond网卡。其中,命令与参数的意思是创建一个类型为bond(绑定)、名称为bond0、网卡名为bond0的绑定设备,绑定模式为balance-rr:
[root@redhat ~]# nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-rr"
Connection 'bond0' (06f77a12-1e10-4acc-a055-fbc02ca5b7d8) successfully added.
2.向bond0添加从属网卡
刚才创建成功的bond0设备当前仅仅是个名称,里面并没有真正能为用户传输数据的网卡设备,接下来使用下面的命令把ens38和ens39网卡添加进来。其中,con-name参数后面接的是从属网卡的名称(可以随时设置);ifname参数后面接的是两块网卡的名称
[root@redhat network-scripts]# ifconfig
[root@redhat network-scripts]# nmcli connection add type ethernet slave-type bond con-name bond0-port1 ifname ens38 master bond0
Connection 'bond0-port1' (257e65e4-e265-4a31-91b4-959dffadde95) successfully added.
[root@redhat network-scripts]# nmcli connection add type ethernet slave-type bond con-name bond0-port2 ifname ens39 master bond0
Connection 'bond0-port2' (c34e6344-2830-455e-a7f4-5490e479fd61) successfully added.
3.配置bond0设备的网卡信息
下面还是用nmcli命令依次配置网络的IP地址及子网掩码、网关、DNS、搜索域和手动配置等参数
[root@redhat ~]# nmcli connection modify bond0 ipv4.addresses 192.168.30.30/24
[root@redhat ~]# nmcli connection modify bond0 ipv4.gateway 192.168.30.1
[root@redhat ~]# nmcli connection modify bond0 ipv4.dns 192.168.30.1
[root@redhat ~]# nmcli connection modify bond0 ipv4.method manual
4.启动
[root@redhat network-scripts]# nmcli connection up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
查看状态
[root@redhat network-scripts]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
bond0 bond connected bond0
virbr0 bridge connected virbr0
ens38 ethernet connected bond0-port1
ens39 ethernet connected bond0-port2
lo loopback unmanaged --
virbr0-nic tun unmanaged --
当用户接下来访问主机IP地址192.168.30.30时,主机实际上是由两块网卡在共同提供服务。可以在本地主机执行ping 192.168.30.30命令检查网络的连通性。
为了检验网卡绑定技术的自动备援功能,可以突然在虚拟机硬件配置中随机移除一块网卡设备,如图9-13所示。
ping 192.168.30.30
[root@redhat network-scripts]# ping 192.168.30.30
PING 192.168.30.30 (192.168.30.30) 56(84) bytes of data.
64 bytes from 192.168.30.30: icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from 192.168.30.30: icmp_seq=2 ttl=64 time=0.106 ms
64 bytes from 192.168.30.30: icmp_seq=3 ttl=64 time=0.100 ms
64 bytes from 192.168.30.30: icmp_seq=4 ttl=64 time=0.036 ms
64 bytes from 192.168.30.30: icmp_seq=5 ttl=64 time=0.041 ms
64 bytes from 192.168.30.30: icmp_seq=6 ttl=64 time=0.037 ms
64 bytes from 192.168.30.30: icmp_seq=7 ttl=64 time=0.035 ms
64 bytes from 192.168.30.30: icmp_seq=8 ttl=64 time=0.038 ms
64 bytes from 192.168.30.30: icmp_seq=9 ttl=64 time=0.048 ms
64 bytes from 192.168.30.30: icmp_seq=10 ttl=64 time=0.035 ms
64 bytes from 192.168.30.30: icmp_seq=11 ttl=64 time=0.610 ms
64 bytes from 192.168.30.30: icmp_seq=12 ttl=64 time=0.038 ms
64 bytes from 192.168.30.30: icmp_seq=13 ttl=64 time=0.038 ms
64 bytes from 192.168.30.30: icmp_seq=14 ttl=64 time=0.053 ms
网卡绑定切换间隔为1毫秒(也就是1/1000秒),因此发生一个丢包的情况大概率不会出现。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。