#author("2020-01-23T09:08:36+09:00","default:okkun-lab","okkun-lab") #author("2020-01-23T09:08:55+09:00","default:okkun-lab","okkun-lab") *NetworkManagerまとめ [#b6860ba5] -CentOS7からNetworkManagerが導入され、/etc/sysconfig/network-scripts/ifcfg-eth0などで設定しないことが推奨された。 -コマンド初見無理。 #contents *ホスト名の変更 [#c9ca2e0d] -nmcli general hostname <ホスト名> --/etc/hostnameが書き換わる -再起動 --または systemctl restart systemd-hostnamed *情報取得 [#m21cfe08] **デバイス [#xecece5a] -nmcli device DEVICE TYPE STATE CONNECTION enp2s0 ethernet connected enp2s0 enp1s0 ethernet connected enp1s0 lo loopback unmanaged -- -ip a 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 2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 group default qlen 1000 link/ether 00:1b:21:61:44:5a brd ff:ff:ff:ff:ff:ff inet 192.168.127.4/24 brd 192.168.127.255 scope global noprefixroute enp2s0 valid_lft forever preferred_lft forever 3: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 group default qlen 1000 link/ether 00:1b:21:80:38:02 brd ff:ff:ff:ff:ff:ff inet 172.27.0.2/16 brd 172.27.255.255 scope global noprefixroute enp1s0 valid_lft forever preferred_lft forever -nmcli device show <デバイス名> GENERAL.DEVICE: enp1s0 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:1B:21:80:**:** GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: enp1s0 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveCo WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 172.16.0.2/16 IP4.GATEWAY: -- IP4.ROUTE[1]: dst = 172.16.0.0/16, nh = 0.0.0.0, mt = IP4.ROUTE[2]: dst = 192.168.128.0/24, nh = 172.27.0.25 IP4.ROUTE[3]: dst = 192.168.129.0/24, nh = 172.27.0.25 IP4.ROUTE[4]: dst = 192.168.133.0/24, nh = 172.27.0.25 IP4.DNS[1]: 172.16.0.2 IP4.DNS[2]: 172.16.0.1 IP6.GATEWAY: -- **ネットワーク設定 [#ya24e26d] -nmcli connection show <デバイス名> connection.id: enp1s0 connection.uuid: b496d6a8-9657-4f84-8868-ad09b37fbed6 connection.stable-id: -- connection.type: 802-3-ethernet connection.interface-name: enp1s0 connection.autoconnect: yes connection.autoconnect-priority: 0 connection.autoconnect-retries: -1 (default) ...(略)... ipv4.method: manual ipv4.dns: 172.16.0.2,172.16.0.1 ipv4.dns-search: -- ipv4.dns-options: "" ipv4.dns-priority: 0 ipv4.addresses: 172.16.0.2/16 ipv4.gateway: -- ipv4.routes: { ip = 192.168.128.0/24, nh = 172.27.0.2 ...(略)... --設定可能な項目 **ルーティング [#z98f92f5] -route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.127.1 0.0.0.0 UG 100 0 0 enp2s0 172.16.0.0 0.0.0.0 255.255.0.0 U 101 0 0 enp1s0 192.168.127.0 0.0.0.0 255.255.255.0 U 100 0 0 enp2s0 192.168.128.0 172.16.0.254 255.255.255.0 UG 101 0 0 enp1s0 192.168.129.0 172.16.0.254 255.255.255.0 UG 101 0 0 enp1s0 192.168.133.0 172.16.0.254 255.255.255.0 UG 101 0 0 enp1s0 -ip route default via 192.168.127.1 dev enp2s0 proto static metric 100 172.27.0.0/16 dev enp1s0 proto kernel scope link src 172.16.0.2 metric 101 192.168.127.0/24 dev enp2s0 proto kernel scope link src 192.168.127.4 metric 100 192.168.128.0/24 via 172.16.0.254 dev enp1s0 proto static metric 101 192.168.129.0/24 via 172.16.0.254 dev enp1s0 proto static metric 101 192.168.130.0/24 via 172.16.0.254 dev enp1s0 proto static metric 101 --route -nと同じ内容 *NIC上げ [#z00076a6] -nmcli connection up <デバイス名> *NICの追加 [#d785810f] -NICを物理的に追加したときに実施 --nmcli deviceでSTATEがdisconnectだったり、/etc/sysconfig/network-scripts/ifcfg-enp2s0などができていない場合 -nmcli connection add type <デバイスタイプ> ifname <ifname名> con-name <接続名> --例: nmcli connection add type ethernet ifname enp2s0 con-name enp2s0 --/etc/sysconfig/network-scripts/ifcfg-enp2s0ができあがる -ちなみに --後述するIPアドレスやルーティングを消したいときに、nmcli connection delete などと打ち込むとデバイスごと消すことになるので注意。 *デバイス名の変更 [#s04eb74e] -nmcli connection modify <旧デバイス名> connection.interface-name <新デバイス名> connection.id enp0s8 --nmcli connection modify "Wired connection 1" connection.interface-name enp3s0 connection.id enp3s0 *NICにIPアドレスを振る [#l09a1245] -nmcli connection modify <デバイス名> ipv4.method manual ipv4.addresses <IPアドレス> --nmcli connection modify enp3s0 ipv4.method manual ipv4.addresses 10.0.0.1/24 -逆にNICを無効にしたい場合は --ipv4.method ignore -IPv6を無効にしたい --ipv6.method ignore *NICの自動起動 [#w7523f3f] -nmcli connection modify <デバイス名> connection.autoconnect yes *デフォルトゲートウエイ [#f77ab340] -nmcli connection modify <デバイス名> ipv4.gateway <ゲートウェイIP> --nmcli connection modify enp3s0 ipv4.gateway 192.168.151.254 *スタティックルート [#a91eb073] -nmcli connection modify <デバイス名> ipv4.routes "<ネットワーク>/<マスク> <ゲートウェイ>" --nmcli connection modify enp3s0 ipv4.routes "192.168.0.0/16 192.168.151.254" -複数指定したいときは --nmcli connection modify enp3s0 ipv4.routes "192.168.0.0/16 192.168.151.254, 192.168.1.0/24 192.168.151.254" *DNS [#c9ca3117] -nmcli connection modify <デバイス名> ipv4.dns <DNSサーバ> --nmcli connection modify enp3s0 ipv4.dns "192.168.130.2 192.168.130.1" *設定反映 [#rcacc77b] -systemctl restart network.service *参考 [#e9a28eaf] -100%レンタルサーバーを使いこなすサイト --https://go-journey.club/archives/4124 -CentOS7のnmcliコマンドについて --https://qiita.com/ytooyama/items/847250f17fa7715f3037