nmcli
NetworkManagerのコマンドラインツールnmcliの使い方。
ipアドレス設定
# nmcli con mod eth0 ipv4.addresses 192.168.0.78/24 # nmcli con mod eth0 ipv4.method manual # nmcli con mod eth0 ipv4.gateway 192.168.0.1 # nmcli con mod eth0 ipv4.dns 192.168.0.1 # nmcli con mod eth0 connection.autoconnect yes
リンク制御
# nmcli con up eth0 # nmcli con down eth0
デバイス表示
# nmcli dev デバイス タイプ 状態 接続 enp0s3 ethernet 接続済み enp0s3 lo loopback 管理無し # # nmcli con 名前 UUID タイプ デバイス enp0s3 a85a0edf-2fec-30d0-a01b-ed6c9544f9d6 802-3-ethernet enp0s3 #
vlan作成
$ nmcli con add type vlan ifname VLAN10 dev eth0 id 10 Connection 'vlan-VLAN10' (37750b4a-8ef5-40e6-be9b-4fb21a4b6d17) successfully added. $ nmcli con add type vlan con-name VLAN12 dev eth0 id 12 Connection 'VLAN12' (b796c16a-9f5f-441c-835c-f594d40e6533) successfully added.
dns and gw
# デフォルトゲートウェイの設定 / 削除コマンド nmcli connection modify enp0s3 ipv4.gateway 10.0.0.1 nmcli connection modify enp0s3 ipv4.gateway 0.0.0.0 # DNS設定の設定 / 削除コマンド nmcli connection modify enp0s3 ipv4.dns 8.8.8.8 nmcli connection modify enp0s3 +ipv4.dns 8.8.4.4 nmcli connection modify enp0s3 -ipv4.dns 8.8.8.8 -ipv4.dns 8.8.4.4
残り
# nmcli con add type eth ifname '*' con-name eth0 接続 'eth0' (04c1f188-2c6e-4159-b530-f2c465c1128c) が正常に追加されました。 # # nmcli con 名前 UUID タイプ デバイス enp0s3 a85a0edf-2fec-30d0-a01b-ed6c9544f9d6 802-3-ethernet enp0s3 eth0 04c1f188-2c6e-4159-b530-f2c465c1128c 802-3-ethernet -- # # nmcli con show eth0 connection.id: eth0 connection.uuid: 04c1f188-2c6e-4159-b530-f2c465c1128c connection.stable-id: -- connection.interface-name: -- connection.type: 802-3-ethernet connection.autoconnect: yes connection.autoconnect-priority: 0 connection.timestamp: 0 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: -- # # nmcli con mod eth0 connection.autoconnect yes # nmcli con mod eth0 ipv4.method manual エラー: 接続 'eth0' の変更に失敗しました: ipv4.addresses: 'method=manual' のこのプロパティーを空にすることはできません # nmcli con mod eth0 ipv4.addresses 192.168.0.78/24 # nmcli con mod eth0 ipv4.method manual # nmcli con mod eth0 ipv4.gateway 192.168.0.1 # nmcli con mod eth0 ipv4.dns 192.168.0.1 # # nmcli con show eth0 connection.id: eth0 connection.uuid: 04c1f188-2c6e-4159-b530-f2c465c1128c connection.stable-id: -- connection.interface-name: -- connection.type: 802-3-ethernet connection.autoconnect: yes connection.autoconnect-priority: 0 connection.timestamp: 0 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: manual ipv4.dns: 192.168.0.1 ipv4.dns-search: ipv4.dns-options: (デフォルト) ipv4.dns-priority: 0 ipv4.addresses: 192.168.0.78/24 ipv4.gateway: 192.168.0.1 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: -- # # cat /etc/sysconfig/network-scripts/ifcfg-eth0 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=eth0 UUID=04c1f188-2c6e-4159-b530-f2c465c1128c ONBOOT=yes IPADDR=192.168.0.78 PREFIX=24 GATEWAY=192.168.0.1 DNS1=192.168.0.1 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes # # nmcli con down enp0s3 && nmcli con up eth0 ifname enp0s3 接続プロファイルの適用には、ネットワークの切断(再起動)が必要です。 SSH が切断されたら再接続します。 $ nmcli con 名前 UUID タイプ デバイス eth0 04c1f188-2c6e-4159-b530-f2c465c1128c 802-3-ethernet enp0s3 enp0s3 a85a0edf-2fec-30d0-a01b-ed6c9544f9d6 802-3-ethernet -- $ $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:ab:65:58 brd ff:ff:ff:ff:ff:ff inet 192.168.0.78/24 brd 192.168.0.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 2001:a450:4b:b300:8633:4f:6ae2:e32f/64 scope global tentative noprefixroute dynamic valid_lft 2591998sec preferred_lft 604798sec inet6 fe80::d10a:4b3c:60d8:ec22/64 scope link valid_lft forever preferred_lft forever $