Can not connect to database : Mongoose/MongoDB, virtual box - virtualbox

Context
A MongoDB database runs on an Ubuntu Virtual Machine (VM).
An express server app serves a directory on my host machine (Windows 10).
This directory is shared with the VM.
Issue
I am trying to launch my express app locally without success.
On VM side, connecting to the database via the mongo shell works normally.
On the host side, i just used npm start to launch the app.
Do I need to do something else so my machine host/the app can communicate with the db in the VM ?
I have tried :
https://serverfault.com/questions/225155/virtualbox-how-to-set-up-networking-so-both-host-and-guest-can-access-internet
and
https://2buntu.com/articles/1513/accessing-your-virtualbox-guest-from-your-host-os/
...but it didn't work.
I get this error :
error with npm start
Thank you for you help

It seems that you are here mixing two things :
Connection to a remote database host on a Virtual Machine
Running an application on a Virtual Machine that communicates to a local database on the Virtual Machine too
From what you explains, it seems that your setup looks like this :
+-------------------------+ +------------------------+
| | | |
| Windows 10 host machine | -- Shared folder -| Virtual machine |
| | application | MongoDB running |
| | | |
+-------------------------+ +------------------------+
When you run npm run main on your host machine, the application needs to connect to the remote database using Virtual Machine network adresse. Sharing a folder with the Virtual Machine has no report with reaching database.
When you run npm run main on your local machine, you can connect using localhost
or Virtual machinbe network adresse.
Your issue is not related to npm or mongodb but on your Virtual Machine connection setup.
If the application runs on Windows 10, the easiest way to setup your Virtual Machine network and connect to database is to set Bridge adpater on the VirtualBox's VM settings.
Then, setting dhcp on the main network interface of your Ubuntu machine will provides you an address.
Edit /etc/networking/interfaces then restart network using sudo /etc/init.d/networking restart
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
Use provided enp0s3 inet address to connect to your VM's database. To get the proivided adress, use ip addr on a shell.

#user7364588
i don't have the etc/networking/interfaces but etc/network/interfaces with only this message inside :
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
Should I still apply your advice or use netplan ?
Inside netplan, I have a file 50-cloud-init.yaml containing
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
dhcp6: false
optional: true
nameservers:
addresses: [4.2.2.1, 4.2.2.2, 208.67.220.220]
ip addr :
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:e3:9f:67 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
valid_lft 85581sec preferred_lft 85581sec
inet6 fe80::a00:27ff:fee3:9f67/64 scope link
valid_lft forever preferred_lft forever

Related

How to mount from Windows 10 host to Linux guest via NFS?

I have ZorinOS 15 Lite as a Linux guest on my Windows 10 host machine.
The aim is to mount from my Windows 10 host to this Linux NFS server.
The NFS client setup on Windows 10 is done.
The NFS server setup on Zorin OS is done.
But still there are problems with mounting.
On Zorin guest nfs-kernel-server installed and edited /etc/exports/ file:
/data 192.168.0.0/24(rw,sync,no_subtree_check,insecure)
/data/ - the folder which I want to be shared between Win10 host and Zorin guest.
192.168.0.0/24 - share directory for IPs between 192.168.0.0 and192.168.255.255
Doing ipconfig I know this:
Windows host IP address - 192.168.1.66
Linux guest IP address - 192.168.56.1
When I'm trying to mount from Win10 host, I get this error:
C:\Users\Alibek Kaparov>mount -o nolock -o anon \\192.168.56.1\data I:
Network Error - 53
Type 'NET HELPMSG 53' for more information.
What am I doing wrong? I'm not experienced with NFS and VBox.
As it was pointed out in comments, thanks Mark Setchell, I changed IP address and mask to * pattern glob, copied IP address of virtual machine from it via ifconfig (not from Win10 host ipconfig) and could mount to it from host.

Not able to connect remote floodlight controller to mininet

I am new to mininet and I was trying to build a mininet topology which uses a remote SDN controller.
I tried using floodlight as the remote controller. I installed it and ran it and it is running on "localhost:6653". But it is also running on 192.168.122.1:6653 (And I have no idea why).
192.168.122.1 is my virbr0 interface's address. In my mininet VM which is in virtualbox i have two network adapters.
NAT
Host only adapter
And for host only adapter i have the following configuration.
Adapter settings:
Ipv4 address: 192.168.56.1 and net mask: 255.255.255.0
DHCP server settings: Sever ip= 192.168.56.100; net mask= 255.255.255.0; Lower bound Ip: 192.168.56.101; Upper bound Ip: 192.168.56.254
To avoid confusion i have added the screenshots as well.
I tried the following command to build my topology:
sudo mn --controller=remote,ip=192.168.122.1,port=6653
I get the following response from mininet
Unable to contact remote controller 192.168.122.1:6653
I have tried changing ip to 192.168.56.1 but that also didn't work.
Any kind of help will be appreciated.
Thanks.
As per your setup, I guess FLC is running on Host OS and mininet is running in Oracle VM.
Your Host-Only network is useful if you are trying to reach something deployed in VM from your Host Os.
It will not work other way around. Here you want to access FLC running on Host inside your VM.
I would suggest using Floodlight VM for Virtual Box. It has mininet and FLC inbuild.
Once imported. Start VM.
Credentials: floodlight/floodlight
Inside VM start FLC
Do ifconfig ithe n terminal and get IP
change to that IP in this
sudo mn --controller=remote,ip=192.168.122.1,port=6653
and execute, all will work fine.
You can access FLC in Host using above IP

