[root@localhost network-scripts]# nmcli con add con-name eth3 type ethernet
Error: 'ifname' argument is required.
[root@localhost network-scripts]# nmcli con add con-name eth3 type ethernet ifname eth2
Connection 'eth3' (4ff8075e-46f8-4e8f-8ec1-cc3153007807) successfully added.
[root@localhost network-scripts]# nmcli con status
Error: argument 'status' not understood. Try passing --help instead.
[root@localhost network-scripts]# nmcli dev status
DEVICE TYPE STATE CONNECTION
ens38 ethernet connected ens38
eth0 ethernet connected eth0
eth1 ethernet connected eth1
lo loopback unmanaged --
[root@localhost network-scripts]# nmcli con show
NAME UUID TYPE DEVICE
ens38 db342294-1be6-4573-8a83-cca53576f60b 802-3-ethernet ens38
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet eth1
eth2 3a73717e-65ab-93e8-b518-24f5af32dc0d 802-3-ethernet --
eth3 4ff8075e-46f8-4e8f-8ec1-cc3153007807 802-3-ethernet --
[root@localhost network-scripts]# ls
ifcfg-ens38 ifdown ifdown-isdn ifdown-TeamPort ifup-ib ifup-post ifup-tunnel
ifcfg-eth0 ifdown-bnep ifdown-post ifdown-tunnel ifup-ippp ifup-ppp ifup-wireless
ifcfg-eth1 ifdown-eth ifdown-ppp ifup ifup-ipv6 ifup-routes init.ipv6-global
ifcfg-eth2 ifdown-ib ifdown-routes ifup-aliases ifup-isdn ifup-sit network-functions
ifcfg-eth3 ifdown-ippp ifdown-sit ifup-bnep ifup-plip ifup-Team network-functions-ipv6
ifcfg-lo ifdown-ipv6 ifdown-Team ifup-eth ifup-plusb ifup-TeamPort
[root@localhost network-scripts]# cat ifcfg-eth3
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
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth3
UUID=4ff8075e-46f8-4e8f-8ec1-cc3153007807
DEVICE=eth2
ONBOOT=yes
[root@localhost network-scripts]#
[root@localhost ~]# nmcli con show
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth4 fd41632f-bd43-4bb2-9615-f792502ea741 802-3-ethernet ens38
ens38 db342294-1be6-4573-8a83-cca53576f60b 802-3-ethernet --
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet --
eth2 3a73717e-65ab-93e8-b518-24f5af32dc0d 802-3-ethernet --
eth3 4ff8075e-46f8-4e8f-8ec1-cc3153007807 802-3-ethernet --
[root@localhost ~]# nmcli con show
NAME UUID TYPE DEVICE
ens38 db342294-1be6-4573-8a83-cca53576f60b 802-3-ethernet ens38
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet --
eth2 3a73717e-65ab-93e8-b518-24f5af32dc0d 802-3-ethernet --
eth3 4ff8075e-46f8-4e8f-8ec1-cc3153007807 802-3-ethernet --
eth4 fd41632f-bd43-4bb2-9615-f792502ea741 802-3-ethernet --
[root@localhost ~]# nmcli con show
NAME UUID TYPE DEVICE
ens38 db342294-1be6-4573-8a83-cca53576f60b 802-3-ethernet ens38
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet eth1
eth2 3a73717e-65ab-93e8-b518-24f5af32dc0d 802-3-ethernet --
eth3 4ff8075e-46f8-4e8f-8ec1-cc3153007807 802-3-ethernet --
eth4 fd41632f-bd43-4bb2-9615-f792502ea741 802-3-ethernet --
[root@localhost ~]# nmcli dev status
DEVICE TYPE STATE CONNECTION
ens38 ethernet connected ens38
eth0 ethernet connected eth0
eth1 ethernet disconnected --
lo loopback unmanaged --
[root@localhost ~]# nmcli con show
NAME UUID TYPE DEVICE
ens38 db342294-1be6-4573-8a83-cca53576f60b 802-3-ethernet ens38
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet --
eth2 3a73717e-65ab-93e8-b518-24f5af32dc0d 802-3-ethernet --
eth3 4ff8075e-46f8-4e8f-8ec1-cc3153007807 802-3-ethernet --
eth4 fd41632f-bd43-4bb2-9615-f792502ea741 802-3-
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]# nmcli con up ens38
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
[root@localhost ~]# nmcli con up eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[root@localhost ~]# nmcli con up eth2
Error: Connection activation failed: No suitable device found for this connection.
[root@localhost ~]# nmcli con down eth1
Connection 'eth1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[root@localhost ~]# nmcli con up eth2
Error: Connection activation failed: No suitable device found for this connection.
[root@localhost ~]# ^C
[root@localhost ~]#
即使网卡dev down了,新建连接接口时如果没有指定连接接口的dev,就不能趁机把这个连接接口起来
nmcli con add con-name eth2 type ethernet ifname eth0
nmcli con add con-name eth3 type ethernet ifname eth0
nmcli 新建连接con时,连接接口和网卡之间就建立了关系
eth2,eth3这两个连接接口对应的是eth0网口
nmcli con up eth2
nmcli con up eth3
直接切换那个连接接口使用这个eth0网卡
在主机内shell可以添加的网卡设备有网桥,链路等,但网卡需外部添加(到目前为止还没有找到直接在主机内添加网卡的命令)
新旧版本添加子网卡对比
添加新的连接:
[root@centos4 network-scripts]# nmcli con add con-name eth2 type ethernet ifname eth0
Connection 'eth2' (6fff8b8e-5f04-4cfd-b81c-1a40c70ebe3f) successfully added.
[root@centos4 network-scripts]# nmcli dev status
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
eth0 ethernet connected System eth0
lo loopback unmanaged --
[root@centos4 network-scripts]# nmcli con show
NAME UUID TYPE DEVICE
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
ens33 c157cc49-8bcc-4950-9966-4c8c0718c0b3 802-3-ethernet ens33
eth2 6fff8b8e-5f04-4cfd-b81c-1a40c70ebe3f 802-3-ethernet --
[root@centos4 network-scripts]# ls
ifcfg ifdown-bnep ifdown-ppp ifup ifup-isdn ifup-sit network-functions
ifcfg-ens33 ifdown-eth ifdown-routes ifup-aliases ifup-plip ifup-Team network-functions-ipv6
ifcfg-eth0 ifdown-ippp ifdown-sit ifup-bnep ifup-plusb ifup-TeamPort
ifcfg-eth2 ifdown-ipv6 ifdown-Team ifup-eth ifup-post ifup-tunnel
ifcfg-lo ifdown-isdn ifdown-TeamPort ifup-ippp ifup-ppp ifup-wireless
ifdown ifdown-post ifdown-tunnel ifup-ipv6 ifup-routes init.ipv6-global
[root@centos4 network-scripts]#
ens33 ethernet connected ens33
eth0 ethernet connected System eth0
断开连接:
原来ip为192.168.43.168断开后,系统开启新的连接,而且与原来的连接文件ifcfg-eth0不相同。新连接ip 192.168.43.125
[root@centos4 network-scripts]# nmcli con down "System eth0"
Connection 'System eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)可见网卡eth0此时的连接为eth2
补充:有时网卡的名称与连接的名称是一样的
修改网卡device名称:http://blog.csdn.net/JackLiu16/article/details/79352467