LoginSignup
15
13

More than 3 years have passed since last update.

CentOS7におけるネットワーク設定・確認

Last updated at Posted at 2020-03-16

環境

  • CentOS Linux release 7.7.1908
実行結果
[root@CENTOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@CENTOS7 ~]#

1. ホスト名

1.1. ホスト名の確認

hostname
または
cat /etc/hostname

実行結果
[root@CENTOS7 ~]# hostname
CENTOS7
[root@CENTOS7 ~]#
実行結果
[root@CENTOS7 ~]# cat /etc/hostname
CENTOS7
[root@CENTOS7 ~]#

1.2. ホスト名の変更

nmcli general hostname <ホスト名>
または
hostnamectl set-hostname <ホスト名>

実行結果
[root@CENTOS7 ~]# nmcli general hostname CENTOS7AF
[root@CENTOS7 ~]# hostname
CENTOS7AF
[root@CENTOS7 ~]# cat /etc/hostname
CENTOS7AF
[root@CENTOS7 ~]#
実行結果
[root@CENTOS7 ~]# hostnamectl set-hostname CENTOS7AF
[root@CENTOS7 ~]# hostname
centos7af
[root@CENTOS7 ~]# cat /etc/hostname
centos7af
[root@CENTOS7 ~]#

hostnamectl set-hostname <ホスト名>の場合、小文字で設定されました。

2. ネットワークインターフェース

2.1. ネットワーク物理インターフェース(device)の一覧表示

nmcli device

実行結果
[root@CENTOS7 ~]# nmcli device
DEVICE  TYPE      STATE     CONNECTION
enp0s3  ethernet  接続済み  enp0s3
lo      loopback  管理無し  --
[root@CENTOS7 ~]#

2.2 ネットワーク物理インターフェース(device)の詳細表示

nmcli device show <デバイス名>

実行結果
[root@CENTOS7 ~]# nmcli device show enp0s3
GENERAL.DEVICE:                         enp0s3
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:57:A3:39
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (接続済み)
GENERAL.CONNECTION:                     enp0s3
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveCo
WIRED-PROPERTIES.CARRIER:               オン
IP4.ADDRESS[1]:                         192.168.0.11/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt =
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt =
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP6.ADDRESS[1]:                         fe80::2eca:a058:c18f:fd7e/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table
[root@CENTOS7 ~]#

2.3. ネットワーク論理インターフェース(connection)の一覧表示

nmcli connection

実行結果
[root@CENTOS7 ~]# nmcli connection
NAME    UUID                                  TYPE      DEVICE
enp0s3  0f174b12-5dc6-40c9-99fc-06c6ce550c24  ethernet  enp0s3
[root@CENTOS7 ~]#

2.4. ネットワーク論理インターフェース(connection)の詳細表示

nmcli connection show <コネクション名>

実行結果
[root@CENTOS7 ~]# nmcli connection show enp0s3
connection.id:                          enp0s3
connection.uuid:                        0f174b12-5dc6-40c9-99fc-06c6ce550c24
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s3
connection.autoconnect:                 はい
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   1584364512
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)
connection.llmnr:                       -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:                            manual
ipv4.dns:                               8.8.8.8,8.8.4.4
ipv4.dns-search:                        --
ipv4.dns-options:                       ""
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.0.11/24
ipv4.gateway:                           192.168.0.1
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
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.routing-rules:                     --
ipv6.ignore-auto-routes:                いいえ
ipv6.ignore-auto-dns:                   いいえ
ipv6.never-default:                     いいえ
ipv6.may-fail:                          はい
ipv6.ip6-privacy:                       0 (disabled)
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:                           enp0s3
GENERAL.UUID:                           0f174b12-5dc6-40c9-99fc-06c6ce550c24
GENERAL.DEVICES:                        enp0s3
GENERAL.STATE:                          アクティベート済み
GENERAL.DEFAULT:                        はい
GENERAL.DEFAULT6:                       いいえ
GENERAL.SPEC-OBJECT:                    --
GENERAL.VPN:                            いいえ
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveCo
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         192.168.0.11/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt =
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt =
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP6.ADDRESS[1]:                         fe80::2eca:a058:c18f:fd7e/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table
[root@CENTOS7 ~]#

上記設定を変更するコマンドは以下となります。
nmcli connection modify <コネクション名> <項目名> <値>

IPアドレスを192.168.0.12/24に変更
nmcli connection modify enp0s3 ipv4.address 192.168.0.12/24

実行結果
[root@CENTOS7 ~]# nmcli connection modify enp0s3 ipv4.address 192.168.0.12/24
[root@CENTOS7 ~]#

DNSサーバを208.67.222.222と208.67.220.220に変更
nmcli connection modify enp0s3 ipv4.dns "208.67.222.222 208.67.220.220"

実行結果
[root@CENTOS7 ~]# nmcli connection modify enp0s3 ipv4.dns "208.67.222.222 208.67.220.220"
[root@CENTOS7 ~]#

NetworkManagerを再起動することで有効となります。

systemctl restart NetworkManager

実行結果
[root@CENTOS7 ~]# systemctl restart NetworkManager
[root@CENTOS7 ~]#

上記設定の場合、IPアドレスの変更はインターフェースコネクションを再起動(非アクティブ→アクティブ)する必要がありました。

以下のコマンドで手動でインターフェースコネクションをアクティブ/非アクティブに設定することがです。

インターフェースコネクションを非アクティブにする。
nmcli connection down <コネクション名>

実行結果
[root@CENTOS7 ~]# nmcli connection down enp0s3
接続 'enp0s3' が正常に非アクティブ化されました (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@CENTOS7 ~]#

インターフェースコネクションをアクティブにする。
nmcli connection up <コネクション名>

実行結果
[root@CENTOS7 ~]# nmcli connection up enp0s3
接続が正常にアクティベートされました (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@CENTOS7 ~]#

2.5. ネットワークインターフェースの確認(昔のifconfigの代わり)

ip addr show

実行結果
[root@CENTOS7 ~]# ip addr 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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:57:a3:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.11/24 brd 192.168.0.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::2eca:a058:c18f:fd7e/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@CENTOS7 ~]#

3. TUI(テキストユーザインタフェース)によるネットワークの設定

以下のコマンドでTUI(テキストユーザインタフェース)でネットワークの設定が可能です。

nmtui

[root@CENTOS7 ~]# nmtui

01.png

4. その他

CentOS7ではifconfigroutenetstatarp等のネットワーク関連コマンドが入っていません。これらのコマンドは、「net-tools」パッケージを追加することで利用可能になります。

yum install net-tools

「net-tools」パッケージを導入しない環境では、「iproute2」パッケージに含ま れる「ip, ss」等のコマンドを使用します。

コマンド対応表

net-tools iproute2
ifconfig ip addr、ip link
route ip route
netstat ss
netstat -i ip -s link
arp ip neighbor

以上

15
13
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
15
13