CentOS IP address Setup

6 minute read

It is a story that solved the problem that ens224 and ens256 do not UP and the IP address cannot be set.

Problem

[root@centos ~]# nmcli device
DEVICE  TYPE      STATE                                  CONNECTION
ens192  ethernet  connected                              ens192
ens224  ethernet  connecting (getting IP configuration)  Wired connection 1
ens256  ethernet  connecting (getting IP configuration)  Wired connection 2
lo      loopback  unmanaged                              --

First, I tried to change the name of the interface, but I can’t see ens224 and ens256 in the first place.

[root@centos network-scripts]# ls -la
total 240
drwxr-xr-x. 2 root root  4096 Oct  8 00:45 .
drwxr-xr-x. 6 root root  4096 Oct  8 00:45 ..
-rw-r--r--. 1 root root   422 Oct  7 01:04 ifcfg-ens192
-rw-r--r--. 1 root root   254 Sep 12  2016 ifcfg-lo

I tried the interface enable command, but I got angry when there was no connection.

[root@centos network-scripts]# nmcli c m eth224 connection.autoconnect yes
Error: unknown connection 'eth224'.

[root@centos network-scripts]# nmcli c down eth224
Error: 'eth224' is not an active connection.
Error: no active connection provided.

When you execute the command to add a connection,

[root@centos network-scripts]# nmcli con add type ethernet ifname ens81
Connection 'ethernet-ens81' (36a6afec-8712-4242-8d75-4cc6d2c9bbf0) successfully added.

[root@centos network-scripts]# nmcli con add type ethernet ifname ens91
Connection 'ethernet-ens91' (b6b6eaac-0593-44c6-a0af-6cdb340a85e4) successfully added.

[root@centos network-scripts]# nmcli device
DEVICE  TYPE      STATE                                  CONNECTION
ens192  ethernet  connected                              ens192
ens224  ethernet  connecting (getting IP configuration)  Wired connection 1
ens256  ethernet  connecting (getting IP configuration)  Wired connection 2
lo      loopback  unmanaged                              --

The file is ready!

[root@centos network-scripts]# ls -la
total 248
drwxr-xr-x. 2 root root  4096 Oct  8 16:31 .
drwxr-xr-x. 6 root root  4096 Oct  8 00:45 ..
-rw-r--r--. 1 root root   422 Oct  7 01:04 ifcfg-ens192
-rw-r--r--. 1 root root   319 Oct  8 16:22 ifcfg-ethernet-ens81
-rw-r--r--. 1 root root   319 Oct  8 16:23 ifcfg-ethernet-ens91
-rw-r--r--. 1 root root   254 Sep 12  2016 ifcfg-lo

However, the IP address cannot be set.

[root@centos network-scripts]# nmcli c m ens81 ipv4.method manual ipv4.addr 10.1.81.102/24 10.1.81.21
Error: unknown connection 'ens81'.

Problem solving

When I read the article Poke the corner of the nmcli command, I found that Connection and Device seem to be different.

The name of ens254 that I saw on the nmcli device is actually “Wired connection 1”.