Access rails server from host machine

My rails server (WEBrick 1.3.1) is set on the virtual machine (ubuntu 12.04) and use NAT. The default IP address is 10.0.2.15 with port 3000. How can I access from my host machine (win8) ?
I have tried to use port forwarding but it doesn't work.
Settings -> Network -> Port forwarding
Protocol | Host IP | Host Port | Guest IP | Guest Port
TCP 127.0.0.1 3308 10.0.2.15 3000
By setting your port forwarding as you did, you are telling your host PC that when you visit 127.0.0.1 at port 3308 in your browser, you want that resolved to be your guest virtual machine's I.P. address at port 3000.
With your virtual machine's Rails server running, open a browser on your host PC and navigate to 127.0.0.1:3308.
If your browser doesn't render your guest server's web pages, I'd suspect you have a port conflict (that port 3308 may already be in use). In that case, search for ways to view what ports are currently in use on your PC. Find a port which is not in use and use that in your port forwarding's host port settings.
If anyone faces the same problem, after port forwarding, I resolved this problem running the server binding the ip address of the virtual machine like this:
rails server -b 10.0.2.15

Getting acces to host VM in a VirtualBox with Puppet

I have an application running in a VirtualBox VM that for testing purposes needs to connect to the host machine. The VM is started with Vagrant and managed by Puppet.
What is the best way to set-up this connection? For example, om my host machine the app runs on port 9200. So from my VM I'd like to go to myhostmachine:9200.
Currently I'm thinking of hacking in a small command that adds hostvm as a entry to /etc/hosts using a simple command like this to figure out my host ip (which is the same as the default route).
/sbin/ip -4 route list 0/0 | grep -m 1 default | awk '/default/ { print $3 }'
And just let Puppet run that every time using the exec functionality. However, I get the feeling there has to be a better way.
The guest OS is Ubuntu 12.04 and the Host is OS-X.
Thanks!
As far as I know, at the moment Vagrant always sets up a natted interface to connect to virtualbox, so I think that the ip of your host machine will always be the 10.0.2.2 address you mentioned. I reckon a puppet host declaration might be easier to manage than running that command each time.
host { 'myhostmachine':
ip => '10.0.2.2',
}
The puppet resource reference for hosts has all the other params you can set too.
I was then able to access the host using myhostmachine:9200

Running APE Server in a Virtual Machine

I have been trying to set-up an Ajax Push Engine (APE) Server in a virtual machine, and have run into a bit of a snag. The problem is that the APE server cannot be accessed outside of the virtual machine.
Setup:
Guest OS: Ubuntu 10.10 (I believe) with the ape package installed
IP Address: 192.168.56.1 using a host-only network adapter
APE Server running on port 6969
If I try wget 127.0.0.1:6969 in the virtual machine, I get a response.
If I try wget 192.168.56.1:6969 from the host OS, I get a Connection Refused message.
If I ping 192.168.56.1, I also get a response.
Any help would be greatly appreciated!
I ended up redoing everything from scratch, and it worked, so I must have got it right somehow. For the benefit of others...
To get APE Server running in a virtual machine (in particular, using VirtualBox), you need to do the following:
Setting up the environment
Download and install VirtualBox
Open VirtualBox, and go to File > Preferences, then Network
Confirm that there exists a host-only network vboxnet0 (if not, create it). Take note of its IPv4 address (192.168.56.1, in my case)
Create a new Ubuntu Virtual Machine
Start the Virtual Machine
Getting the Libraries
Add the PPA for libmysqlclient15off, a pre-requisite for APE Server:
username# gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
username# gpg -a --export CD2EFD2A | apt-key add -
sudo sh -c 'echo "deb http://repo.percona.com/apt maverick main" >> /etc/apt/sources.list.d/percona.list'
Install libmysqlclient15off
sudo apt-get update; sudo apt-get install libmysqlclient15off
Get and install the latest version of APE server
Edit /etc/network/interfaces, and add the following to the end:
auto eth0
iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
Close the virtual machine and go into its settings. Change the network settings for the first interface to Host-only Adapter
Setting Up APE
Restart the Virtual Machine, and ensure that the APE daemon is running
username# ps -ef | grep "aped"
If you need to, make changes to /etc/ape/ape.conf
Final Steps
Add the following to your hosts file, or some variation:
192.168.56.101 local.site.com
192.168.56.101 0.local.site.com
192.168.56.101 1.local.site.com
192.168.56.101 2.local.site.com
192.168.56.101 3.local.site.com
192.168.56.101 4.local.site.com
192.168.56.101 5.local.site.com
192.168.56.101 6.local.site.com
192.168.56.101 7.local.site.com
192.168.56.101 8.local.site.com
192.168.56.101 9.local.site.com
Access your new APE server via local.site.com:6969
Check APE config file. Are you binding to the right IP ? By default it's 127.0.0.1