この記事は約35分43秒で読むことができます。

nmcliコマンドで物理NICを再設定してみた話

参考文献

NetworkManagerの設定変更、nmtuiとnmcliについてまとめたよ!  

再設定前

コード表示

[oracle@centos ~]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3d2fca6b-9fdc-4e0f-bd92-9bdc0bce16f0  bridge    docker0 
eno1     07b6ee3f-20bc-475a-ae19-586062dd98e1  ethernet  eno1    
[oracle@centos ~]$ ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::60d7:c81e:a23e:623/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:89:15:22:84 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
[oracle@centos ~]$ cd /etc/sysconfig/network-scripts/
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 10:08 ifcfg-eno1
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
[oracle@centos network-scripts]$ sudo cp ifcfg-eno1{,_org}
[sudo] oracle のパスワード:
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 10:08 ifcfg-eno1
-rw-r--r--. 1 root root   346  6月  1 10:16 ifcfg-eno1_org
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
[oracle@centos network-scripts]$ sudo diff ifcfg-eno1{,_org}
[oracle@centos network-scripts]$ cat ifcfg-eno1
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
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=eno1
UUID=07b6ee3f-20bc-475a-ae19-586062dd98e1
DEVICE=eno1
ONBOOT=yes
IPADDR=192.168.1.109
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.1.1

nmcliで接続設定を削除

nmcli c delete 07b6ee3f-20bc-475a-ae19-586062dd98e1書き忘れた。。そのあと、nmcli c show。ip a show。確認忘れない。

コード表示

[oracle@centos ~]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3d2fca6b-9fdc-4e0f-bd92-9bdc0bce16f0  bridge    docker0 
eno1     07b6ee3f-20bc-475a-ae19-586062dd98e1  ethernet  eno1    
[oracle@centos ~]$ ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::60d7:c81e:a23e:623/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:89:15:22:84 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

削除した接続設定を元に戻す

コード表示

[oracle@centos network-scripts]$ nmcli c add type ethernet ifname eno1 con-name eno1
接続 'eno1' (aada411e-26e2-47b6-b928-d0536bdab98c) が正常に追加されました。
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   278  6月  1 10:20 ifcfg-eno1
-rw-r--r--. 1 root root   346  6月  1 10:16 ifcfg-eno1_org
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
[oracle@centos network-scripts]$ ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.27/24 brd 192.168.1.255 scope global noprefixroute dynamic eno1
       valid_lft 86385sec preferred_lft 86385sec
    inet6 fe80::c7ed:b259:e5a2:20f9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:89:15:22:84 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
[oracle@centos network-scripts]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3d2fca6b-9fdc-4e0f-bd92-9bdc0bce16f0  bridge    docker0 
eno1     aada411e-26e2-47b6-b928-d0536bdab98c  ethernet  eno1    
[oracle@centos network-scripts]$ nmcli con modify eno1 ipv4.method manual ipv4.address "192.168.1.109/24" ipv4.gateway "192.168.1.1" ipv4.dns 192.168.1.1
[oracle@centos network-scripts]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3d2fca6b-9fdc-4e0f-bd92-9bdc0bce16f0  bridge    docker0 
eno1     aada411e-26e2-47b6-b928-d0536bdab98c  ethernet  eno1    
[oracle@centos network-scripts]$ ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.27/24 brd 192.168.1.255 scope global noprefixroute dynamic eno1
       valid_lft 86297sec preferred_lft 86297sec
    inet6 fe80::c7ed:b259:e5a2:20f9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:89:15:22:84 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 10:21 ifcfg-eno1
-rw-r--r--. 1 root root   346  6月  1 10:16 ifcfg-eno1_org
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
[oracle@centos network-scripts]$ sudo diff ifcfg-eno1{,_org}
[sudo] oracle のパスワード:
13c13
< UUID=aada411e-26e2-47b6-b928-d0536bdab98c
---
> UUID=07b6ee3f-20bc-475a-ae19-586062dd98e1
[oracle@centos network-scripts]$ reboot
[oracle@centos ~]$ ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::c7ed:b259:e5a2:20f9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:75:74:06:06 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
[oracle@centos ~]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3c7a092e-b4a1-4ded-8c83-7204645a706a  bridge    docker0 
eno1     aada411e-26e2-47b6-b928-d0536bdab98c  ethernet  eno1    
eno1     07b6ee3f-20bc-475a-ae19-586062dd98e1  ethernet  --      
[oracle@centos ~]$ cd /etc/sysconfig/network-scripts/
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 10:21 ifcfg-eno1
-rw-r--r--. 1 root root   346  6月  1 10:16 ifcfg-eno1_org
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
[oracle@centos network-scripts]$ traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  gateway (192.168.1.1)  1.456 ms  1.384 ms  1.405 ms
 2  nas827.p-kanagawa.nttpc.ne.jp (210.153.251.235)  5.188 ms  5.197 ms  5.192 ms
 3  210.139.125.169 (210.139.125.169)  5.468 ms  5.174 ms  5.168 ms
 4  210.165.249.177 (210.165.249.177)  6.734 ms  5.736 ms  6.394 ms
 5  0-0-0-18.tky-no-acr01.sphere.ad.jp (210.153.241.89)  9.280 ms  9.295 ms  9.292 ms
 6  0-0-1-0--2025.tky-t4-bdr01.sphere.ad.jp (202.239.117.14)  9.940 ms  6.531 ms  6.764 ms
 7  72.14.205.32 (72.14.205.32)  6.619 ms  6.769 ms  6.835 ms
 8  * * *
 9  google-public-dns-a.google.com (8.8.8.8)  7.145 ms  7.120 ms  7.972 ms