[root@centos network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE
Wired connection 1  d7993957-17e7-38ae-8499-289a1d69a331  802-3-ethernet  ens224
Wired connection 2  c5323930-cfab-3867-a1c2-89ed3727c83f  802-3-ethernet  ens256
ens192              25523ce6-e6f2-4a9c-831c-4ba5a3d36d94  802-3-ethernet  ens192
ethernet-ens81      36a6afec-8712-4242-8d75-4cc6d2c9bbf0  802-3-ethernet  --
ethernet-ens81-1    6e02b7f5-af7d-4c97-a895-7ceb4a52feae  802-3-ethernet  --
ethernet-ens91      b6b6eaac-0593-44c6-a0af-6cdb340a85e4  802-3-ethernet  --
ethernet-ens91-1    059e7a43-ef58-4382-8c62-14366341b7f9  802-3-ethernet  --

[root@centos network-scripts]# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:86:99:7a brd ff:ff:ff:ff:ff:ff
    inet 172.22.2.102/16 brd 172.22.255.255 scope global ens192
       valid_lft forever preferred_lft forever
    inet6 fe80::608f:5a80:8910:3594/64 scope link
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:86:20:c8 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::549c:63a:2c22:8109/64 scope link
       valid_lft forever preferred_lft forever
4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:86:82:06 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::511d:7bfc:90d2:8df8/64 scope link
       valid_lft forever preferred_lft forever

So when I tried to execute the command again with “Wired connection 1”, the command passed. However, the interface is not UP.

[root@centos ~]# nmcli c m "Wired connection 1"  connection.autoconnect yes

[root@centos ~]# nmcli device
DEVICE  TYPE      STATE                                  CONNECTION
ens192  ethernet  connected                              ens192
ens224  ethernet  connecting (getting IP configuration)  Wired connection 1
ens256  ethernet  connecting (getting IP configuration)  Wired connection 2
lo      loopback  unmanaged                              --
[root@centos ~]# nmcli device

When I set the IP address again, it became Connected!

[root@centos ~]# nmcli c m "Wired connection 1" ipv4.method manual ipv4.addr 10.1.81.102/24
[root@centos ~]# nmcli device
DEVICE  TYPE      STATE         CONNECTION
ens192  ethernet  connected     ens192
ens224  ethernet  connected     Wired connection 1
ens256  ethernet  disconnected  --
lo      loopback  unmanaged     --

Try changing the name.

[root@centos ~]# nmcli connection modify "Wired connection 2" connection.id ens91
Error: unknown connection 'Wired connection 2'.
[root@centos ~]# nmcli connection modify "Wired connection 1" connection.id ens81
Error: unknown connection 'Wired connection 1'.
[root@centos ~]# nmcli device
DEVICE  TYPE      STATE      CONNECTION
ens192  ethernet  connected  ens192
ens224  ethernet  connected  ens81
ens256  ethernet  connected  ens91
lo      loopback  unmanaged  --

If you look at the file, the one that is updated is the “ifcfg-Wired_connection_1” file.

[root@centos network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@centos network-scripts]# ls
ifcfg-ens192              ifdown-ipv6      ifup-bnep    ifup-sit
ifcfg-ethernet-ens81      ifdown-isdn      ifup-eth     ifup-Team
ifcfg-ethernet-ens91      ifdown-post      ifup-ib      ifup-TeamPort
ifcfg-lo                  ifdown-ppp       ifup-ippp    ifup-tunnel
ifcfg-Wired_connection_1  ifdown-routes    ifup-ipv6    ifup-wireless
ifcfg-Wired_connection_2  ifdown-sit       ifup-isdn    init.ipv6-global
ifdown                    ifdown-Team      ifup-plip    network-functions
ifdown-bnep               ifdown-TeamPort  ifup-plusb   network-functions-ipv6
ifdown-eth                ifdown-tunnel    ifup-post
ifdown-ib                 ifup             ifup-ppp
ifdown-ippp               ifup-aliases     ifup-routes

[root@centos network-scripts]# cat ifcfg-Wired_connection_1
HWADDR=00:50:56:86:20:C8
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth81
UUID=d7993957-17e7-38ae-8499-289a1d69a331
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
IPADDR=10.1.81.102
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Therefore, delete this file created earlier.

[root@centos network-scripts]# cat ifcfg-ethernet-ens81
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=ethernet-ens81
UUID=36a6afec-8712-4242-8d75-4cc6d2c9bbf0
DEVICE=ens81
ONBOOT=yes

The file has been renamed.

[root@centos network-scripts]# ls
ifcfg-ens192  ifdown-isdn      ifup-bnep   ifup-routes
ifcfg-ens81   ifdown-post      ifup-eth    ifup-sit
ifcfg-ens91   ifdown-ppp       ifup-ib     ifup-Team
ifcfg-lo      ifdown-routes    ifup-ippp   ifup-TeamPort
ifdown        ifdown-sit       ifup-ipv6   ifup-tunnel
ifdown-bnep   ifdown-Team      ifup-isdn   ifup-wireless
ifdown-eth    ifdown-TeamPort  ifup-plip   init.ipv6-global
ifdown-ib     ifdown-tunnel    ifup-plusb  network-functions
ifdown-ippp   ifup             ifup-post   network-functions-ipv6
ifdown-ipv6   ifup-aliases     ifup-ppp

When the IP address does not change

The IP address did not change with service restart.

[root@centos squid-4.13]# systemctl restart network.service

[root@centos squid-4.13]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:99:7a brd ff:ff:ff:ff:ff:ff
    inet 172.22.2.102/16 brd 172.22.255.255 scope global ens192
       valid_lft forever preferred_lft forever
    inet6 fe80::608f:5a80:8910:3594/64 scope link
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:20:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.1.81.102/24 brd 10.1.81.255 scope global ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::549c:63a:2c22:8109/64 scope link
       valid_lft forever preferred_lft forever
4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:82:06 brd ff:ff:ff:ff:ff:ff
    inet 10.1.91.102/24 brd 10.1.91.255 scope global ens256
       valid_lft forever preferred_lft forever
    inet6 fe80::511d:7bfc:90d2:8df8/64 scope link
       valid_lft forever preferred_lft forever

Looking at the contents of the file, the settings have changed.

[root@centos squid-4.13]# cd /etc/sysconfig/network-scripts
[root@centos network-scripts]# ls
ifcfg-ens192  ifdown-isdn      ifup-bnep   ifup-routes
ifcfg-ens81   ifdown-post      ifup-eth    ifup-sit
ifcfg-ens91   ifdown-ppp       ifup-ib     ifup-Team
ifcfg-lo      ifdown-routes    ifup-ippp   ifup-TeamPort
ifdown        ifdown-sit       ifup-ipv6   ifup-tunnel
ifdown-bnep   ifdown-Team      ifup-isdn   ifup-wireless
ifdown-eth    ifdown-TeamPort  ifup-plip   init.ipv6-global
ifdown-ib     ifdown-tunnel    ifup-plusb  network-functions
ifdown-ippp   ifup             ifup-post   network-functions-ipv6
ifdown-ipv6   ifup-aliases     ifup-ppp

[root@centos network-scripts]# cat ifcfg-ens81
HWADDR=00:50:56:86:20:C8
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens82
UUID=d7993957-17e7-38ae-8499-289a1d69a331
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
IPADDR=10.1.82.102
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Up / down the interface.

[root@centos network-scripts]# nmcli connection down ens82 && nmcli connection u                                                                             p ens82
Connection 'ens82' successfully deactivated (D-Bus active path: /org/freedesktop                                                                             /NetworkManager/ActiveConnection/1158)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkMa                                                                             nager/ActiveConnection/1162)

