1

I have been trying to solve this problem (on and off) for three months, but still can't get it to work or even understand it why it happens.

THE SCENARIO:

I have a VirtualBox installed in my {HP 32bit, Windows 7} Laptop

In this VB, I've installed CentOs 6.5 minimal, Nginx, PHP-FPM with no problems.

In short, everything works well.

The PROBLEM

The problem is I can only access locahost if I am connected to the Internet.

While connected to the Internet, If I go to http://192.168.1.100/ everything works, I can see my files like index.html just fine, but as soon as I am go offline, I get nothing, as if I was trying to access Google without being connected to the Internet.

This is a screen shot of my Vbox settings:

enter image description here

Also here is the config for /etc/sysconfig/network-scripts/ifcfg-eth0:

enter image description here

I have done the following various times.

Tried with iptables disabled/enabled
Tried with Host Only, NAT Bridged Adapters
Tried with Static IP, and DHCP..
refreshed networks several times

I am sure the answer is somewhere, because I still don't have the perfect setup configs, but mixing many things as I go, so still can't get it to work.

1 Answer 1

0

In the VirtualBox Network settings, you have the CentOS machine 'bridged' onto your WiFi network, with a static IP address.

Your laptop won't have a fixed IP address on its WiFi connection; when you are not connected to WiFi, Windows has no network connection up and running and doesn't know how to get to the CentOS server. When you connect to WiFi your router gives Windows an address on the same network and then it can get to the CentOS server.

They are running on the same computer, but they are separate and can't automatically talk between each other. The fix is to change the networking setup somehow, and how you change it depends on what you want to do.

The easiest way might be to go to Windows Control Panel, Network Connections, then find your wired network adapter (assuming your laptop has one and you don't use it), and go to the properties and set a TCP/IP network address of 192.168.1.101, subnet mask of 255.255.255.0, no gateway.

This will pretend your computer is always on the same network as the CentOS machine and can always get to it, yet should still allow the WiFi connection to take over and be your internet connection when you use it, and still allow CentOS to get out to the internet when WiFi is connected, and still allow other computers to connect in to CentOS, and still allow your computer to work on other WiFi networks, but it will stop your wired connection from working in as many places.

There are other approaches you could take, but they will all affect one or more of these use cases, and require more work to put right afterwards.

[Edit: I am ignoring where you say "can't access localhost". That might be important. You should describe exactly what your test is - which computer are you using, what software are you loading, where are you typing localhost?]

Edit: New suggested configuration

This involves having a separate, two-computer network just for Windows to talk to CentOS.

  1. In Windows, in the image you showed here https://i.stack.imgur.com/a3CIZ.jpg - go to the properties of the VirtualBox Host-Only Network adapter, into Internet Protocol TCP/IP v4 properties, and set an IP address of 192.168.250.1 and a subnet mask of 255.255.255.0, leave the other settings empty, and OK out of it.

  2. In the CentOS Virtual Machine settings (with it powered off), go to the Network settings and set Adapter 1 to "Host Only Adapter".

  3. Power on the CentOS machine. Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 and set IP address 192.168.250.2 and subnet mask of 255.255.255.0. Have no gateway, no DNS servers. Restart the networking or restart the CentOS machine.

You should now have this new, separate network of 192.168.250.1 -- 192.168.250.2 to talk between them. Run your NGinX so it listens on the 192.168.250.2 address, and visit http://192.168.250.2/ in Windows to get to it.

This should work with or without WiFi. The only problem is that CentOS cannot get to the internet to do updates or installs. If this is a problem:

  1. Power off the CentOS machine and go to the VirtualBox settings for it, in Network. Choose the Adapter 2 tab, enable it, set it to Bridged Adapter.

  2. Power on the CentOS machine, and configure an eth1 interface. Configure this to get an IP address dynamically / by DHCP. I use system-config-network-tui but I had to install it. You might be able to copy /etc/sysconfig/network-scripts/ifcfg-eth0 to /etc/sysconfig/network-scripts/ifcfg-eth1 Restart the networking make sure it comes up.

It should have a network connection joined to your WiFi like the original one that only works when WiFi is connected, but CentOS can use it to get to the internet.

10
  • Sorry for the delay, I asked and went for a while. Anyway Thank You! I have got a feeling you finally can help me. But I have one problem: I can't find the Wired Network Adapter in my Win7 I went to this Control Panel\Network and Internet\Network Connections and only found these networks I even tried with some by modifiying the IP, but it does not seem to work Mar 8, 2014 at 23:06
  • Hmm; Picture extremely useful, thanks. You don't have a wired connection. I'm not sure if this will work, but go into the properties of "Wireless Network Connection", then click "Internet Protocol Version 4 (TCP/IP)" and click the properties button, then go to the tab "alternative configuration" and set user configured, just put IP address 192.168.1.101 and subnet 255.255.255.0, OK out of everything. Hopefully your laptop will use this address when not connected to WiFi, and will still pick up an address and work properly when connected to WiFi. Mar 9, 2014 at 0:04
  • I think we may have slightly different OS, as mine does not have "Alternative Configuration" tab, I only have have one general tab, and I filled the numbers (though your ip suggestion ends 101, but what worked for me earlier ends with 100) At the end still nothing, I can't get it to work. I am upvoting you for your effort, I will just keep trying I guess. Mar 9, 2014 at 0:36
  • We do, my only wireless device is Windows 8. On the screen you show, behind the 'advanced' button there's an option for a "secondary IP" and I would have suggested putting it there. But if you tried filling in the numbers on the screen you show and it didn't work, that's more of a problem. You have 192.168.1.100 showing in your CentOS eth0 config, so you can't use that address on your Windows 7 computer networking as well, so I suggested the next one up. Windows does not have an address on 192.168.1.??? unless it's on WiFi, I hoped you could give one that it could always fall back to. Mar 9, 2014 at 0:56
  • Nope nothing works. This problem has cost me many hours already. Anyway, as a last resort, is there any way I could do to make it work, with another method? I don't know what vagrant is, but it might be another way of running VM on my machine, or how about if I use NAT, HOST Only bridges? I'm trying to change my WAMP enviroment, so any help will do as long as I can run a web server and php using centOs Mar 9, 2014 at 1:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .