nm(Network Manager)家族(CentOS 7专用):nmcli

nmcli命令

  • 格式:
    nmcli [OPTIONS...] {help | general | networking | radio | connection | device | agent | monitor} [COMMAND] [ARGUMENTS...]
    • device:查看并管理网络接口
       COMMAND := { status | show | connect | disconnect | delete |wifi | wimax }
    [root@node1 network-scripts]# nmcli device status 
    DEVICE      TYPE      STATE      CONNECTION         
    ens37       ethernet  connected  Wired connection 1 
    ens33       ethernet  connected  ens33              
    virbr0      bridge    connected  virbr0             
    lo          loopback  unmanaged  --                 
    virbr0-nic  tun       unmanaged  --                 
    [root@node1 network-scripts]# nmcli device show   
    GENERAL.DEVICE:                         ens37
    GENERAL.TYPE:                           ethernet
    GENERAL.HWADDR:                         00:0C:29:0E:AF:8A
    GENERAL.MTU:                            1500
    GENERAL.STATE:                          100 (connected)
    GENERAL.CONNECTION:                     Wired connection 1
    GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/4
    WIRED-PROPERTIES.CARRIER:               on
    IP4.ADDRESS[1]:                         192.168.1.115/24
    IP4.ADDRESS[2]:                         192.168.1.115/8
    IP4.GATEWAY:                            192.168.1.1
    IP4.ROUTE[1]:                           dst = 0.0.0.0/0, nh = 192.168.1.1, mt = 101
    IP4.ROUTE[2]:                           dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 101
    IP4.ROUTE[3]:                           dst = 192.0.0.0/8, nh = 0.0.0.0, mt = 101
    IP4.DNS[1]:                             192.168.1.1
    IP6.GATEWAY:                            --
    IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 101
    IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table=255
    ...
    
    • connection:启动、停止和管理网络连接
       COMMAND := { show | up | down | add | edit | modify | delete | reload | load }
    [root@node1 network-scripts]# nmcli connection show 
    NAME                UUID                                  TYPE      DEVICE 
    ens33               fac256e3-e571-4ef0-9770-d8c208eaeabf  ethernet  ens33  
    ens37               4a5516a4-dfa4-24af-b1c4-e843e312e2fd  ethernet  ens37  
    virbr0              849d7516-1749-4cda-9ce5-da8924a6a220  bridge    virbr0 
    Wired connection 1  1cd19407-0ba6-34c4-a819-d9495b44ee1c  ethernet  --     
    [root@node1 network-scripts]# nmcli connection down ens37
    Connection 'ens37' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
    [root@node1 network-scripts]# nmcli connection show      
    NAME                UUID                                  TYPE      DEVICE 
    ens33               fac256e3-e571-4ef0-9770-d8c208eaeabf  ethernet  ens33  
    virbr0              849d7516-1749-4cda-9ce5-da8924a6a220  bridge    virbr0 
    ens37               4a5516a4-dfa4-24af-b1c4-e843e312e2fd  ethernet  --     
    Wired connection 1  1cd19407-0ba6-34c4-a819-d9495b44ee1c  ethernet  --     
    [root@node1 network-scripts]# nmcli connection up ens37  
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
    [root@node1 network-scripts]# nmcli connection show    
    NAME                UUID                                  TYPE      DEVICE 
    ens33               fac256e3-e571-4ef0-9770-d8c208eaeabf  ethernet  ens33  
    ens37               4a5516a4-dfa4-24af-b1c4-e843e312e2fd  ethernet  ens37  
    virbr0              849d7516-1749-4cda-9ce5-da8924a6a220  bridge    virbr0 
    Wired connection 1  1cd19407-0ba6-34c4-a819-d9495b44ee1c  ethernet  --     
    [root@node1 network-scripts]# nmcli connection add con-name eth0 ipv4.addresses 1.1.1.1 ipv4.method manual type ethernet ifname ens37
    Connection 'eth0' (7fe1a2f8-27ca-4451-904f-cbdadcaf9215) successfully added.
    [root@node1 network-scripts]# nmcli connection show 
    NAME                UUID                                  TYPE      DEVICE 
    ens33               fac256e3-e571-4ef0-9770-d8c208eaeabf  ethernet  ens33  
    ens37               4a5516a4-dfa4-24af-b1c4-e843e312e2fd  ethernet  ens37  
    virbr0              849d7516-1749-4cda-9ce5-da8924a6a220  bridge    virbr0 
    eth0                7fe1a2f8-27ca-4451-904f-cbdadcaf9215  ethernet  --     
    Wired connection 1  1cd19407-0ba6-34c4-a819-d9495b44ee1c  ethernet  --     
    [root@node1 network-scripts]# nmcli connection delete eth0 
    Connection 'eth0' (7fe1a2f8-27ca-4451-904f-cbdadcaf9215) successfully deleted.
    [root@node1 network-scripts]# nmcli connection show        
    NAME                UUID                                  TYPE      DEVICE 
    ens33               fac256e3-e571-4ef0-9770-d8c208eaeabf  ethernet  ens33  
    ens37               4a5516a4-dfa4-24af-b1c4-e843e312e2fd  ethernet  ens37  
    virbr0              849d7516-1749-4cda-9ce5-da8924a6a220  bridge    virbr0 
    Wired connection 1  1cd19407-0ba6-34c4-a819-d9495b44ee1c  ethernet  --     
    

  modify [ id | uuid | path ] [+|-].
  如何修改IP地址等属性:
   [root@node1 ~]# nmcli connection modify IFACE [+|-]setting.property value
    ipv4.address
    ipv4.gateway
    ipv4.dns1
    ipv3.method

你可能感兴趣的:(nm(Network Manager)家族(CentOS 7专用):nmcli)