
Linuxでコマンドラインでnmcuiコマンドを使用して、IPアドレスを設定します。
記事の目次
nmcuiコマンドを実行する!
nmcuiコマンドを引数なしで実行してみます。ネットワークインターフェスに設定されたIPアドレスの情報が表示されます。
# nmcli
enp0s3: connected to enp0s3
"Intel 82540EM"
ethernet (e1000), 08:00:27:4F:21:9F, hw, mtu 1500
ip4 default
inet4 10.1.12.11/16
route4 10.1.0.0/16 metric 100
route4 default via 10.1.0.1 metric 100
lo: unmanaged
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
DNS configuration:
servers: 10.1.20.1 10.1.20.2 10.1.0.1
domains: loc.lab4ict.com
interface: enp0s3
Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.
Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
nmcuiコマンドのヘルプを表示する!
nmcuiコマンドのヘルプを表示します。IPアドレスを設定するのは、c[necction]オプションを使用することが分かります。
# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-a, --ask ask for missing parameters
-c, --colors auto|yes|no whether to use colors in output
-e, --escape yes|no escape columns separators in values
-f, --fields <field,...>|all|common specify fields to output
-g, --get-values <field,...>|all|common shortcut for -m tabular -t -f
-h, --help print this help
-m, --mode tabular|multiline output mode
-o, --overview overview mode
-p, --pretty pretty output
-s, --show-secrets allow displaying passwords
-t, --terse terse output
-v, --version show program version
-w, --wait <seconds> set timeout waiting for finishing operations
OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes
操作できるネットワークインターフェースの状態を確認する!
操作できるネットワークインターフェースの状態を表示します。
# nmcli c NAME UUID TYPE DEVICE enp0s3 d1009707-ed0f-428f-a136-e2146259c6e3 ethernet enp0s3
さらにヘルプを表示します。IPアドレスを設定するためには、m[odify]オプションを指定する必要があります。
# nmcli c --help
Usage: nmcli connection { COMMAND | help }
COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export }
show [--active] [--order <order spec>]
show [--active] [id | uuid | path | apath] <ID> ...
up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [passwd-file <file with passwords>]
down [id | uuid | path | apath] <ID> ...
add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]<setting>.<property> <value>)+]
modify [--temporary] [id | uuid | path] <ID> ([+|-]<setting>.<property> <value>)+
clone [--temporary] [id | uuid | path ] <ID> <new name>
edit [id | uuid | path] <ID>
edit [type <new_con_type>] [con-name <new_con_name>]
delete [id | uuid | path] <ID>
monitor [id | uuid | path] <ID> ...
reload
load <filename> [ <filename>... ]
import [--temporary] type <type> file <file to import>
export [id | uuid | path] <ID> [<output file>]
IPアドレスを設定するためのサンプルのコマンドも表示されます。
# nmcli c m --help
Usage: nmcli connection modify { ARGUMENTS | help }
ARGUMENTS := [id | uuid | path] <ID> ([+|-]<setting>.<property> <value>)+
Modify one or more properties of the connection profile.
The profile is identified by its name, UUID or D-Bus path. For multi-valued
properties you can use optional '+' or '-' prefix to the property name.
The '+' sign allows appending items instead of overwriting the whole value.
The '-' sign allows removing selected items instead of the whole value.
ARGUMENTS := remove <setting>
Remove a setting from the connection profile.
Examples:
nmcli con mod home-wifi wifi.ssid rakosnicek
nmcli con mod em1-1 ipv4.method manual ipv4.addr "192.168.1.2/24, 10.10.1.5/8"
nmcli con mod em1-1 +ipv4.dns 8.8.4.4
nmcli con mod em1-1 -ipv4.dns 1
nmcli con mod em1-1 -ipv6.addr "abbe::cafe/56"
nmcli con mod bond0 +bond.options mii=500
nmcli con mod bond0 -bond.options downdelay
nmcli con mod em1-1 remove sriov
IPアドレスを変更する!
IPアドレスを変更してみます。即時には変更されません。
# nmcli c m enp0s3 ipv4.method manual ipv4.addresses 10.1.0.2/16 ipv4.gateway 10.1.0.1
以下のコマンドを実行します。SSHで接続している場合は、変更したIPアドレスを指定してログインし直します。
# nmcli c down enp0s3 && nmcli c up enp0s3
nmcuiコマンドでIPアドレスが変更されたことを確認します。
# nmcli
enp0s3: connected to enp0s3
"Intel 82540EM"
ethernet (e1000), 08:00:27:4F:21:9F, hw, mtu 1500
ip4 default
inet4 10.1.0.2/16
route4 10.1.0.0/16 metric 100
route4 default via 10.1.0.1 metric 100
lo: unmanaged
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
DNS configuration:
servers: 10.1.20.1 10.1.20.2 10.1.0.1
domains: loc.lab4ict.com
interface: enp0s3
Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.
Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
おわりに
Network Managerのnmcuiコマンドを使用すると、コマンドラインからIPアドレスの設定を行うことができます。
関連記事
関連書籍(Amazon)
