Как пинговать виртуальную машину virtualbox

от admin

Ping Virtual Box(Guest) from Windows(Host)

In this article we will set up our VirtualBox network interface that is easily accessible by the host machine. We will ping the VirtualBox from the host machine and also make sure VirtualBox is able to access the Internet.

Lets get started.

  • Oracle VM VirtualBox [Ubuntu_18.04.3] [Guest]
  • Windows 10 [Host]

Provided you have VirtualBox set up already done, I will be going through the steps here to set up the Network interfaces in Virtual box.

In the Oracle VM VirtualBox Manager we will add the Network Adapter i.e Host-Only Adapter. Check image below.

Above setting is done to so that our VM will share the host only network i.e. our Windows 10 host.

Login to your VM and now we will assign a static IP to our VM

  • Once logged in VM, run below command

This will list down all the network interfaces in the VM. Output would be similar like below:-

Observe the IP address of eth0 interface. Now, try check the IP address of your host [Windows 10] by running command ipconfig. You will observe that the IPv4 DNS range is different from what is shown in above image.

Right now, If you ping the VM machine from Host machine it will not work because of the above reason. So, now we will assign a static IP to our VM so that both host and VM share the same DNS IP range and able to communicate with each other even if there is no Internet in town.

  • Run below commands

There will be a file called 01-network-manager-all.yaml. We need to update this file with below content.

We are basically applying the IP 192.168.56.108 to our VM.

  • Run below command now

Bingo we are done.Really.

Yes, now is the time to ping the VM from Host machine.

Go to your host machine terminal and run the command below

Most probably, you will see the output as below

Thats it. We have made it.

Now you can even do ssh or ftp from your host machine to VM machine without the need of Internet.

If you want to access the Internet on your VM too….then we have a solution for that too here.

If this post was helpful, please click the clap �� button below a few times to show your support! ⬇⬇

How to ping ubuntu guest on VirtualBox [closed]

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 7 years ago .

I have an VM (VirtualBox) with Ubuntu. Host machine is Windows 7. How can I ping my Ubuntu from host and vice versa? Trying to set «Bridged» connection type in VM settings but there is no effect, I only lose my internet connection in Ubuntu.

3 Answers 3

In most cases simply switching the virtual machine network adapter to bridged mode is enough to make the guest machine accessible from outside.

Sometimes it’s possible for the guest machine to not automatically receive an IP which matches the host’s IP range after switching to bridged mode (even after rebooting the guest machine). This is often caused by a malfunctioning or badly configured DHCP on the host network.

For example, if the host IP is 192.168.1.1 the guest machine needs to have an IP in the format 192.168.1.* where only the last group of numbers is allowed to be different from the host IP.

You can use a terminal (shell) and type ifconfig ( ipconfig for Windows guests) to check what IP is assigned to the guest machine and change it if required.

If the host and guest IPs do not match simply setting a static IP for the guest machine explicitly should resolve the issue.

Using NAT (the default) this is not possible. Bridged Networking should allow it. If bridged does not work for you (this may be the case when your network adminstration does not allow multiple IP addresses on one physical interface), you could try ‘Host-only networking’ instead.

For configuration of Host-only here is a quote from the vbox manual(which is pretty good). http://www.virtualbox.org/manual/ch06.html:

For host-only networking, like with internal networking, you may find the DHCP server useful that is built into VirtualBox. This can be enabled to then manage the IP addresses in the host-only network since otherwise you would need to configure all IP addresses statically.

In the VirtualBox graphical user interface, you can configure all these items in the global settings via «File» -> «Settings» -> «Network», which lists all host-only networks which are presently in use. Click on the network name and then on the «Edit» button to the right, and you can modify the adapter and DHCP settings.

How do I ping virtual machines that are connected to my host pc?

I have installed VirtualBox on my pc. I have «Virtual Host-Only Network» virtual network card and two connected machines to it via Host-Only network mode.

I want to check their addresses from host, an then I want to ping each machine from host.

EDIT:

(note: I work on Windows, so instead of grep I used find)

