linux基礎之網絡篇第四章nmcli綁定

  • nmcli 上篇已經介紹了創建網卡配置,網卡切換等
  • 在CentOS7里面如何實現多網卡綁定
  • 也可以修改文件,這里是用命令
  • 我們先定義一個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  --    
  • 我們在來查看下他的格式
[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
  • 在來查看下網卡配置狀態
[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已經生效里面已經有了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
  • 查看下,另外一臺電腦是否ping通
  • 已經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
  • 現在只是給他IP 還沒有給他綁定物理網卡,他沒有容錯功能
  • 接下來把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命令來執行,添加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.
  • 現在我們查看下/etc/sysconfig/network-scripts/路徑下的文件
  • 已經多了些配置文件
[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
  • 接下來我們關聯到物理網卡上
[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)
  • 我們在來查詢綁定的情況
  • 他們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
  • 接下來我們去 /proc/net/bonding/bond0路徑下面查看下他們的綁定關系
  • None表示運行中,up表示待命狀態
  • 綁定配置成功
[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 模塊也自動下線了
[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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,156評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,401評論 3 415
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,069評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,873評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,635評論 6 408
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,128評論 1 323
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,203評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,365評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,881評論 1 334
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,733評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,935評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,475評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,172評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,582評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,821評論 1 282
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,595評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,908評論 2 372

推薦閱讀更多精彩內容

  • Ubuntu的發音 Ubuntu,源于非洲祖魯人和科薩人的語言,發作 oo-boon-too 的音。了解發音是有意...
    螢火蟲de夢閱讀 99,423評論 9 467
  • hexdump -C 查看二進制文件 xxd:查看二進制文件 whatis 簡單描述命令的用途whatis c...
    JevonWei閱讀 808評論 0 0
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經改了很多 但是錯誤還是無法避免 以后資料會慢慢更新 大...
    數據革命閱讀 12,197評論 2 33
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,781評論 18 139
  • 本文整理了在實踐過程中使用的Linux網絡工具,這些工具提供的功能非常強大,我們平時使用的只是冰山一角,比如lso...
    老夫劉某閱讀 3,551評論 0 7