linux基礎(chǔ)之網(wǎng)絡(luò)篇第四章nmcli綁定

  • nmcli 上篇已經(jīng)介紹了創(chuàng)建網(wǎng)卡配置,網(wǎng)卡切換等
  • 在CentOS7里面如何實(shí)現(xiàn)多網(wǎng)卡綁定
  • 也可以修改文件,這里是用命令
  • 我們先定義一個(gè)IP:我定義的是172.17.250.89
  • ping下IP,他是不通的
[root@localhost ~]# ping 172.17.250.89
PING 172.17.250.89 (172.17.250.89) 56(84) bytes of data.
From 172.17.254.78 icmp_seq=2 Destination Host Unreachable
From 172.17.254.78 icmp_seq=3 Destination Host Unreachable
From 172.17.254.78 icmp_seq=4 Destination Host Unreachable
From 172.17.254.78 icmp_seq=6 Destination Host Unreachable
From 172.17.254.78 icmp_seq=7 Destination Host Unreachable
From 172.17.254.78 icmp_seq=8 Destination Host Unreachable

nmcli綁定

  • 首先我們先用命令來生成配置文件 ,用命令nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup
[root@localhost ~]# nmcli connection add  type bond con-name bond0 ifname bond0 mode active-backup 
Connection 'bond0' (282d8832-e1ea-43de-b769-fae4b26d7244) successfully added.
  • 來查看下配置生成了沒有,使用命令nmcli connection show,下面的bond0就是我們生成的文件
[root@localhost ~]# nmcli connection show 
NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  d2444c8a-2a16-3338-9558-5920b573bc91  802-3-ethernet  eth0   
Wired connection 2  679bea27-b8ed-3e8e-94a5-62329f148f3e  802-3-ethernet  eth1   
Wired connection 3  d094d2c1-6fac-3b62-81c8-4bbae33bbc12  802-3-ethernet  eth2   
bond0               282d8832-e1ea-43de-b769-fae4b26d7244  bond                
ens33               d5b2a714-b9f6-44dc-9724-45d60edbde62  802-3-ethernet  --     
ens34               a688a753-ba50-416b-bd37-02d240901857  802-3-ethernet  --    
  • 我們?cè)趤聿榭聪滤母袷?/li>
