LoginSignup
7
15

More than 5 years have passed since last update.

Ubuntu16.04で複数ネットワークの設定

Last updated at Posted at 2018-05-11

環境

Ubuntu16.04(Windows Server2012 r2内のHyper-V上)
Hyper-Vの仮想スイッチマネージャーで複数のNICを設定
(NICが複数ある実サーバでも可)

ネットワーク構成

eth0(NIC#1)に192.168.0.1/24
eth1(NIC#2)に128.20.0.1/16
を割り当てる。
インターネットは192.168.0.1の方を通る。

INTERNET
|
192.168.0.254(デフォゲ・ルータ)
192.168.0.0/24(ネットワークアドレス)
192.168.0.1(eth0,NIC#1)
|
Ubuntu
|
128.20.0.1(eth1,NIC#2)
128.20.0.0/16(ネットワークアドレス)
128.20.0.254

ネットワークの確認

sh
$sudo lshw -short -class network

このような表示が出てくる

H/W path        Device      Class      Description
==================================================
/1              eth1        network    Ethernet interface
/2              eth0        network    Ethernet interface

/etc/network/interfacesを開く

$ cat /etc/network/interfaces

こんな感じ。eth1が認識されていない。

/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 eth0
iface eth0 inet dhcp

まずeth1をdhcpしてみる。
eth1のネットワークがdhcpなのが前提なので、不要ならば飛ばしても構わない。
interfaces ファイルを編集

$ sudo pico /etc/network/interfaces

以下を追加

/etc/network/interfaces
# The secondary network interface
auto eth1
iface eth1 inet dhcp

eth1を起動

$ sudo ifup eth1

何やらDHCPを参照してIPが付与されることを確認。

スタティックIPの設定

dhcpからstaticにする。

/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 eth0
#iface eth0 inet dhcp
iface eth0 inet static
  address 192.168.0.1
  netmask 255.255.255.0
  gateway 192.168.0.254
  dns-nameservers 192.168.0.254

# The secondary network interface
auto eth1
#iface eth1 inet dhcp
iface eth1 inet static
  address 128.20.0.1
  netmask 255.255.0.0

スタティックルートを追加する

明示的にルーティングしたい場合スタティックルートを追加する。
下の例では
10.0.0.0/8はeth0
172.16.0.0/16はeth1を通るルーティングを最後に追加してやる。

/etc/network/interfaces
#static route
  post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.0.254
  post-up route add -net 172.16.0.0 netmask 255.255.0.0 gw 128.20.0.254

サーバを再起動

終わったらサーバを再起動(した方が早かった)。

7
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
15