【LIVA】【Ubuntu server14.04】ローカルマシンに固定IP付与

DHCPだと都合が悪いので固定IPを割り振ります。

 

1.経路テーブルを一応確認

使っているインタフェースを確認するため、念のため実行します。

$ netstat -nr
カーネルIP経路テーブル
受信先サイト    ゲートウェイ    ネットマスク   フラグ   MSS Window  irtt インタ フェース
0.0.0.0         192.168.11.1    0.0.0.0         UG        0 0          0 p2p1
192.168.11.0    0.0.0.0         255.255.255.0   U         0 0          0 p2p1

使っているインタフェースは「p2p1」、ネットワークは192.168.11.0を使ってるのがわかりますね。

 

2.インタフェースに対する固定IPの設定

$sudo vi /etc/network/interfaces 

 

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

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto p2p1
iface p2p1 inet dhcp

 

初期状態ではp2p1はdhcpを使うようになっているので、

auto p2p1

#iface p2p1 inet dhcp
iface p2p1 inet static
address 192.168.11.38  ←末番を38(サーバ)に変更
netmask 255.255.255.0
gateway 192.168.11.1

network 192.168.11.0
broadcast 192.168.11.255
dns-nameservers 192.168.11.1

#でコメントアウトをして、その下にIPアドレス(+その他)を設定してあげます。

 

3.ネットワークの再起動

ネットワークインタフェースを再起動して、IPアドレスを設定します。

※ファイルを書き換えただけでは適用されません。

 

$sudo /etc/init.d/networking restart

 

上記でできるはずですが、もし変わってなさそうであれば、サーバ再起動で。

再起動後は新IPアドレスにアクセスするように。 

 ※追記:どうもUbuntu14.04では上記コマンドはうまく動作しないようなので以下のようにコマンドを打つべし

$sudo service networking restart

stop: Job failed while stopping
start: Job is already running: networking

4.IPアドレスの確認

$ ifconfig -a
p2p1      Link encap:イーサネット  ハードウェアアドレス xx:xx:xx:xx:xx:xx
inetアドレス:192.168.11.38  ブロードキャスト:192.168.11.255  マスク:255.255.255.0
inet6アドレス: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 範囲:グローバ ル
inet6アドレス: xxxx::xxxx:xxxx:xxxx:xxxx/64 範囲:リンク
inet6アドレス: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 範囲:グローバ ル
UP BROADCAST RUNNING MULTICAST  MTU:1500  メトリック:1
RXパケット:351 エラー:0 損失:0 オーバラン:0 フレーム:0
TXパケット:65 エラー:0 損失:0 オーバラン:0 キャリア:0
衝突(Collisions):0 TXキュー長:1000
RXバイト:29798 (29.7 KB)  TXバイト:11223 (11.2 KB)

インタフェースに新しいIPアドレスが割り振られてるのが確認できました。