Ubuntuの初期設定では、NATのポートフォワーディングを利用してホストOSのWindows7からゲストOSのUbuntuにSSH接続した。また、WindowsとUbuntuのファイル共有はVirtualBoxの共有フォルダーを利用した。
VirtualBoxのファイル共有だけでは今後何かと不便だろうと思い、Sambaをインストールすることに。
$ sudo apt-get install samba
Sambaのインストール自体はこれで完了。まずはダメもとでWindowsからUbuntu(\\192.168.56.1)につないでみると・・なぜか、Windows側PCの共有フォルダーが見えている。ポートフォワーディングを設定していないので、単純にどこにもつながらないエラーが出るのかと思っていたが、そうではないらしい。良くわからない。。
どちらにせよダメなので、VirtualBox Virtual Networkingを参考にネットワーク設定を再考する。
[要件]
1) ゲストOSのUbuntuからもホストOSのWindowsを通じてインターネットに接続したい
2) ゲストOSのUbuntuはホストOSのWindows以外のPCからは見えてほしくない
3) ホストOSのWindowsからゲストOSのUbuntuには無制限にアクセス可能
1)と2)の要件はUbuntuの初期設定のようにNATで問題なし。
3)の要件を満たすため、アダプター2に「ホストオンリーアダプター」を割り当てる。VirtualBox側の設定はこれで完了。
次はUbuntu側の設定。上で割り当てたネットワークは自動起動しないので、手動でIPを割り当てる。
$ sudo dhclient eth1 [sudo] password for mokimokisan: Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service smbd reload Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the reload(8) utility, e.g. reload smbd
ifconfig で割り当てられたIPアドレスを確認する。
毎回dhclientコマンドを打つのはさすがに面倒なので、Ubuntuのネットワーク設定に追加する。
$ 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 # VirtualBox Host-only Network auto eth1 iface eth1 inet dhcp
上記はDHCPでIPアドレスを取得する設定だが、DHCPで割り当てるIPアドレスの範囲はVirtualBox側の [ファイル] > [環境設定] > [ネットワーク] で設定可能。