I have used these commands (first line is command, next is result):

Then arp -a | find «_MAC_ADDRESS» (In this command, I had to separate MAC digits with «-» as arp displays it like AA-BB-CC-DD-EE-FF)

I guess I am close, but this last command does not give any result like there was no _MAC_ADDRESS; but other addresses are displayed correctly.

EDIT 2:

Finally I got this 🙂 thanks for help, malevolent, you’re awesome.

Fair enough for me 🙂

But malevolent made this in a more elegant way, with regular expressions (see his answer). It could be useful when you really need to stripe down result to get IP address and use it in some tricks, hacks and scripts 🙂

HUUGE THANKS BRO 🙂

1 Answer 1

Turn on the VM

First of all, you should turn on the guest VMs, make sure you have them turned on with

If no machine is listed, you have no VMs turned, on, list them and turn them on with

Where name_of_VM is the name of your Virtual Machine.

Without VirtualBox Guest additions installed. (no internet connection needed)

You have the command VBoxManage. To show all the VM informations you should run:

Once you have the information from the VM’s, write down the MAC address, for example:

Then, you can use arp command like this, changing the _MAC_ADDRESS with your vm’s mac address in ‘:’ notation

You should get your VM’s IP address.

With VirtualBox Guest Additions installed

Another method, easier than the last one, should be through vbox guest additions. If you have guest additions installed, you can simply use:

And search for the IP address

Installation of Guest Additions (Internet connection needed)

Can’t ping VirtualBox? Troubleshooting Guide and Solution

If you have just installed a guest OS like a Linux distro, Windows 10 or macOS on VirtualBox and you are hosting some network service on that virtual machine, then you need to configure some settings on the virtual box so that you can ping to that virtual machine and communicate with it over the network from any machine on your local network.

This article shows you the configuration changes you need to make on your virtual box in order to make it possible. I have written this article keeping complete beginners in mind, so instead of just answering the question “what to do to make it work?” I have also answered the questions “why it doesn’t work?” and “what is the reason behind the default settings?

If you are an advanced user, or if you are just interested in the solution then feel free to just skip to section 5 “The short version of the answer” section using the table of contents below.

VirtualBox Basics

This section gets you introduced to the various terminology used in the rest of the article.

What is VirtualBox? VirtualBox is a hypervisor application that lets us host operating systems in a virtualized environment. In simpler words, its basically an app that runs on one operating system (The Host Operating System) and lets us boot other operating systems (Guest OS) as an app within the Host OS.

The Host OS can be Windows or Linux or Mac OS, and the guest can also be one of these. So if you have a Macbook and you wish to run some windows applications on it, which are not available for macOS, then you can run it by installing Windows inside VirtualBox.

Configuring VirtualBox

What are the configuration options available in a VirtualBox to share resources between Host and Guest OSes?

VirtualBox lets us allocate resources for the Guest OS. These resources include the following

  • RAM
  • CPU cores
  • Hard Disk space
  • Network
  • USB devices, etc.

You can get to these options by clicking on the settings icon as shown in the image below.

Oracle VM Virtua180x Manager File Machine Help Running Nevv Settings Discard IJbuntu S prev,ew Operating System: IJbuntu (64-bit) Syste m Base Memor y: Soot Order: Acceler a bon : Display Video Memory: 2408 MS Floppy, Optcal, Hard Disk VT-x/AMD-V, Nested Paging, KW Paravirtualizabon Graphics Controller: Remote Desktop Server: Recor ding : Sto rage Controller: IDE IDE Secondary Master: Controller: SATA SATA Port O: VMSVGA Disabled Disabled [Opbcal Drive] ubuntu-18.04.3-desktop-amd64.iso (I. 94 GE) IJbuntu.vdi Clormal, 10.00 GE) Host Driver: Windows Dir ectSound controller: ICH Acg7 Network Adapter 1: Intel MT Desktop(NAT)

