1

I'm planning to setup a LDAP configuration between two ubuntu virtual machines on my windows machine.

So I installed two ubuntu 16.04 virtual machines on my windows machine using VirtualBox. Now I want to get a real IP so I can connect to the virtual machine from anywhere.

When I use NAT it sets up the IP as 10.0.4.14 and when I choose Bridged adapter or Host-only Adapter then I don't get any internet connection.

Could anyone please advise how I can get a "real" IP when using Virtualbox with Ubuntu 16.04 so I can use this IP for LDAP?

1

Vagrant

I've moved to using Vagrant + Vagrantfiles exclusively to do this with Virtualbox. This is a file that I use that sets 2 VMs on my laptop.

Characteristics of this Vagrantfile:

  • VMs are Ubuntu 16.04 (xenial64)
  • VMs request public IP addresses from your LAN's DHCP server
  • VMs will utilize your Virtualbox Host's NIC's interface (see file)
  • I left the name of the centos/7 image in the file if you want to switch

Resources for Vagrant

Sample Vagrantfile

$ 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

Usage

start both VMs
 $ vagrant up
start one VM at time
 $ vagrant up box-101
 $ vagrant up box-102
ssh to 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:~$
confirm IP address
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:~$

NOTE: It's expected behavior that you'll have 2 interfaces. Vagrant/Virtualbox always sets up a interface similar to enp0s3 which is associated to the 10.0.2.15/24 interface. This is the NIC that Vagrant is using when SSH'ing into the VM among other things.

Testing network connectivity

With the above Vagrantfile and the 2 VMs started up (box-101 & box-102) we can verify 3 scenarios of network connectivity. NOTE: Before we start take note of the VM's IP addresses.

Background

For box-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
For box-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

Scenarios

Scenario #1: box-102 → box-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
Scenario #2: Virtualbox Host → 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
Scenario #3: Remote Server → 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.