あとかたづけ

なぞに残っているので、けす。

コード表示

[oracle@centos network-scripts]$ nmcli c delete 07b6ee3f-20bc-475a-ae19-586062dd98e1
接続 'eno1' (07b6ee3f-20bc-475a-ae19-586062dd98e1) が正常に削除されました。
[oracle@centos network-scripts]$ nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3c7a092e-b4a1-4ded-8c83-7204645a706a  bridge    docker0 
eno1     aada411e-26e2-47b6-b928-d0536bdab98c  ethernet  eno1    

あとかたづけしなくてもすむように考えた

ifcfg-eno1_orgではなくてorg_ifcfg-eno1としてみた。接頭辞にorg_つけるといいね。

コード表示

[oracle@centos ~]$ cd /etc/sysconfig/network-scripts
[oracle@centos network-scripts]$ ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 11:08 ifcfg-eno1
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
-rw-r--r--. 1 root root   346  6月  1 11:08 org_ifcfg-eno1
[oracle@centos network-scripts]$ cat def_eno@.sh
#!/bin/bash
NM="$1"
( cd /etc/sysconfig/network-scripts; cp {,org_}ifcfg-eno${NM}; diff {,org_}ifcfg-eno${NM}; )
nmcli c del $(nmcli c show | grep eno${NM} | awk '{print $2}')
nmcli c add type ethernet ifname eno${NM} con-name eno${NM}
nmcli c modify eno${NM} ipv4.method manual ipv4.address "192.168.1.109/24" ipv4.gateway "192.168.1.1" ipv4.dns 192.168.1.1
nmcli c down eno${NM}
nmcli c up eno${NM}
( cd /etc/sysconfig/network-scripts; diff {,org_}ifcfg-eno${NM}; )
[oracle@centos network-scripts]$ ll | grep def_eno@.sh
-rwxr-xr-x. 1 root root   468  6月  1 11:11 def_eno@.sh
[oracle@centos network-scripts]$ su root
パスワード:
[root@centos network-scripts]# nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3c7a092e-b4a1-4ded-8c83-7204645a706a  bridge    docker0 
eno1     f42175a9-09a5-439d-93ff-a04191bd00e7  ethernet  eno1    
[root@centos network-scripts]# ip a show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::d892:e414:f9a2:1682/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@centos network-scripts]# ./def_eno@.sh 1
接続 'eno1' (fc806969-5b90-46c4-8683-5fc395e58194) が正常に削除されました。
接続 'eno1' (9240bee1-d231-46c2-8159-95b77b75da78) が正常に追加されました。
接続 'eno1' が正常に非アクティブ化されました (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/15)
接続が正常にアクティベートされました (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/16)
13c13
< UUID=9240bee1-d231-46c2-8159-95b77b75da78
---
> UUID=fc806969-5b90-46c4-8683-5fc395e58194
[root@centos network-scripts]# ll | grep ifcfg
-rw-r--r--. 1 root root   346  6月  1 11:14 ifcfg-eno1
-rw-r--r--. 1 root root   254  1月  3  2018 ifcfg-lo
-rw-r--r--. 1 root root   346  6月  1 11:14 org_ifcfg-eno1
[root@centos network-scripts]# ip a show eno1
2: eno1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::eaf1:8b0e:e52d:d28a/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@centos network-scripts]# nmcli c show
NAME     UUID                                  TYPE      DEVICE  
docker0  3c7a092e-b4a1-4ded-8c83-7204645a706a  bridge    docker0 
eno1     9240bee1-d231-46c2-8159-95b77b75da78  ethernet  eno1    

[root@centos network-scripts]# traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  gateway (192.168.1.1)  0.464 ms  0.441 ms  0.412 ms
 2  nas827.p-kanagawa.nttpc.ne.jp (210.153.251.235)  4.886 ms  4.788 ms  5.022 ms
 3  210.139.125.169 (210.139.125.169)  4.566 ms  4.962 ms  4.822 ms
 4  210.165.249.177 (210.165.249.177)  5.737 ms  5.895 ms  5.654 ms
 5  0-0-0-18.tky-no-acr01.sphere.ad.jp (210.153.241.89)  6.630 ms  9.839 ms  9.847 ms
 6  0-0-1-0--2025.tky-t4-bdr01.sphere.ad.jp (202.239.117.14)  10.507 ms  10.092 ms  9.996 ms
 7  72.14.202.229 (72.14.202.229)  9.428 ms 72.14.205.32 (72.14.205.32)  6.533 ms  6.509 ms
 8  * * *
 9  google-public-dns-a.google.com (8.8.8.8)  6.456 ms  6.793 ms  7.254 ms

Leave a Reply

Your email address will not be published. Required fields are marked *