[root@centos network-scripts]# nmcli connection down ens92 && nmcli connection u                                                                             p ens92
Connection 'ens92' successfully deactivated (D-Bus active path: /org/freedesktop                                                                             /NetworkManager/ActiveConnection/1156)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkMa                                                                             nager/ActiveConnection/1163)

The change of IP address was reflected.

[root@centos network-scripts]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:99:7a brd ff:ff:ff:ff:ff:ff
    inet 172.22.2.102/16 brd 172.22.255.255 scope global ens192
       valid_lft forever preferred_lft forever
    inet6 fe80::608f:5a80:8910:3594/64 scope link
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:20:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.1.82.102/24 brd 10.1.82.255 scope global ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::549c:63a:2c22:8109/64 scope link
       valid_lft forever preferred_lft forever
4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100                                                                             0
    link/ether 00:50:56:86:82:06 brd ff:ff:ff:ff:ff:ff
    inet 10.1.92.102/24 brd 10.1.92.255 scope global ens256
       valid_lft forever preferred_lft forever
    inet6 fe80::511d:7bfc:90d2:8df8/64 scope link
       valid_lft forever preferred_lft forever
[root@centos network-scripts]#

Command summary

Device confirmation

nmcli device

Interface enablement

nmcli c m eth224 connection.autoconnect yes

IP address setting

nmcli c m ens81 ipv4.method manual ipv4.addr 10.1.81.102/24 10.1.81.21

Device name change

nmcli connection modify "Wired connection 2" connection.id ens91

Location of interface configuration file

cd /etc/sysconfig/network-scripts

reference:
After adding the Network Adapter in the RHEL 7.x VM.

centos7 network settings

I was addicted to the network not being connected when rebooting centos7