Get IP of VM running on an Ubuntu server configured on bridged networking - ip

I want to set up an exported VM on an Ubuntu Server using VirtualBox on headless mode.
I have the VM up and running and bridged with the ethernet interface of the host (em1), so the dhcp of the host should now assign an IP to the VM if I'm not mistaken.
Is there a way to check if this is working and if yes to get the VM's IP?
Since this is on headless mode so without GUI, the only way to login to the VM is through ssh and for that I need the IP..

welthenwel,
you can do this with VBoxManage.
from a shell, just type:
VBoxManage guestproperty enumerate VM_NAME --pattern */IP
and you will get as response something like in the below image.
now, ignore the fact that I run this cmd from a Windows host, because its behaves exactly the same from inside a linux host

I'm not very familiar with VirtualBox. Bridged with VMWare Workstation meant the IP is given by your default DHCP server, which means you could look up the assigned IP address there (e.g. your router - if you have access to it).
Another option would be a ping sweep of your network segment as I believe Ubuntu doesn't drop ICMP requests.

Related

How do I access my Ubuntu Server installed on Virtual box from anywhere in the World

I am trying to make an IOT using nodemcu and a LED. I want to access the Ubuntu Server(which is installed in the virtual box) through some other network(outside my LAN). How can I do it? I read many articles online, but I am not able to figure it out. I tried port forwarding but it did not work.
I am not sure what I am doing wrong. Is there's a problem in the port forwarding, or I am following a wrong method.
I have installed Ubuntu Server 16.04 LTS on my laptop via VirtualBox. I have installed LAMP. Also, network set to bridged adapter, plus I have dynamic IP
As I logged in, I ran ifconfig. It gave me the inet address as 192.168.16.101
Did you set the VM network interface to be NAT or Bridged?
If it is NAT, then you are essentially double NATTed which means you will need to port forward from your router to the VM host and then you will need to port forward from the host to the VM as the IP assigned will be local to the host machine.
However, the easiest is to set the VM network interface to Bridged.
This will mean the VM will be able access your network directly as it should be on the same subnet as your laptop and appear as another device, which your router will be able to port forward to.

How to do port forwarding on VMWare Player 14.1.2 (Ubuntu 18.04 guest, Windows 10 host)?

