ミムの部屋

社内SEが,興味をもったことを書いていきます.

Ubuntu 14.04 LTSでの固定IPアドレスの方法

今回は,Ubuntu サーバでのIPアドレスを固定する方法をつらつら書いていきたいともいます. アドレスが固定されいないと,たまに接続できなくなるときがあったので,がっちり固定しいきたいと思います.

まずは,いじるファイルは/etc/network/interfacesです.ここにデフォルトでは,DHCPによってアドレスが割り振られます.それをがっちり固定するために,nano,vimなどのエディタで編集を行います.そのため,以下のコマンドをまず入れます.

sudo nano /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 eth0
iface eth0 inet dhcp # ここがDHCPで振り分けるように指示している.
以下のように書き換える.
# 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 eth0
#iface eth0 inet dhcp # DHCPで振り分ける指示をコメントアウト.
iface eth0 inet static # 固定アドレスにするように指示

# add for static IP address
address 192.168.0.44         #固定IPアドレスを書く
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.1.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1

変更を認識するために,/etc/init.d/networkingを再起動する.
sudo /etc/init.d/networking restart

参考サイト