4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CentOS IPアドレス Setup

Last updated at Posted at 2020-10-08

ens224,ens256がUPしない、IPアドレスが設定できない、を解決した話です。

#問題編

[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                              --

まず、インターフェースの名前を変えようと思ったけど、そもそもens224, ens256 が見えない。

[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

インターフェース有効化コマンドを試すも、コネクションが無いと怒られる。

[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.

コネクションを追加するコマンドを実行すると、

[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                              --

ファイルができた!

[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

しかし、IPアドレスの設定はできない。

[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'.

#問題解決編

nmcliコマンドの隅をつつく という記事を読んだところ、ConnectionとDeviceは違うらしいということが分かった。

nmcli deviceで見てたens254の名前は実は「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

そこで「Wired connection 1」で再度コマンド実行してみると、コマンドが通った。が、インターフェースは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

再度IPアドレスを設定してみると、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     --

名前を変えてみる。

[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  --

ファイルを見ると更新されているのは「ifcfg-Wired_connection_1」のファイルです。

[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

よって、先ほど作ったこちらのファイルは削除する。

[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

ファイルの名前を変更済。

[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

#IPアドレスが変わらないとき

service restart でIPアドレスが変わらなかった。

[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

ファイルの中身を見ると設定は変わっている。

[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する。

[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)

IPアドレスの変更が反映された。

[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]#

#コマンドまとめ

デバイス確認

nmcli device

インターフェース有効化

nmcli c m eth224 connection.autoconnect yes

IPアドレス設定

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

デバイス名変更

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

インターフェース設定ファイルの所在

cd /etc/sysconfig/network-scripts

参考:
RHEL7.xのVMでNetwork Adapterを追加したあとは。

centos7 ネットワーク設定

centos7のreboot時にネットワークがつながらなくてハマった話

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?