I have a VMWare Player (14.1.2 build-8497320) running a Ubuntu 18.04 guest on a Windows 10 host. The Ubuntu guest has a LAMP stack that runs a few web applications. I am using NAT to connect the Ubuntu guest to the Windows host's network.
I can access these applications by using the local IP address of the guest (e.g., http://192.168.80.128/mediawiki) from my Windows host. But I want to access it like so from my Windows host: http://localhost/mediawiki. I think this should be possible if I can forward the port 80 of my Ubuntu guest to that of the Windows host.
How do I make this happen please? I don't have access to VMWare Workstation and its Virtual Network Editor.
Edit: I should probably add the motivation for wanting to do this. Basically, I want to avoid figuring out the IP address of the virtual machine everytime I access the web applications.
The (further) reason is that the local IP address of the Ubuntu guest might (I suspect) change, and that will affect quite a few things, such as the base URLs configured in the webapps' configuration files (e.g., the $wgServer variable in LocalSettings.php of MediaWiki).
VMWare Player supports port forwarding over NAT natively:
In the file C:\ProgramData\VMware\vmnetnat.conf put under section [incomingtcp] a line like:
80 = 192.168.80.128:80
Then restart the VMWare NAT Service :
net stop "VMWare NAT Service"
net start "VMWare NAT Service"
Source/credits: https://hitchhikingtheweb.wordpress.com/2014/09/02/portforwarding-with-vmware-player-and-nat/
Also: VMWare documentation of this
You can do it using SSH Tunneling for example.
From windows you open a tunnel from the windows port 80 to the ubuntu port 80.
You can do it using Putty on Windows and having the ssh deamon running on ubuntu, which I guess you should already have.
There are many tutorials on how to do this.
I'll add just one link, but you can always google it and find one that suites you.
Portforwarding with SSH (Putty)
For the possible changes in the guest’s ip:
If you can’t fix the ip in settings then perhaps you can edit the windows hosts file and add a host name for the current Ubuntu ip. Then build the urls using the host name. If the ip changes you change it in the hosts file.

port forwarding to a virtual machine using Virtualbox

I want to forward a port to a VM. However i dont want the VM to be behind my host PC, i want it to be connected directly to the router so that packets coming on that port go directly to the VM without passing through my host PC.
In other words, i want the VM to look like any other machine on the network.
EDIT: i used bridged adapter, but i couldnt make it connect to the network.
Thank you
The VM will use the Ethernet port in all cases and the OS in it.
Typically if you have Windows and a VM with a bridged port, you will see the traffic flow when you take a capture on the Windows machine. IP won't be the one from the Windows machine but the traffic, like said, will flow through the same physical interface.
Secondly, you need to use a bridged adapter. For the details you can find help here: Bridged networking not working in Virtualbox under Windows 10

Windows: How to redirect udp traffic to another port

I currently have a virtual machine running on Windows. The VM is running Linux and has a virtual box network between the windows machine and the linux machine. The VM is running a application that I want to be able to connect to from the outside world.
To make this possible I tried port forwarding from the windows internet interface, to the windows virtualbox interface. Finally I created another port forward from the windows virtualbox interface to the Virtual machine interface.
netsh interface portproxy add v4tov4 listenport=5000 listenaddress=10.11.65.103 connectport=7890 connectaddress=192.168.56.1
netsh interface portproxy add v4tov4 listenport=7890 listenaddress=192.168.56.1 connectport=5000 connectaddress=192.168.56.101
So if I connect to the 10.11.65.103:5000 on the Windows Machine it will be the same thing as connecting to 192.168.56.101:5000 of the VM.
[Win Internet Intf] [Win VM Intf] [VM intf]
10.11.65.103:5000<----->192.168.56.1:7890 <------> 192.168.56.101:5000
Unfortunately, this is not working for me... Can someone tell me why? Am I using port forwarding correctly?
If you use a bridged network adapter your Linux machine should pick up an IP off the host network (if you have DHCP enabled on the network, or set a static IP on the linux box). Then you should then not need the port forwarding.
If you cant use that approach and are using a NAT adapter (which it looks like you are), then you will need to enable port forwarding within VB. The details are in section 6.3 of the VB Help with this in place you should only then need the first port forward, VB will be doing the second.
Dont forget to make sure the relevant firwalls on the Windows and Linux machines are open.

SSH from Virtualbox Guest to DynDNS address

I have Windows 10 as host with a Manjaro installation as Guest on Virtualbox.
I have set a Debian server on another house with ssh installed. I have setup a dyndns on Debian's network so I can access it remotely.
For example..
From address 12.34.56.78 I ssh to foo.dyndns.org:1234. This port redirects me to 192.168.1.5:22 always as this is my Debian machine and the connection is established. I am able to do this from Windows 10 as well as my android and any other device in 12.34.56.78 or by 3G.
But..
When I try to do this
$ ssh foo.dyndns.org:1234
from the Manjaro Guest in Virtualbox I get the following error:
ssh: Could not resolve hostname foo.dyndns.org:1234: Name or service not known
So I did ifconfig and I saw my inet address was 10.0.2.15. I changed virtualbox's network adapter from NAT to Bridged so I can get a lan ip and I got the host's ip, 192.168.2.4. So I gave it another try and still didn't work.
Also, if i try to connect from vm to server while I'm in the same network
$ ssh user#192.168.2.5:22
it works. In this case virtualbox's network adapter was NAT.
This command works if I try from my android (connectbot).
I can connect the same way from PuTTY from Windows.
So my questions are:
Can it be done?
If so, how? (and why?)
Can a VBox Guest get lan ip that's not the same as the host's?
Is there any more information I should provide?
I have searched for a couple of days in here and on google and all I found where solutions on how someone can ssh INTO a vm. No one (from what I saw) asked the opposite.
Checking manual page for ssh reveals the format of command-line options:
ssh [...] [-p port] [...] [user#]hostnamessh
This simply describes, that you need to change
ssh foo.dyndns.org:1234
to
ssh -p 1234 foo.dyndns.org
if the domain resolves correctly to the ip address.

Resources