Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
24
Help us understand the problem. What is going on with this article?
@urunru@github

Virtualboxで仮想サーバー構築(ubuntu server 12.04 + SSH)

More than 5 years have passed since last update.

以下の様な構成で仮想サーバー(ゲストOS)を構築する。

ubuntu server インストール

Virtualboxにubuntu server をインストール。

ユーザ名はme
ホスト名はubuntu
に設定

インストール後はゲストOSをシャットダウンして停止する。

仮想アダプタ追加

環境設定(⌘+,)からネットワークアダプタを追加する。

アダプタは追加ボタンをクリックするだけで自動生成される。

 
DHCPサーバーは以下のように設定する。

ゲストOSのネットワーク設定

ゲストOSにログインしてネットワーク設定を書き換える。

初期状態のネットワークを確認

me@ubuntu:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:29:02:f3  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe29:2f3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5011 (5.0 KB)  TX bytes:5438 (5.4 KB)

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)

ネットワーク設定にeth1を追加
eth1のIPは192.168.56.101に固定 

me@ubuntu:~$ 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 eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
  address 192.168.56.101
  netmask 255.255.255.0

sshをインストール & 起動

me@ubuntu:~$ sudo apt-get install ssh
me@ubuntu:~$ sudo /etc/init.d/ssh start

ネットワーク再起動

me@ubuntu:~$ sudo /etc/init.d/networking restart
 * Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
 * Reconfiguring network interfaces...                                          ssh stop/waiting
ssh start/running, process 1685
ssh stop/waiting
ssh start/running, process 1727

ネットワークにeth1が追加されたことを確認

me@ubuntu:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:29:02:f3  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe29:2f3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5011 (5.0 KB)  TX bytes:5438 (5.4 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:5c:4f:0a  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe5c:4f0a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:388 errors:0 dropped:0 overruns:0 frame:0
          TX packets:235 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:36205 (36.2 KB)  TX bytes:29593 (29.5 KB)

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)

ゲストOSデフォルトゲートウェイが10.0.2.2となっていることを確認(10.0.2.2はホストOSの仮想ルータ)

me@ubuntu:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.0.2.2        0.0.0.0         UG    100    0        0 eth0
10.0.2.0        *               255.255.255.0   U     0      0        0 eth0
192.168.56.0    *               255.255.255.0   U     0      0        0 eth1

me@ubuntu:~$ ping google.com
PING google.com (173.194.38.110) 56(84) bytes of data.
64 bytes from nrt19s18-in-f14.1e100.net (173.194.38.110): icmp_req=1 ttl=63 time=13.4 ms
64 bytes from nrt19s18-in-f14.1e100.net (173.194.38.110): icmp_req=2 ttl=63 time=16.2 ms

ホストOSにvirtualboxの仮想ルーターvboxnet0が追加されていることを確認

me@host_mac:~$ ifcofing
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:00 
    inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255

ホストOSからSSHログイン

Macのターミナルからログイン

me@host_mac:~$ me@ssh 192.168.56.101
me@ubuntu's password: 
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic x86_64)

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

  System information as of Sun May  5 15:55:01 JST 2013

  System load:  0.0               Processes:           68
  Usage of /:   14.5% of 7.12GB   Users logged in:     1
  Memory usage: 13%               IP address for eth0: 10.0.2.15
  Swap usage:   0%                IP address for eth1: 192.168.56.101

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

Last login: Sun May  5 15:40:17 2013 from 192.168.56.1
me@ubuntu:~$ 

おまけ

ホストOSでゲストOSのhostsを追加しておくとsshログインが簡単

me@host_mac$ sudo vi /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
192.168.56.101  ubuntu 

me@host_mac$ ssh ubuntu

ゲストOSの言語を変更する。

me@ubuntu:~$ sudo vi /etc/default/locale 

LANG="en_US.UTF-8"

参考

virtualbox割り当てアダプタの種類
http://garbagetown.hatenablog.com/entry20100313/1270039659)

24
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
24
Help us understand the problem. What is going on with this article?