CentOS7 ネットワーク設定(Connection追加)
Linuxに不慣れでネットワーク設定に苦戦したので、今後のためにメモ。
環境
OS | CentOS Linux release 7.5.1804 |
---|
ネットワーク設定の考え方
- Device
Windowsでいうところのネットワークアダプタ - Connection
ネットワークアダプタの設定内容
ConnectionにIPアドレス等を設定し、それをDeviceに割り当てる。
設定手順
例)有線LAN Device:eth1に既存のConnectionがない場合に、新規でConnectionを作成しIPアドレス等を設定してネットワークに接続する。
1.Connectionの追加
コマンドを実行し、対象DeviceにConnectionを追加する。IPアドレスを設定してから接続するため、自動接続を無効にする。
Connectionを追加 | nmcli connection add type ethernet ifname [対象Device名] autoconnect no |
---|
# nmcli connection add type ethernet ifname eth1 autoconnect no 接続 'ethernet-eth1' (xxxxff5e-b602-4d73-a332-0ee1c722xxxx) が正常に追加されました。
コマンドを実行し、追加されたConnectionを確認する。
Connection 一覧を表示 | nmcli connection |
---|
# nmcli connection NAME UUID TYPE DEVICE ethernet-eth1 xxxxff5e-b602-4d73-a332-0ee1c722xxxx ethernet --
2.Connectionの設定
Connection(ethernet-eth1)を設定するコマンドを実行する。
ipv4アドレスを192.168.200.100に設定 | nmcli connection modify ethernet-eth1 ipv4.method manual ipv4.addresses '192.168.200.100/24' |
---|---|
DNSサーバを設定 | nmcli connection modify ethernet-eth1 ipv4.dns '192.168.200.1' |
デフォルトゲートウェイを設定 | nmcli connection modify ethernet-eth1 ipv4.gateway '192.168.200.1' |
ipv6を無効化 | nmcli connection modify ethernet-eth1 ipv6.method ignore |
自動接続を有効化 | nmcli connection modify ethernet-eth1 autoconnect yes |
3.Deviceを接続
自動接続を有効にしたので、すでに接続されているはず。コマンドを実行して状態を確認する。
Device 一覧を表示 | nmcli device |
---|
# nmcli device
DEVICE TYPE STATE CONNECTION
eth1 ethernet 接続済み ethernet-eth1
接続されていない場合はコマンドを実行して手動で接続する。
Deviceを接続 | nmcli device connect eth1 |
---|
# ping www.google.co.jp PING www.google.co.jp (172.217.31.131) 56(84) bytes of data. 64 bytes from nrt20s08-in-f3.1e100.net (172.217.31.131): icmp_seq=1 ttl=50 time=29.3 ms 64 bytes from nrt20s08-in-f3.1e100.net (172.217.31.131): icmp_seq=2 ttl=50 time=25.9 ms 64 bytes from nrt20s08-in-f3.1e100.net (172.217.31.131): icmp_seq=3 ttl=50 time=28.9 ms ^C --- www.google.co.jp ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 25.912/28.072/29.363/1.543 ms
正常に接続できました!