本文共 6907 字,大约阅读时间需要 23 分钟。
实验1
网卡支持多会话功能,由于工作环境不同,需要配置不同的网络:如在家里使用使用DHCP获取,在公司使用固定ip,如果使用修改方式比较麻烦,配置多会话功能,在不同场景激活即可。实验环境:centos7、home:DHCP、company:static,自动连接配置过程:配置信息会保存至/etc/sysconfig/network-scripts/ifcfg-name[root@xt ~]# nmcli connection add con-name company autoconnect yes ifname ens36 type ethernet Connection 'company' (46f14092-152e-4af3-9273-5acbf573b2a2) successfully added.[root@xt ~]# nmcli connection add con-name home autoconnect no ifname ens36 type ethernet Connection 'home' (d3c8a326-e494-47b9-b6ea-92f18998b9b6) successfully added.[root@xt ~]# nmcli connection show NAME UUID TYPE DEVICE eno16777736 2361aff4-2de8-4868-9fd6-5d30ccdada02 802-3-ethernet eno16777736 home d3c8a326-e494-47b9-b6ea-92f18998b9b6 802-3-ethernet -- company 46f14092-152e-4af3-9273-5acbf573b2a2 802-3-ethernet ens36 [root@xt ~]# nmcli device status DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 ens36 ethernet connected company lo loopback unmanaged --
修改IP地址
如果不修改默认为自动分配;[root@xt ~]# nmcli connection modify company ipv4.addresses 172.16.0.10/16 ipv4.method manual 还可以配置DNS、gateway...[root@xt ~]# systemctl restart network #重启服务 [root@xt ~]# nmcli device status #ens36当前自动连接至company会话DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 ens36 ethernet connected company lo loopback unmanaged -- [root@xt ~]# ifconfig ens36 #ens36的ip信息配置正常ens36: flags=4163mtu 1500 inet 172.16.0.10 netmask 255.255.0.0 broadcast 172.16.255.255 inet6 fe80::20c:29ff:fe20:b507 prefixlen 64 scopeid 0x20 ether 00:0c:29:20:b5:07 txqueuelen 1000 (Ethernet) RX packets 187 bytes 23730 (23.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 88 bytes 10998 (10.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@xt ~]# nmcli connection up home #将网卡会话切换至home会话Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)[root@xt ~]# nmcli device status DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 ens36 ethernet connected home #ens36当前会话状态lo loopback unmanaged -- [root@xt ~]# ifconfig ens36 #此时ip信息是自动获取ens36: flags=4163 mtu 1500 inet 192.168.175.133 netmask 255.255.255.0 broadcast 192.168.175.255 inet6 fe80::20c:29ff:fe20:b507 prefixlen 64 scopeid 0x20 ether 00:0c:29:20:b5:07 txqueuelen 1000 (Ethernet) RX packets 190 bytes 24476 (23.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 98 bytes 12306 (12.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
实验2:网卡绑定
1.配置两块网卡信息:设置主卡为bond0,[root@xt test]# cat ifcfg-ens36TYPE="Ethernet"BOOTPROTO="none"DEVICE="ens36" #修改第二块网卡的名称ONBOOT="yes"MASTER=bond0SLAVE=yes
2.创建绑定 网卡的配置文件并指定ip地址等信息
[root@xt test]# cat ifcfg-bond0TYPE="Ethernet"BOOTPROTO="none"NAME=bond0DEVICE=bond0ONBOOT="yes"IPADDR=192.168.0.10PREFIX=24DNS=192.168.0.1NM_CONTROLLED=no
3.让内核支持bonding驱动
vim /etc/modprobe.d/bond.confalias bond0 bondingoptions bond0 miimon=100 mode=6说明:miimon是用来进行链路监测的。 比如:miimon=100,那么系统会100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;
4.重启服务
$ nmcli con add type bond ifname mybond0 mode active-backup $ nmcli con add type bond-slave ifname eth1 master mybond0$ nmcli con add type bond-slave ifname eth2 master mybond0$再modify mybond0 ip相关信息,或者一开始添加常用模式:mode=0 |balance-rr:平衡负载,同时工作且自动备援,但需要”Switch”支援及设定mode=1:自动备援模式,只有一块网卡工作,故障后自动切换mode=6:平均负载均衡模式,且自动备援,但无需”Switch”支援及设定 #nmcli connection add autoconnect no type bond mode balance-alb ip4 192.168.10.10/24 gw4 192.168.10.1 autoconnect no-->ONBOOT=no
[root@xt test]# nmcli -p connection show bond =============================================================================== Connection profile details (bond)===============================================================================connection.id: bondconnection.uuid: 56802b0b-824e-4c76-8562-94ad43661d56connection.interface-name: nm-bondconnection.type: bondconnection.autoconnect: noconnection.autoconnect-priority: 0connection.timestamp: 0connection.read-only: noconnection.permissions: connection.zone: --connection.master: --connection.slave-type: --connection.autoconnect-slaves: -1 (default)connection.secondaries: connection.gateway-ping-timeout: 0connection.metered: unknown-------------------------------------------------------------------------------ipv4.method: manualipv4.dns: ipv4.dns-search: ipv4.addresses: 192.168.10.10/24ipv4.gateway: 192.168.10.1ipv4.routes: ipv4.route-metric: -1ipv4.ignore-auto-routes: noipv4.ignore-auto-dns: noipv4.dhcp-client-id: --ipv4.dhcp-send-hostname: yesipv4.dhcp-hostname: --ipv4.never-default: noipv4.may-fail: yes-------------------------------------------------------------------------------ipv6.method: autoipv6.dns: ipv6.dns-search: ipv6.addresses: ipv6.gateway: --ipv6.routes: ipv6.route-metric: -1ipv6.ignore-auto-routes: noipv6.ignore-auto-dns: noipv6.never-default: noipv6.may-fail: yesipv6.ip6-privacy: -1 (unknown)ipv6.dhcp-send-hostname: yesipv6.dhcp-hostname: ---------------------------------------------------------------------------------bond.options: mode=balance-alb-------------------------------------------------------------------------------
重启服务生效:生成 配置文件永久有效:
[root@xt network-scripts]# cat ifcfg-bondDEVICE=nm-bondBONDING_OPTS=mode=balance-albTYPE=BondBONDING_MASTER=yesBOOTPROTO=noneIPADDR=192.168.10.10PREFIX=24GATEWAY=192.168.10.1DEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noNAME=bondUUID=523b6b71-9151-4887-877d-7c0bfa55e489ONBOOT=no
转载于:https://blog.51cto.com/12580678/2339170