Let’s assume your computer running the Host OS is a Windows 10 laptop that has a quadcore processor, 16GB of RAM and 1TB of hard disk space. If you wish to run Linux on it, you can tell the virtual box app to allocate it one of the CPU cores, 4GB of RAM and 25GB of hard disk space so that you can run both these operating systems smoothly and simultaneously.

If you wish to run more than one Guest OS, then that is also possible, you just need to have enough resources and allocate them to each of the Guest OS appropriately so that there are enough resources left for the Host OS, Windows 10 in our example, to run smoothly.

Other than CPU, RAM, and hard disk space, you can also allocate networking resources and USB devices to the guest OS.

Mouse and Keyboard will automatically be transferred to the guest OS as soon as you give focus to the virtual machine by clicking on it.

Assume you have another USB device that you need to use from the guest OS. Then using the configuration options, you can specify it in the settings so that the special USB device also transferred to the guest OS once you boot it up.

Читать:
Как перенести формулу в ворде

Now that we have seen the basic configuration options of VirtualBox, lets next look at the network configuration options, which is the main focus of this article.

Network Configuration Options in VirtualBox

You can get to the network configuration options by clicking on the Network tab as shown in the picture below.

Ubuntu - Settings General System Display Sto rage Audio Netwo rk Serial Ports Shared Folders User Interface Network Adapter I Adapter 2 Adapter 3 Enable NetA

These are the default settings that VirtualBox provides you with once you install any Guest OS on it. As you can see the “Attached to” field is set as NAT.

Meanings of these Network Options

The table below shows the various available options for the Attached to field shown in the screenshot above and their meanings

Internet using public/outside IP addresses Internet Router Translates between private and public IP using NAT device 1 device 2 device 3 device 4 Local Area Network using private/inside IP

How NAT works?

To explain how it works briefly, the router keeps track of which computer requested what resource with the help of something called address translation tables so that when a network packet is received from the internet it can send the received packets to the correct computer on your local area network.

I hope you understood the need for NAT and how it conceptually works. The exact mechanisms of NAT and its various types are beyond the scope of this article, so let’s stop here. I recommend you to do more research on it if you are interested.

The problem

Keeping the default settings, I have booted up my ubuntu virtual machine and I got its IP using the ifconfig command as shown in the screenshot below.

In Linux, the inet addr is the IP address.

When I try to ping to this IP from my host OS (windows10), I get the following results.

As we can see from the screenshot above, my host windows machine cannot see the virtual machine on my network.

Let’s try pinging the other way. I got the IP of my windows machine using the ipconfig command as shown in the screenshot below.

Ethernet adapter Ethernet : Connection-specific DNS Link-local IPv6 Address IPu Address. Subnet mask Default Gateway Suffix . few: . 192.168.8.184 . 255.255.255.8 . 192.168.8.1

Then I tried pinging this IP from the guest OS and you can see the screenshot below.

bala@ba1a-Virtua1Box 192. 168.0. 104: -e. 639 -e. 772 —3 -e. 689 -e. 751 -e. 797 -e. 855 -e. 777 —8 -e. 769 -e. 776 PING 192. ping 192.168.0.104 168.0.104 (192.168.0.104) 56(84) bytes 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 16 bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes bytes from f rom from from f rom f rom from from f rom f rom from from f rom f rom from from 192. 168.0. 104 192.168.0.104 192.168.0. 104 192. 168.0. 104 192. 168.0. 104 192.168.0.104 192.168.0. 104 192. 168.0. 104 192. 168.0. 104 192.168.0.104 192.168.0. 104 192. 168.0. 104 192. 168.0. 104 192.168.0.104 192.168.0.104 tcmp : tcmp_ : tcmp : tcmp : tcmp : tcmp_ : tcmp : tcmp : tcmp : tcmp_ : tcmp : tcmp : tcmp : tcmp_ : tcmp : tcmp_ seq seq seq- seq seq -6 seq- seq seq— seq = 10 seq —11 seq —12 seq —13 seq = 14 seq —15 seq —16 seq ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 ttl— -127 of data. time time- time time time time- time time time time- -e. 758 time -o . 846 time; 0.779 time -e. 837 time -e. 829 time -o. 780 time -e. 756 ms ms ms ms ms ms ms ms ms ms ms ms ms ms ms ms 192. 168.0. 104 ping statistics - packets transmitted, 16 received, 0% packet loss, time 15368ms rtt mtn/avg/max/mdev = 0.639/0.775/0.855/0.061 ms

