トップページ > インフォメーション

自宅サーバ構築MY HOME SERVER

ネットワーク設定 固定IP設定 ネットワーク設定を有効にする方法 ファイアウォールについて

- ネットワーク設定 -

インストール直後はルータからネットワークアドレスが自動で割り当てられています。 サーバのIPアドレスを固定にします。IPアドレスは基本的に、他のローカルネットワークのパソコンと重複 していなければ、任意で設定します。本サイトはサーバローカルIPアドレスを192.168.0.10にしています。 ネットワーク接続に関する設定ファイルは/etc/network/ディレクトリ内のinterfaces です。ネットワーク接続できるようにinterfacesをviエディタで編集・保存します。

初めての設定なので、念のためディレクト構成を説明します。rootディレクトリ(管理者権限でログインした状態) からetcフォルダに入るとnetworkフォルダがあります。networkフォルダには入ると、お目当てのinterfacesファイルがあります。

まずは root でログインするところから始めます。もうすでにログインしている場合は、無視してください。
hoge123 login: hogehoge
Password: ← rootのパスワードを入力します。(入力中、何も表示されません)

Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/

  System information as of Wed Jul  4 22:47:41 JST 2012

  System load:  0.0               Processes:           72
  Usage of /:   2.9% of 53.56GB   Users logged in:     1
  Memory usage: 6%                IP address for eth0: 192.168.0.21
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

Last login: Wed Apr  4 22:37:39 2012

hogehoge@hoge123:~$ sudo -i ← この操作により設定の際、sudoコマンドの入力が不要です。
root@hoge123:~# ifconfig ← 現在割り当てられているサーバのIPアドレスを調べます。

ルーターからDHCP機能で192.168.0.21が割り当てられています。

eth0      Link encap:Ethernet  HWaddr 00:16:41:3f:b5:dd
          inet addr:192.168.0.21  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2001:a543:4015:0:11b1:1378:a84f:7d37/64 Scope:Global
          inet6 addr: 2001:a543:4015:0:216:41ff:fe3f:b5dd/64 Scope:Global
          inet6 addr: fe80::216:41ff:fe3f:b5dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3482 errors:0 dropped:0 overruns:0 frame:0
          TX packets:763 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:775124 (775.1 KB)  TX bytes:76397 (76.3 KB)
          Interrupt:17

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)




- 固定IP設定 -

/etc/network/interfacesの編集前の内容です。catコマンドを使いinterfacesの内容を確認します。 もしnetworkフォルダにいる場合は、cat interfacesを入力します。root ディレクトリにいる場合は、下記の とおりです。

では、実際に設定していきます。
root@hoge123:~# 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).

# The loopback network interface
auto lo
iface lo inet loopback

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

viエディタを使い、/etc/network/interfacesを下記内容に編集・保存してください。
※サーバ及びルータのIPアドレスは、ご自分の環境に合わせて設定してください。
      
root@hoge123:~# vi /etc/network/interfaces

下記の通り、編集・追記します。iface eth0 inet6 autoは先頭に#を付けて無効にします。
赤文字の部分はコメントですので、記載しないでください。エラーの原因になります。
# 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 static ← IP固定にする設定です。
# This is an autoconfigured IPv6 interface
#iface eth0 inet6 auto

address 192.168.0.10 ← サーバのIPアドレスです。
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1 ← ルータのIPアドレスです。
dns-nameservers 192.168.0.1 ← ルータのIPアドレスです。




- ネットワーク設定を有効にする方法 -

変更内容を反映させるために、ネットワークを再起動します。
          
root@hoge123:~# /etc/init.d/networking restart ← ネットワークを再起動します。
root@hoge123:~# ifconfig

サーバのIPアドレスが192.168.0.10に固定されました。

eth0      Link encap:Ethernet  HWaddr 00:16:41:3f:b5:dd
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2001:a543:4015:0:11b1:1378:a84f:7d37/64 Scope:Global
          inet6 addr: 2001:a543:4015:0:216:41ff:fe3f:b5dd/64 Scope:Global
          inet6 addr: fe80::216:41ff:fe3f:b5dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:111 errors:0 dropped:0 overruns:0 frame:0
          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13256 (13.2 KB)  TX bytes:11206 (11.2 KB)
          Interrupt:17

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:178 (178.0 B)  TX bytes:178 (178.0 B)



ここまで設定が完了していれば、サーバのネットワーク構成は以下の通りになります。

IP Adress : 192.168.0.10
GATEWAY : 192.168.0.1
DNS : 192.168.0.1
これでサーバはローカルのネットワーク及び、外部WAN側と固定IPアドレスで通信が可能になります。



- ファイアウォールについて -

Ubuntuはインストール時点では、ファイアウォールは無効になっています。標準でUFWと言うファイアウオール(iptabels)管理 ツールがインストールされています。 設定は無効のままで進めます。尚、iptablesは設定が全て終わり正常動作することが確認できてから、 有効にして必要な変更を加えます。

ルータのファイアウオール機能で十分と言う場合は、無効のままで運用します。iptabelsを有効にする方法は セキュリティ設定のセクションで確認してください。

自宅サーバ構築(Ubuntu12.04TLS)に戻る


Copyright(C) PCDEMAGIC All Rights Reserved.