linux学习

inux网络篇第三章:地址配置工具nmcli

2017-06-29  本文已影响287人  数据革命

nmcli命令表

命令 使用
nmcli dev status List all devices
nmcli con show List all connections
nmcli con up "ID" Activate a connection
nmcli con down "ID" Deactivate a connection . The connection will restart if autoconnect is yes.
nmcli dev dis "DEV" Disble all managed interfaces
nmcli con add... Add anew connection
nmcli con mod "ID"... Modify a copnnection
nmcli con del "ID" Delite a connection...

配置文件和文件的对应关系

nmcli con mod ifcfg-*
ipv4.method manual BOOTPROTO=none
ipv4.method auto BOOTPROTO=dhcp
ipv4.addresses “192.0.2.1/24
192.0.2.254 IPADDR0=192.0.2.1
PREFIX0=24
GATEWAY0=192.0.2.254
ipv4.dns 8.8.8.8 DNS0=8.8.8.8
ipv4.dns-search example.com DOMAIN=example.com
ipv4.ignore-auto-dns true PEERDNS=no
connection.autoconnect yes ONBOOT=yes
connection.id eth0 NAME=eth0
connection.interface-name eth0 DEVICE=eth0
connection.interface-name eth0 DEVICE=eth0
802-3-ethernet.mac-address . . . HWADDR= . . .

动态和静态配置文件

动态配置 静态配置
DEVICE=ethX DEVICE=ethX
HWADDR=0:02:8A:A6:30:45 HWADDR=0:02:8A:A6:30:45
BOOTPROTO=dhcp IPADDR=192.168.0.123
ONBOOT=yes NETMASK=255.255.255.0
type=Ethernet GATEWAy=192.168.0.254
ONBOOT=yes
type=Ethernet

nmcli的使用

