CentOS7 網絡管理工具nmcli

  今天幫別人調試虛擬機的網絡問題(CentOS 7系統),習慣性直接改/etc/sysconfig/network-scripts/ifcfg-xxx配置文件,可是不知道爲何重啓network後靜態ip沒有生效。而後百度了一下,CentOS使用NetworkManager來管理網絡配置,就順便接觸了下網絡管理命令行工具NetworkManager command line tool,也叫nmcli。bash

  初次使用也沒研究太深,如下只給出一部分使用過的語句。網絡

  查看鏈接服務設備工具

[yu@yu ~]$ nmcli connection show 
名稱  UUID                                  類型            設備 
p2p1  649cf3f6-8d93-4517-b299-7b5671e37069  802-3-ethernet  p2p1 

  查看特定鏈接的詳情oop

[yu@yu ~]$ nmcli connection show p2p1 
connection.id:                          p2p1
connection.uuid:                        649cf3f6-8d93-4517-b299-7b5671e37069
connection.stable-id:                   --
...

  查看網絡設備狀態ui

[yu@yu ~]$ nmcli device status
設備  類型      狀態    鏈接 
p2p1  ethernet  鏈接的  p2p1 
lo    loopback  未託管  --

  使用「dhcp」建立鏈接命令行

[yu@yu ~]$ nmcli connection add con-name "dhcp" type ethernet ifname enoxxxxxx
Connection 'dhcp' (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) successfully added.

  其中:connection add - 添加新的鏈接;調試

    con-name - 鏈接名;rest

    type - 設備類型;blog

    ifname - 接口名。dns

  使用「static」建立鏈接

[yu@yu ~]$ nmcli connection add con-name "static" ifname enoxxxxxx autoconnect no type ethernet ip4 192.168.1.xxx gw4 192.168.1.1
Connection 'static' (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) successfully added.

  其中:connection add - 添加新的鏈接;

    con-name - 鏈接名;

    ifname - 接口名;

    type - 設備類型;

    autoconnect - 自動鏈接;

    ip4 - 指定ip;

    gw4 - 網關。

  更新鏈接

[yu@yu ~]$ nmcli connection up enoxxxxxx

  單獨設置鏈接

  設置靜態ip地址

nmcli connection modify <interface> ipv4.addresses '192.168.1.xxx'

  設置DNS

nmcli connection modify <interface> ipv4.dns '8.8.8.8'

  設置網關

nmcli connection modify <interface> ipv4.gateway '192.168.1.1'

  設置IP地址爲手動指定

nmcli connection modify <interface> ipv4.method manual

  設置開機自動鏈接

nmcli connection modify <interface> connection.autoconnect yes

  從新加載配置

nmcli connection reload

  配置完成須要重啓網絡

systemctl restart network
相關文章
相關標籤/搜索