LoginSignup
10
7

More than 3 years have passed since last update.

nmcliをおじさん的に理解する

Last updated at Posted at 2019-03-16

古代魔術の翻訳早見表

ネットワークサービス起動/停止

# 古代魔術
$ sudo service network {start|stop}

# 現代魔術
$ sudo nmcli networking {on|off}

ネットワークサービス再起動

# 古代魔術
$ sudo service network restart

# 現代魔術
ない??
$ sudo nmcli networking off
$ sudo nmcli networking on
で対応だろうか。

これは「ネットワークサービスを再起動する」という場面がnmcliを使っているうえでは遭遇しないためと思われる。古代、ネットワークサービスを再起動する場面はifcfg-xxを編集したのちに反映させるために行うことがほとんどだが、nmcilを使うとそもそもifcfg-xxを編集する機会がない。すべて以降のコマンドで実現できるためだ。

IFの追加/削除

# 古代魔術
$ sudo ifconfig {add|del} デバイス名

# 現代魔術
$ sudo nmcli connection {add|del} デバイス名

VLANタグ付きのIF(eth0.10とか)を追加したいとき使うやつね。ただオンプレミス環境でもなければ使う機会ないのかもなぁ。

IFの起動/停止(有効化/無効化)

# 古代魔術
$ sudo {ifup|ifdown} デバイス名

# 現代魔術
$ sudo nmcli connection {up|down} デバイス名

ホスト名設定

# 古代魔術
$ sudo vim /etc/sysconfig/network
HOSTNAME=xxxxx

# 現代魔術
$ sudo nmcli general hostname xxxxx
or
$ sudo hostnamectl set-hostname xxxxx

これ現代魔術の方はいつもhostnamectl使っちゃうんだけどnmcliでやると何が違うんだろう。

IF設定(ifcfg-xxxの編集)

ここは厚く語らないといけない。

# 古代魔術
$ sudo vim /etc/sysconfig/network-scripts/ifcfg-xxx
$ sudo service network restart

# 現代魔術
$ sudo nmcli connection modify ....

おじさん達に知っておいて欲しいのはifcfg-xx直接編集は禁じられていること。
NetworkManager利用環境下ではすべてコマンドで操作します。

IF設定:BOOTPROT=dhcp

# 古代魔術
ifcfg-xxxに以下を記入
---
BOOTPROT=dhcp
---

# 現代魔術
$ sudo nmcli connection modify デバイス名 ipv4.method auto

IF設定:BOOTPROT=static

# 古代魔術
ifcfg-xxxに以下を記入
---
BOOTPROT={static|none}
IPADDR=192.168.0.98
NETMASK=255.255.255.0
---

# 現代魔術
$ sudo nmcli connection modify デバイス名 ipv4.method manual ipv4.address "192.168.0.98/24"

IF設定:ONBOOT={yes|no}

# 古代魔術
ifcfg-xxxに以下を記入
---
ONBOOT={yes|no}
---

# 現代魔術
$ sudo nmcli connection modiry デバイス名 connection.autoconnect {yes|no}

IF設定:その他

代表的なものは↑に書いた。
他にどのような設定できるかは以下を参照。

$ sudo nmcli connection show enp0s9
connection.id:                          enp0s9
connection.uuid:                        22031419-a510-4583-8a14-c6c1d3cc1f9f
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s9
connection.autoconnect:                 はい
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.auth-retries:                -1
connection.timestamp:                   0
connection.read-only:                   いいえ
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:                        default
connection.mdns:                        -1 (default)
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          いいえ
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:             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.route-table:                       0 (unspec)
ipv4.ignore-auto-routes:                いいえ
ipv4.ignore-auto-dns:                   いいえ
ipv4.dhcp-client-id:                    --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                はい
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.never-default:                     いいえ
ipv4.may-fail:                          はい
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.route-table:                       0 (unspec)
ipv6.ignore-auto-routes:                いいえ
ipv6.ignore-auto-dns:                   いいえ
ipv6.never-default:                     いいえ
ipv6.may-fail:                          はい
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.dhcp-duid:                         --
ipv6.dhcp-send-hostname:                はい
ipv6.dhcp-hostname:                     --
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:                     いいえ
proxy.pac-url:                          --
proxy.pac-script:                       --
GENERAL.NAME:                           enp0s9
GENERAL.UUID:                           22031419-a510-4583-8a14-c6c1d3cc1f9f
GENERAL.DEVICES:                        enp0s9
GENERAL.STATE:                          アクティベート中
GENERAL.DEFAULT:                        いいえ
GENERAL.DEFAULT6:                       いいえ
GENERAL.SPEC-OBJECT:                    --
GENERAL.VPN:                            いいえ
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/23
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/5
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --

その他

nmcliのオプションにいちいちconnectionとかmodifyとか面倒だったら、特定できる文字列まで打てば省略できる。

$ sudo nmcli connection modify enp0s9 ...
↓
$ sudo nmcli con mod enp0s9 ...

ぜひ覚えてほしい。

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