[root@localhost ~]# nmcli connection show 
NAME                UUID                                  TYPE            DEVICE     
Wired connection 1  7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1   <<<这是套配置  
eno33554960         eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  --         
eno16777736         da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
virbr0-nic          45f38f6d-fb8b-49f4-a261-daa9ff952746  generic         virbr0-nic 
virbr0              3ce60a22-a7d8-4e7d-9997-6813be97eead  bridge          virbr0     <<<这是虚拟网卡
Wired connection 2  46f4952d-ecd7-4a58-afd2-feea00d087fa  802-3-ethernet  eth0 
[root@localhost ~]# nmcli connection modify Wired\ connection\ 1 connection.id eth1-office
[root@localhost ~]# nmcli connection show 
NAME                UUID                                  TYPE            DEVICE     
eth1-office         7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1  <<<看已经改了     
eno33554960         eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  --         
eno16777736         da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
virbr0-nic          45f38f6d-fb8b-49f4-a261-daa9ff952746  generic         virbr0-nic 
virbr0              3ce60a22-a7d8-4e7d-9997-6813be97eead  bridge          virbr0     
Wired connection 2  46f4952d-ecd7-4a58-afd2-feea00d087fa  802-3-ethernet  eth0 
[root@localhost ~]# nmcli con delete Wired\ connection\ 2 
Connection 'Wired connection 2' (46f4952d-ecd7-4a58-afd2-feea00d087fa) successfully deleted.
[root@localhost ~]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE     
eth1-office  7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1       
eno33554960  eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  --         
eno16777736  da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
virbr0-nic   45f38f6d-fb8b-49f4-a261-daa9ff952746  generic         virbr0-nic 
virbr0       3ce60a22-a7d8-4e7d-9997-6813be97eead  bridge          virbr0   
[root@localhost ~]# nmcli connection add con-name  eyh1-lan type ethernet ifname  eth1
Connection 'eyh1-lan' (077284ec-39f6-47f8-becd-168b8bd3b64c) successfully added.
[root@localhost network-scripts]# ls
ifcfg-eno16777736  ifdown       ifdown-ipv6    ifdown-sit       ifup-aliases  ifup-ipv6   ifup-ppp       ifup-tunnel
ifcfg-eno33554960  ifdown-bnep  ifdown-isdn    ifdown-Team      ifup-bnep     ifup-isdn   ifup-routes    ifup-wireless
ifcfg-eth1-office  ifdown-eth   ifdown-post    ifdown-TeamPort  ifup-eth      ifup-plip   ifup-sit       init.ipv6-global
ifcfg-eyh1-lan     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
[root@localhost network-scripts]# cat ifcfg-eyh1-lan 
TYPE=Ethernet
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
NAME=eyh1-lan
UUID=077284ec-39f6-47f8-becd-168b8bd3b64c
DEVICE=eth1
ONBOOT=yes
[root@localhost network-scripts]# nmcli  connection show 
NAME         UUID                                  TYPE            DEVICE     
eth1-office  7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1       
eno33554960  eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  --         
eno16777736  da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
eyh1-lan     077284ec-39f6-47f8-becd-168b8bd3b64c  802-3-ethernet  --         
virbr0-nic   45f38f6d-fb8b-49f4-a261-daa9ff952746  generic         virbr0-nic 
virbr0       3ce60a22-a7d8-4e7d-9997-6813be97eead  bridge          virbr0  
[root@localhost network-scripts]# nmcli connection modify eyh1-lan connection.autoconnect yes ipv4.addresses 172.17.100.11/16 ipv4.method manual  <<<使用了这条命令 ,这项很重要记住了,不然配置文件不会生效 
[root@localhost network-scripts]# cat ifcfg-eyh1-lan 
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eyh1-lan
UUID=077284ec-39f6-47f8-becd-168b8bd3b64c
DEVICE=eth1
ONBOOT=yes
IPADDR=172.17.100.11
PREFIX=16
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@localhost network-scripts]# nmcli connection modify eyh1-lan connection.autoconnect yes ipv4.addresses 172.17.100.11/16 ipv4.method manual ipv4.gateway 172.17.0.1 ipv4.dns 172.17.0.1
[root@localhost network-scripts]# cat ifcfg-eyh1-lan 
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eyh1-lan
UUID=077284ec-39f6-47f8-becd-168b8bd3b64c
DEVICE=eth1
ONBOOT=yes
IPADDR=172.17.100.11
PREFIX=16
GATEWAY=172.17.0.1
DNS1=172.17.0.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@localhost Desktop]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:4f:db:89  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 276 (276.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

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.100.11  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::20c:29ff:fe4f:db93  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4f:db:93  txqueuelen 1000  (Ethernet)
        RX packets 2078  bytes 207195 (202.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 133  bytes 20881 (20.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost network-scripts]# cp  ifcfg-eyh1-lan    ifcfg-eyh1-home 
[root@localhost network-scripts]# vi  ifcfg-eyh1-home    
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eyh1-lan      <<<<名字
UUID=077284ec-39f6-47f8-becd-168b8bd3b64c   UID:必须改
DEVICE=eth1
ONBOOT=yes
IPADDR=172.17.100.11     <<<IP:自己看情况改
PREFIX=16
GATEWAY=172.17.0.1
DNS1=172.17.0.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@localhost network-scripts]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE     
eyh1-lan     077284ec-39f6-47f8-becd-168b8bd3b64c  802-3-ethernet  --         
eno16777736  da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
eth1-office  7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1       
virbr0-nic   46e06189-1049-446e-bd47-255f006d02e3  generic         virbr0-nic 
virbr0       69e7fc2c-61e8-4a6d-9a11-ffa5905d1302  bridge          virbr0     
eno33554960  eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  -- 
[root@localhost network-scripts]# nmcli connection reload           
[root@localhost network-scripts]# nmcli connection show     
NAME         UUID                                  TYPE            DEVICE     
eyh1-lan     077284ec-39f6-47f8-becd-168b8bd3b64c  802-3-ethernet  --         
eno16777736  da0d66c1-91b9-456e-8a51-f0e0772212bc  802-3-ethernet  --         
eth1-office  7f8ee0f7-41b8-41c3-a922-49266a2b9303  802-3-ethernet  eth1       
eyh1-home    c9b75b5d-6975-b4e8-0e17-d32f44f56ef2  802-3-ethernet  --         
virbr0-nic   46e06189-1049-446e-bd47-255f006d02e3  generic         virbr0-nic 
virbr0       69e7fc2c-61e8-4a6d-9a11-ffa5905d1302  bridge          virbr0     
eno33554960  eb15cda5-85ec-44d9-8ea4-fc5dd7ea76c3  802-3-ethernet  --  
[root@localhost network-scripts]# nmcli connection delete eth1-office 
Connection 'eth1-office' (7f8ee0f7-41b8-41c3-a922-49266a2b9303) successfully deleted.
上一篇 下一篇

猜你喜欢

热点阅读