【Ubuntu 16.04 LTS Server】Network設定を固定IPに変更

スポンサーリンク

以前の記事で、Ubuntu 16.04 LTS Serverをインストールしたが、デフォルトではIPアドレスはDHCP自動取得になっている。
サーバで運用する場合は、IPアドレスは固定にしておいた方が都合がよいので、Network設定を変更する。

現状設定の確認

/etc/network/interfacesファイルの内容を確認。

$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp3s0
iface enp3s0 inet dhcp
# This is an autoconfigured IPv6 interface
iface enp3s0 inet6 auto

私の環境では、ネットワークポート名はenp3s0となっている。

固定IPに設定する

以下のように割り当てるとする。

  • 固定IPアドレス:192.168.1.201  (割り当てるIPアドレス)
  • デフォルトゲートウェイ:192.168.1.1 (通常はルータのアドレス)
  • DNSサーバ:192.168.1.1 (通常はルータのアドレス)

/etc/network/interfaceファイルを編集。

$ sudo nano /etc/network/interface
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp3s0
#iface enp3s0 inet dhcp
iface enp3s0 inet static
address 192.168.1.201
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1

# This is an autoconfigured IPv6 interface
#iface enp3s0 inet6 auto

Networkサービスの再起動

$ sudo service networking restart

設定の確認

IPアドレス設定の確認

$ ifconfig
enp3s0    Link encap:イーサネット  ハードウェアアドレス 01:23:45:67:89:00
          inetアドレス:192.168.1.201  ブロードキャスト:192.168.1.255  マスク:255.255.255.0
     :

ゲートウェイ設定の確認

$ route -n
カーネルIP経路テーブル
受信先サイト    ゲートウェイ    ネットマスク   フラグ Metric Ref 使用数 インタフェース
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 enp3s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp3s0

補足

参照記事

Ubuntu 16.04 LTS Serverをインストール
お家サーバ用に、4/21日にリリースされたばかりの、Ubuntu 16.04 (LTS) Serverをインストールしたので、メモを残す。 そこに、WebサーバとGitサーバを構築していく予定。 以前は、Ubuntu Desktop をサー...

追記(2018/05/09)

「Ubuntu 18.04 LTS Server」では「Netplan」という方式に変更になっている。

【Ubuntu 20.04/18.04 LTS Server】ネットワーク設定を固定IPに変更
以前の記事で、Ubuntu 18.04 LTS Serverをインストールした。 「Ubuntu 18.04 LTS Server」ではインストール時に固定IPに設定できるが、DHCP自動取得でインストールした場合の固定IPに変更する手順に...

参考

  1. Linux/UbuntuでIPを自動取得から固定IPに変更する – 情報技術の四方山話

コメント

タイトルとURLをコピーしました