
Windowsシステムの2つのUbuntu仮想マシン間でLDAP構成を設定する予定です。
そのため、VirtualBoxを使用してWindowsコンピュータに2つのUbuntu 16.04仮想マシンをインストールしました。今、どこからでもVMに接続できるように、実際のIPを取得したいと思います。
使用するときは、NAT
IPが10.0.4.14に設定されており、選択したりBridged adapter
インターネットHost-only Adapter
に接続されていません。
Ubuntu 16.04でVirtualboxを使用している場合、LDAPにこのIPを使用できるように「実際の」IPを取得する方法を教えることができる人はいますか?
答え1
徒歩旅行者
Vagrantfiles
私はVirtualboxを介してのみこれを行うVagrant +を使用するように切り替えました。このファイルを使用してラップトップに2つの仮想マシンを設定します。
この作品の特徴Vagrantfile
:
- VMはUbuntu 16.04(xenial64)です。
- 仮想マシンはLANのDHCPサーバーからパブリックIPアドレスを要求します。
- 仮想マシンはVirtualboxホストのNICインターフェイスを利用します(ドキュメントを参照)。
centos/7
切り替えたい場合は、ファイルに画像名を残しました。
放浪資源
Vagrant ファイルの例
$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
##############
### References
# - https://www.vagrantup.com/docs/vagrantfile/machine_settings.html
# - https://www.vagrantup.com/docs/vagrantfile/tips.html
# - https://www.vagrantup.com/docs/networking/forwarded_ports.html
##############
#unless Vagrant.has_plugin?("HostManager")
# raise 'HostManager plugin not installed!'
#end
require 'digest/sha1'
uniqID = "_" + (Digest::SHA1.hexdigest Dir.pwd()).slice(0..8)
image = "ubuntu/xenial64"
#image = "centos/7"
if Vagrant::Util::Platform.windows? then
interfaces = [
"Intel(R) 82583V Gigabit Network Connection",
"Intel(R) 82579LM Gigabit Network Connection",
]
elsif Vagrant::Util::Platform.darwin? then
interfaces = [
"en0: Wi-Fi (AirPort)",
"en1: Wi-Fi (AirPort)",
]
else
interfaces = [
"eth0",
"eth1",
"wlan0",
]
end
Vagrant.configure("2") do |config|
vboxName1 = "box-101"
hostname1 = "box101"
config.vm.define "#{vboxName1}" do |front|
front.vm.box = "#{image}"
#front.vm.network :private_network, ip: "192.168.56.101"
front.vm.network :public_network, use_dhcp_assigned_default_route: true, bridge: interfaces
front.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 512]
v.customize ["modifyvm", :id, "--name", "#{hostname1}#{uniqID}"]
end
end
vboxName2 = "box-102"
hostname2 = "box102"
config.vm.define "#{vboxName2}" do |front|
front.vm.box = "#{image}"
#front.vm.network :private_network, ip: "192.168.56.102"
front.vm.network :public_network, use_dhcp_assigned_default_route: true, bridge: interfaces
front.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 512]
v.customize ["modifyvm", :id, "--name", "#{hostname2}#{uniqID}"]
end
end
end
使用法
2 台の仮想マシンを起動 $ vagrant up
一度に1つの仮想マシンを起動
$ vagrant up box-101
$ vagrant up box-102
SSHからVM box-101へ
$ vagrant ssh box-101
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-130-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
/usr/bin/xauth: file /home/vagrant/.Xauthority does not exist
vagrant@ubuntu-xenial:~$
IPアドレスの確認
vagrant@ubuntu-xenial:~$ ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 02:97:71:8a:f0:d8 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::97:71ff:fe8a:f0d8/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:e6:43:ac brd ff:ff:ff:ff:ff:ff
inet 172.16.12.208/24 brd 172.16.12.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fee6:43ac/64 scope link
valid_lft forever preferred_lft forever
vagrant@ubuntu-xenial:~$
メモ:予想される動作である2つのインタフェースがあります。 Vagrant / Virtualboxは、常にenp0s3
このインターフェイスに関連付けられているインターフェイスと同様のインターフェイスを設定します10.0.2.15/24
。これは、VagrantがSSHを介して仮想マシンに接続するなどのタスクを実行するために使用するNICです。
ネットワーク接続テスト
上記Vagrantfile
のように、2つの仮想マシン(box-101とbox-102)が起動したら、3つのネットワーク接続シナリオを確認できます。メモ:始める前に、仮想マシンのIPアドレスをメモしてください。
背景
ボックス101(172.16.12.208)の場合:$ ip a l enp0s8
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:e6:43:ac brd ff:ff:ff:ff:ff:ff
inet 172.16.12.208/24 brd 172.16.12.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fee6:43ac/64 scope link
valid_lft forever preferred_lft forever
ボックス102(172.16.12.116)の場合:
$ ip a l enp0s8
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:df:3b:06 brd ff:ff:ff:ff:ff:ff
inet 172.16.12.116/24 brd 172.16.12.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fedf:3b06/64 scope link
valid_lft forever preferred_lft forever
アプリケーションシナリオ
シナリオ#1:ボックス-102→ボックス-101## On box-101 run:
$ nc -l 12345
## On box-102 run:
$ curl -v telnet://172.16.12.208:12345
* Rebuilt URL to: telnet://172.16.12.208:12345/
* Trying 172.16.12.208...
* Connected to 172.16.12.208 (172.16.12.208) port 12345 (#0)
^C
シナリオ #2: Virtualbox ホスト → box-101
## On box-101 run:
$ nc -l 12345
# On Virtualbox Host
$ curl -v telnet://172.16.12.208:12345
* Rebuilt URL to: telnet://172.16.12.208:12345/
* Trying 172.16.12.208...
* Connected to 172.16.12.208 (172.16.12.208) port 12345 (#0)
^C
シナリオ#3:リモートサーバー→box-101
## On box-101 run:
$ nc -l 12345
## In Remote Server
$ curl -v telnet://172.16.12.208:12345
* About to connect() to 172.16.12.208 port 12345 (#0)
* Trying 172.16.12.208...
* Connected to 172.16.12.208 (172.16.12.208) port 12345 (#0)
^C