I can't connect to apache through host-only network

Discussions related to using VirtualBox on Windows hosts.
Post Reply
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

I can't connect to apache through host-only network

Post by emil78 »

My host machine is Windows 7 x32 and i am trying to connect to apache server on my guest machine which is Ubuntu server. I have setup two adapters, host-only and NAT:
2015-02-07_131208.jpg
2015-02-07_131208.jpg (54.1 KiB) Viewed 10216 times
2015-02-07_131236.jpg
2015-02-07_131236.jpg (60.84 KiB) Viewed 10216 times
This is the output from ifconfig:

Code: Select all

root@ubuntu:/# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:41:f6:9b
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe41:f69b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:165 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17138 (17.1 KB)  TX bytes:14090 (14.0 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:79:94:2e
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
But when i enter in the browser on my host machine 10.0.2.15 it shows the connection timed out.
I have Comodo Firewall installed on my host but i don't see in the log anything that suggests it's blocking the connections between host and guest machine.

I am also able to ping my host machine from my guest machine but i can't ping the guest machine from my host, it shows "Destination host unreachable"

Any idea why i can't connect to apache server on my guest machine?
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

I found what the was problem. I had to add a second network interface on Ubuntu server so i edited /etc/network/interfaces and added:

Code: Select all

# The secondary network interface
auto eth1
iface eth1 inet dhcp
Then restarted so the changes to take effect.

But can someone tell me how to make dhcp server give the same IP address on Ubuntu machine because it changes the ip address when restarting the machine?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: I can't connect to apache through host-only network

Post by Perryg »

Add the entry as static instead of dhcp in the file.
Be sure to use the right scheme and subnet.
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

Perryg wrote:Add the entry as static instead of dhcp in the file.
Be sure to use the right scheme and subnet.
Can you give me example how it should look?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: I can't connect to apache through host-only network

Post by Perryg »

https://www.google.com/search?q=asssing ... er&spell=1

You can see the address scheme with the following command.

Code: Select all

VBoxManage list hostonlyifs
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

I am not sure if i did everything correctly but so far everything is working fine. This are the lines i added for static IP address:

Code: Select all

# The secondary network interface
auto eth1
iface eth1 inet static
address 192.168.56.105
netmask 255.255.255.0
network 192.168.56.1
broadcast 192.168.56.255
gateway 10.0.2.2
I am not sure if the network line is correct.

This is the ifconfig output:

Code: Select all

root@ubuntu:/# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:41:f6:9b
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe41:f69b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:288 errors:0 dropped:0 overruns:0 frame:0
          TX packets:183 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:27168 (27.1 KB)  TX bytes:22937 (22.9 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:79:94:2e
          inet addr:192.168.56.105  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe79:942e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:115 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:14617 (14.6 KB)  TX bytes:20436 (20.4 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

And this is from VBoxManage list hostonlyifs command:

Code: Select all

c:\Program Files\Oracle\VirtualBox>VBoxManage list hostonlyifs
Name:            VirtualBox Host-Only Ethernet Adapter
GUID:            2e9cecf1-0d1b-437e-b42f-8c5beaa2c455
DHCP:            Disabled
IPAddress:       192.168.56.1
NetworkMask:     255.255.255.0
IPV6Address:     fe80:0000:0000:0000:f921:96ef:cb4b:084e
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 08:00:27:00:24:b8
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: I can't connect to apache through host-only network

Post by Perryg »

The only thing I see that might cause you problems is there should be no gateway listed. Host-only is not intended to be able to reach the Internet, thus the name "host-only".
AnrDaemon
Posts: 134
Joined: 7. Feb 2010, 23:41
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu Linux, Windows

Re: I can't connect to apache through host-only network

Post by AnrDaemon »

network - wrong and useless,
broadcast - right, but also useless,
gateway - wrong, it should be in the same network, as the host, and largely useless, since it's running on windows host.
Don't hold the system for an idiot, it can calculate network and broadcast addresses for you from host address and netmask. And don't specify gateway, unless you know you want one.
Lastly, I suggest disabling DHCP on host-only interface altogether. Mess things more than solves.
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

AnrDaemon wrote:network - wrong and useless
What should be the right value for network?
Lastly, I suggest disabling DHCP on host-only interface altogether. Mess things more than solves.
I am confused about DHCP stuff. I read in some tutorials that if i assign static IP address i have to remove the dhcp client on Ubuntu virtual machine. Is that recommended?

Also, if i don't disable the dhcp server on my host-only network do i have to choose static IP address that is out of the DHCP addresses pool? For example, the dhcp server for my current host only network assigns addresses in this range: 192.168.56.100 to 192.168.56.254. Do i have to choose static IP address that is out of this range, like 192.168.56.300?
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

I removed the gateway line but now every time when i start Ubuntu VM i get notification from Windows for IP conflict. In the system log i see this Tcpip system error:

Code: Select all

The system detected an address conflict for IP address 192.168.56.1 with the system
having network hardware address 08-00-27-46-C1-A6. Network operations on this system may
be disrupted as a result.
It doesn't affect the performance of the virtual machine but i am wondering why i am getting this massage for IP conflict.

Edit: Actually i was wrong. It does affect the performance of the machine because i am not able again to connect to apache. And if i tracerout the stattic IP address it get only to my external gateway and shows Destination host unreachable.

Code: Select all

C:\Windows\System32>tracert 192.168.56.105

Tracing route to 192.168.56.105 over a maximum of 30 hops

  1     1 ms     1 ms     1 ms  192.168.31.1
  2  xxx.xxx.xxx.x  reports: Destination host unreachable.

Trace complete.
xxx.xxx.xxx.x is my gateway.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: I can't connect to apache through host-only network

Post by Perryg »

You have corrupted your host-only network somehow. There is no route to check since it was intended to emulate a local-loopback in the since that there was not Internet or LAN available.

The scheme is by default (host = 192.168.56.1, 255.255.255.0) (guest = 192.168.56.*, 255.255.255.0)
emil78
Posts: 112
Joined: 15. Jun 2012, 11:28

Re: I can't connect to apache through host-only network

Post by emil78 »

Yes, the dhcp server was the problem. I remember i changed the server address from 192.168.56.100 to 192.168.56.1. I reversed back to the default value and now i can ping again the guest machine and i don't receive the message for IP conflict.

But i have question about the dhcp default values for the host only network. These are the values:
2015-02-09_164120.jpg
2015-02-09_164120.jpg (29.09 KiB) Viewed 10129 times
2015-02-09_164141.jpg
2015-02-09_164141.jpg (26.52 KiB) Viewed 10129 times
And the default gateway on my wireless router is 192.168.31.1

Code: Select all

C:\Windows\System32>ipconfig

Windows IP Configuration


Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::983d:f052:5d0e:24c9%12
   IPv4 Address. . . . . . . . . . . : 192.168.31.101
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.31.1

Do i have to change the dhcp address of virtualbox dhcp server from 192.168.56.1 to 192.168.31.1?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: I can't connect to apache through host-only network

Post by Perryg »

As I have said a few times already. You do not use a gateway when you have host-only as it will stop the network if you do. It was not intended to be used if you want the Internet in the guest. The supported way to get the Internet in the guest if you use host-only is to add a second adapter set to NAT.

The whole purpose for host-only was to allow communication with the host-guest if there were not network at all.
AnrDaemon
Posts: 134
Joined: 7. Feb 2010, 23:41
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu Linux, Windows

Re: I can't connect to apache through host-only network

Post by AnrDaemon »

emil78 wrote:Yes, the dhcp server was the problem. I remember i changed the server address from 192.168.56.100 to 192.168.56.1. I reversed back to the default value and now i can ping again the guest machine and i don't receive the message for IP conflict.

But i have question about the dhcp default values for the host only network. These are the values:

And the default gateway on my wireless router is 192.168.31.1
You're confusing apples and oranges.
Gateway and routing in general has nothing to do with address assignment.
You only need to specify gateway, when you want to leave your network. With host-only interface, this is not the case, and not supposed to be so.
And what to the DHCP server, VirtualBox emulate ADDITIONAL machine on address 192.168.56.100, that serves as DHCP server for host-only network.
Something like

Code: Select all

    Host              DHCP server 
192.168.56.1 ---+--- 192.168.56.100
                |  (emulated by host)
         Host-only network
                |
192.168.56.101 -+-- 192.168.56.102
    VM001                VM002
(autoconfigured)   (autoconfigured)
This also explains, why I prefer to keep DHCP away from this - I don't want to remember, what is the DHCP address range, I only use host-only network for administration, and each VM have a note attached to it containing its static management address.
Post Reply