As you can see in the screenshot below, pinging from the guest OS to the Host OS is a success.

This is because VirtualBox uses the NAT protocol to translate between your Host OS’s IP and the Guest OS’s IP.

Reason only one side pinging works

Part of this NAT protocol is that NAT will only allow network traffic originated from the inner side of the NAT.

For example, when you open up your browser and go to google.com, you are sending a request to the google server from the inner side of the NAT (LAN side) and the router sends this request forward to the Google server which is in the outer side of the NAT (the internet) and once the server sends the requested page back, your router sends it back to your computer.

The diagram below shows the hierarchy of NATs in a typical network with devices being the physical computers and vm’s being the virtual machines running inside physical computers.

Internet device 1 Router device 2 level 1 NAT between LAN and the internet device 3 device 4 vml VirtualBox does another level of NAT virtualbox vm2

Reason NAT is chosen as default

In a typical organization, you can see several computers running multiple vm’s on each computer. They also usually have a strict networking policy to allow only authenticated devices to have access to the LAN for security reasons. If developers need to talk to network administrators every time they wish to make a virtual machine, then this process will get tedious for everyone.

Thus by using NAT, you can have as many virtual machines running as you desire and you are not using up any of the IPs in your LAN. In other words, VirtualBox attempts to create a sub-network under your local IP using NAT so that

  • you don’t need to talk to your network admin every time you need to make a VM
  • these machines stay invisible to the other devices on the LAN.

Need#2 for NAT

This brings us to the Need#2 of NATs, which is that nobody from outside your LAN can initiate a session with your computer and nobody from the internet can hack your computer.

Now let’s extend the analogy of the internet & LAN to your host & guest OSes. In the same way, you can initiate a session from your LAN to the internet but not the other way around, your guest OS can talk to machines on the outside of the NAT, in our case the Host OS, but not the other way around. I hope you got the point.

The Solution

But what if you need to set up a network app like a web server or a file server inside the virtual box so that your colleagues can access it from their machines? Or maybe you need to log into your virtual machine remotely over SSH?

Then you need the virtual machine to act as a separate computer on the LAN as shown in the image below.

Internet device 1 device 2 Router vml vm2 device 3

To achieve that, you need to change the option from NAT to Bridged Adapter as shown in the screenshot below.

Ubuntu - Settings General System Display Sto rage Audio Netwo rk Serial Ports Shared Folders User Interface Network Adapter I Adapter 2 Adapter 3 Enable NetA

After changing the settings again, I have booted up my ubuntu virtual machine and I got its IP using the ifconfig command as shown in the screenshot below.

enpes3: , BROADCAST , mtu 1500 tnet 192.168.0.113 net-mask 255.255.255.e broadcast 192.168.0.255 tnet6 fe80: : 535f: prefixlen 64 scopetd ether txqueuelen 1000 (Ethernet) RX packets 639 bytes 801876 (801.8 KB) RX errors O dropped O overruns e frame O TX packets 290 bytes 38511 (38.5 KB) TX errors e dropped e overruns e carrier O collisions O

Now to test if it works, go to the command line again and try pinging the IP to see if it works. When I try to ping to this IP from my host OS (windows10), I get the following results.

So now I can ping to my guest OS from my host OS.

The short version of the answer

To summarize the solution you need to follow these steps to be able to ping your virtual machine from any other device on your network

Step#1: Choose your virtual machine and click on settings

Step#2: Go to network settings

Step#3: Choose Bridged adapter

Step#4: Reboot the virtual machine

Step#5: Get the IP of the virtual machine and ping it to see if it works!

