nmcli添加网卡 并且修改设备名字 添加IP地址

nmcli的命令参数

[root@localhost ~]# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -t[erse]                                   terse output
  -p[retty]                                  pretty output
  -m[ode] tabular|multiline                  output mode
  -f[ields] <field1,field2,...>|all|common   specify fields to output
  -e[scape] yes|no                           escape columns separators in values
  -n[ocheck]                                 don't check nmcli and NetworkManager versions
  -a[sk]                                     ask for missing parameters
  -w[ait] <seconds>                          set timeout waiting for finishing operations
  -v[ersion]                                 show program version
  -h[elp]                                    print this help

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager

nmcli的常用命令选项
-

[root@localhost ~]# nmcli connection 
add     down    help    modify  show    
delete  edit    load    reload  up 

查看网卡

[root@localhost ~]# nmcli connection show 
NAME         UUID                                  TYPE          DEVICE      
eno16777736  ce1a55de-9427-4f08-9ff8-256ac08ebd78  802-3-ethernet  eno16777736 
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pffo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global 
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff

添加网卡到配置文件,并且命名为eth1

[root@localhost ~]# nmcli connection add ifname eno33554992 con-name eth1 type ethernet 
Connection 'eth1' (5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf) successfully added.
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global 
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 

pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fe4d:bb5d/64 scope link 
       valid_lft forever preferred_lft forever

修改网络配置文件添加MAC地址 (eno33554992) 、修改BOOTPROTO=static 修改设备名DEVICE=eth1

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
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=eth1
UUID=5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf
DEVICE=eth1
ONBOOT=yes
HWADDR=00:0c:29:4d:bb:5d

重启服务器之后 查看ip

[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 

pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff

添加ip地址

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 
TYPE=Ethernet
BOOTPROTO=static
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=eth1
UUID=5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf
DEVICE=eth1
ONBOOT=yes
HWADDR=00:0c:29:4d:bb:5d
IPADDR0=192.168.1.101
PREFIX0=24
GATEWAY=192.168.1.254

重启网络服务并且查看ip

[root@localhost ~]# systemctl restart network
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global 
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb5d/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE      
eth1         5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf  802-3-ethernet  eth1        
eno16777736  ce1a55de-9427-4f08-9ff8-256ac08ebd78  802-3-ethernet  eno16777736 

这里写图片描述

posted @ 2017-07-19 11:35  sujc-blogs  阅读(812)  评论(0编辑  收藏  举报