[root@localhost network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=282d8832-e1ea-43de-b769-fae4b26d7244
ONBOOT=yes
  • 接下來我們給他配地址m,使用命令 nmcli connection modify bond0 ipv4.method manual ipv4.addresses 172.17.250.89/24
[root@localhost network-scripts]# nmcli connection modify  bond0 ipv4.method manual ipv4.addresses  172.17.250.89/24
  • 在來查看下網(wǎng)卡配置狀態(tài)
[root@localhost network-scripts]# cat ifcfg-bond0
DEVICE=bond0
TYPE=Bond
BONDING_MASTER=yes
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=bond0
UUID=282d8832-e1ea-43de-b769-fae4b26d7244
ONBOOT=yes
BONDING_OPTS=mode=active-backup
IPADDR=172.17.250.89
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
  • 查看下地址,沒有獲取到IP不能ping通,只是配置文件里面有IP
[root@localhost network-scripts]# ifconfig
bond0: flags=5123<UP,BROADCAST,MASTER,MULTICAST>  mtu 1500
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下來我們使用nmcli connection up bond0命令讓配置文件生效
[root@localhost network-scripts]# nmcli connection up bond0
  • 查看下配置文件,bond0已經(jīng)生效里面已經(jīng)有了IP,我們看看他是否通了
[root@localhost ~]# ifconfig
bond0: flags=5123<UP,BROADCAST,MASTER,MULTICAST>  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 查看下,另外一臺(tái)電腦是否ping通
  • 已經(jīng)ping通
[root@localhost ~]# ping 172.17.250.89
PING 172.17.250.89 (172.17.250.89) 56(84) bytes of data.
64 bytes from 172.17.250.89: icmp_seq=1 ttl=64 time=0.758 ms
64 bytes from 172.17.250.89: icmp_seq=2 ttl=64 time=0.753 ms
64 bytes from 172.17.250.89: icmp_seq=3 ttl=64 time=0.471 ms
64 bytes from 172.17.250.89: icmp_seq=4 ttl=64 time=1.06 ms
64 bytes from 172.17.250.89: icmp_seq=5 ttl=64 time=0.487 ms
64 bytes from 172.17.250.89: icmp_seq=6 ttl=64 time=0.429 ms
  • 現(xiàn)在只是給他IP 還沒有給他綁定物理網(wǎng)卡,他沒有容錯(cuò)功能
  • 接下來把eth0和eth1綁定到bond0里面
[root@localhost ~]# ifconfig
bond0: flags=5123<UP,BROADCAST,MASTER,MULTICAST>  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.128  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::a29b:8116:eaca:f436  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 885  bytes 89264 (87.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 465  bytes 63242 (61.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.254.77  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::edc6:9ab6:837e:b8f7  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:52:72:dc  txqueuelen 1000  (Ethernet)
        RX packets 39525  bytes 3170826 (3.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5186  bytes 535096 (522.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 我們用nmcli connection add type bond-slave ifname eth0 master命令來執(zhí)行,添加eth0和eth1
[root@localhost ~]# nmcli  connection add  type  bond-slave  ifname eth0 master bomd0
Warning: master='bomd0' doesn't refer to any existing profile.
Connection 'bond-slave-eth0-1' (5d1bf5be-89da-4983-bff8-c06d12ace0bb) successfully added.
  • 現(xiàn)在我們查看下/etc/sysconfig/network-scripts/路徑下的文件
  • 已經(jīng)多了些配置文件
[root@localhost network-scripts]# ls
ifcfg-bond0              ifcfg-ens34  ifdown-ib    ifdown-ppp       ifdown-tunnel  ifup-ib    ifup-plusb   ifup-Team         network-functions
    ifcfg-lo     ifdown-ippp  ifdown-routes    ifup           ifup-ippp  ifup-post    ifup-TeamPort     network-functions-ipv6
ifcfg-bond-slave-eth0ifdown       ifdown-ipv6  ifdown-sit       ifup-aliases   ifup-ipv6  ifup-ppp     ifup-tunnel  ifdown-bnep  ifdown-isdn  ifdown-Team      ifup-bnep      ifup-isdn  ifup-routes  ifup-wireless
ifcfg-ens33              ifdown-eth   ifdown-post  ifdown-TeamPort  ifup-eth       ifup-plip  ifup-sit     init.ipv6-global
  • 接下來我們關(guān)聯(lián)到物理網(wǎng)卡上
[root@localhost network-scripts]# nmcli connection up  bond-slave-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
[root@localhost network-scripts]# nmcli connection up  bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
  • 我們?cè)趤聿樵兘壎ǖ那闆r
  • 他們MAC地址完全相同
  • 綁定成功
[root@localhost ~]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        inet6 fe80::28c9:f0c9:1483:a02d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 3486 (3.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 1310 (1.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 1627  bytes 156249 (152.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1050  bytes 139562 (136.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 600  bytes 61748 (60.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 134  bytes 18898 (18.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下來我們?nèi)?/proc/net/bonding/bond0路徑下面查看下他們的綁定關(guān)系
  • None表示運(yùn)行中,up表示待命狀態(tài)
  • 綁定配置成功
[root@localhost ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:52:72:d2
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:52:72:e6
Slave queue ID: 0
[root@localhost ~]# 
  • 接下來刪除bond0 用命令connection down bond0,先下線
[root@localhost ~]# nmcli   connection down bond0
Connection 'bond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
  • 下線以后我們來看下配置
  • bond0 模塊也自動(dòng)下線了
[root@localhost ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 1636  bytes 157932 (154.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1066  bytes 140574 (137.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:52:72:dc  txqueuelen 1000  (Ethernet)
        RX packets 52659  bytes 4215036 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5397  bytes 554782 (541.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下來我們刪除鏈接 用nmcli connection delete命令刪除,也可以直接刪除文件,我就直接刪除文件了
[root@localhost network-scripts]# rm -rf  /etc/sysconfig/network-scripts/ifcfg-bond*
  • 在用nmcli connection reload 讀取一下就完成了
    [root@localhost network-scripts]# nmcli connection reload
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Ubuntu的發(fā)音 Ubuntu,源于非洲祖魯人和科薩人的語(yǔ)言,發(fā)作 oo-boon-too 的音。了解發(fā)音是有意...
    螢火蟲de夢(mèng)閱讀 100,585評(píng)論 9 468
  • hexdump -C 查看二進(jìn)制文件 xxd:查看二進(jìn)制文件 whatis 簡(jiǎn)單描述命令的用途whatis c...
    JevonWei閱讀 955評(píng)論 0 0
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經(jīng)改了很多 但是錯(cuò)誤還是無法避免 以后資料會(huì)慢慢更新 大...
    數(shù)據(jù)革命閱讀 13,179評(píng)論 2 33
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • 本文整理了在實(shí)踐過程中使用的Linux網(wǎng)絡(luò)工具,這些工具提供的功能非常強(qiáng)大,我們平時(shí)使用的只是冰山一角,比如lso...
    老夫劉某閱讀 3,792評(píng)論 0 7

友情鏈接更多精彩內(nèi)容