This is the easiest solution to just let the virtual machine be on the same level as other machines on your LAN. If you are doing this with your home network, it should work just fine. If you are doing it in your office be sure to check in with your network admin to make sure he opens up an IP for you if needed!

Did all the steps correctly and it still doesn’t work? then read on for some more settings you can change that might help make it work as you need it to.

Other settings that might help

1. Check your IP settings

Make sure they are in the same subnet and have the same DNS and gateway. If DHCP is enabled, then the virtual box should automatically get the correct IP settings(dns, gateway and ip addresses)

What is DHCP? DHCP stands for Dynamic Host Configuration Protocol. It’s a networking protocol that assigns IP settings to your device.

If it’s disabled on your guest OS, try enabling it and see if that solves the issues.

Since the process to change the DHCP settings on each OS varies a lot, I leave it to you to google and figure out how to change it.

2. Check your firewall

Configure firewall settings on the host OS to give all permissions to the virtual box app.

What is a firewall? It is a program that scans all the incoming network packers and only allows the ones as instructed by its settings.

I leave it to you to google and figure out how to do this for your specific Host OS.

3. Check your MAC address

MAC stands for Media Access Control, it is a unique address that is assigned to every hardware device capable of connecting to the internet.

Make sure that the MAC address as shown in the screenshot below is not a duplicate on your LAN. In other words, make sure that none of the other computers in your LAN has this MAC address.

ubuntu server General System Display Storage Audio Network Serial Ports - Settings Network Adapter 1 Adapter 2 Z] Enable Net.work Adapter Adapter 3 Adapter 4 Attached to: Name: Advanced Adapter Type: Promiscuous Mode: MAC Address: Bridged Adapter Intel(R) Ethernet Connection 1219-LM Intel PRO/IOOO MT Desktop (82540EM) Deny 080027ACFA49 Cable Connected Port Fomarding Shared Folders User Interface Cancel

A couple more workarounds

Wordaround#1: Try enabling promiscuous mode

This mode basically skips the internal processing of received packets and sends all the incoming packets straight to the CPU.

This can be done by changing the settings of VirtualBox as below.

ubuntu server General System Display Storage Audio Network Serial Ports Settings Network Adapter 1 Adapter 2 Z] Enable Net.work Adapter x Adapter 3 Adapter 4 Attached to: Name: Advanced Adapter Type: Promiscuous Mode: MAC Address: Bridged Adapter Intel(R) Ethernet Connection 1219-LM Intel PRO/1000 MT Desk-top (82540EM) Allow All 080027ACFA49 Cable Connected Port Fomarding Shared Folders User Interface Cancel

But be careful as the promiscuous mode is set to deny for a good reason so that no one can hack into our machines. Make sure you don’t have sensitive data in your virtual box guest OS if you wish to turn it on.

You should be good to go as long as

  • the router that connects your LAN to the internet has a good firewall and
  • Your LAN does not have any hackers!
Wordaround#2: Try sharing a folder

The host/guest OS combination that this workaround is found to work in is shown below

Guest OS: Windows XP or 7

Add at least 1 shared folder from guest to host

But this is not the best solution since its not practical as it can get tedious to share a folder to all the present and future devices that might need to connect to your virtual machine’s network-based service.

If you wish to connect to just one or 2 machines then its worth giving it a try.

There are other ways to get it to work. For example, if your goal is to just connect to your VirtualBox using SSH and not let all other machines on your LAN see your virtual machine, then you can always open port 22 on the NAT settings and connect to it from the particular machine of interest and keep it hidden to all other machines. You can learn more about how to accomplish that at this link.

Bonus Tip

One more tip before I conclude this article! Try enabling hardware virtualization on your Host PC’s BIOS if it supports it, as this will increase the performance of your VirtualBox. You can google how to do this, by searching “how to enable virtualization in <your motherboard name>”

Alright, let’s stop here.

I hope you guys learned something through this post and hope it was useful to you guys.

You can email us or contact us through this link if you have any questions or suggestions.

If you liked the post, feel free to share this post with your friends and colleagues!

Похожие статьи