ボールを蹴りたいシステムエンジニア

ボール蹴りが大好きなシステムエンジニア、ボールを蹴る時間確保の為に時間がある時には勉強する。

CentOS7でローカルIPの設定方法(インストール時に設定したIPでアクセスできなかった時の対処方法)

VMwareでCentOS7環境構築後、インストール時に設定したローカルIPでsshしてもアクセスできないので調査。

取り敢えず、VMwareで直接ログイン後、ip確認

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:95:5b:a0  txqueuelen 1000  (Ethernet)
        RX packets 18611  bytes 2193599 (2.0 MiB)
        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

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 1796  bytes 156244 (152.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1796  bytes 156244 (152.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:97:16:dd  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.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

イーサネットのeth*が無い?と思いきや、CentOS7からはNICの命名規約が変わったとの事。
接頭語ならびにデバイス種別によって決まるらしい。

下記サイトの「Predictable Network Interface Names」が参考になります。
CentOS7におけるNIC命名ルール - 雑木林


上記例だと、ens33がイーサネットという事になりそう。

ネットワークマネージャーコマンドで当該デバイスの情報を確認。

[root@localhost ~]# nmcli con show ens33
connection.id:                          ens33
connection.uuid:                        a9e06db7-29a4-4a9c-80d6-535072025cda
connection.stable-id:                   --
connection.interface-name:              ens33
connection.type:                        802-3-ethernet
connection.autoconnect:                 no
connection.autoconnect-priority:        0
connection.timestamp:                   1483755043
connection.read-only:                   no
connection.permissions:                 
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 
connection.gateway-ping-timeout:        0
connection.metered:                     不明
connection.lldp:                        -1 (default)
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          yes
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:   
802-3-ethernet.mtu:                     自動
802-3-ethernet.s390-subchannels:        
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:            
802-3-ethernet.wake-on-lan:             1 (default)
802-3-ethernet.wake-on-lan-password:    --
ipv4.method:                            auto
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.dns-options:                       (デフォルト)
ipv4.dns-priority:                      0
ipv4.addresses:                         
ipv4.gateway:                           --
ipv4.routes:                            
ipv4.route-metric:                      -1
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-timeout:                      0
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.dad-timeout:                       -1 (default)
ipv6.method:                            auto
ipv6.dns:                               
ipv6.dns-search:                        
ipv6.dns-options:                       (デフォルト)
ipv6.dns-priority:                      0
ipv6.addresses:                         
ipv6.gateway:                           --
ipv6.routes:                            
ipv6.route-metric:                      -1
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (不明)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.token:                             --

connection.autoconnectがnoとなっており起動時に自動起動してないのが原因ぽい。
また、ipv4.methodがautoなのでDHCPで自動的にローカルIPが割り当てられ、インストール時に設定したIPが利用されない。

対策として、各値を設定

[root@localhost ~]# nmcli con mod ens33 connection.autoconnect "yes"
[root@localhost ~]# nmcli con mod ens33 ipv4.addresses "192.168.10.117/24"
[root@localhost ~]# nmcli con mod ens33 ipv4.method "manual"

上から、
サーバー起動時にコネクションを自動接続、
ローカルIPを設定
ローカルIPの設定方法を手動

ローカルIPでの"/24" は24 ビットがネットワーク部という意味となるので"192.168.10" までがネットワーク部であることを示して、残りの"117"がホスト部であることを示しています。

当該ネットワークインターフェースを再起動

[root@localhost ~]# nmcli device disconnect ens33
デバイス 'ens33' が正常に切断されました。
[root@localhost ~]# nmcli device connect ens33
デバイス 'ens33' が 'a9e06db7-29a4-4a9c-80d6-535072025cda' で正常にアクティベートされました。

ローカルIPが割り振られている事を確認

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.117  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::3783:791a:32c5:d0d0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:95:5b:a0  txqueuelen 1000  (Ethernet)
        RX packets 19175  bytes 2262492 (2.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 120  bytes 13822 (13.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

参考

qiita.com