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:
Also here is the config for /etc/sysconfig/network-scripts/ifcfg-eth0
:
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.
Answer
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.
In Windows, in the image you showed here http://i.imgur.com/xiLaUst.jpg?1 - 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.
In the CentOS Virtual Machine settings (with it powered off), go to the Network settings and set Adapter 1 to "Host Only Adapter".
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:
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.
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.
No comments:
Post a Comment