vps - CentOs localhost only work when connected to internet
2014-07
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.
http://i.stack.imgur.com/hGORT.jpg
**Also here is the config for /etc/sysconfig/network-scripts/ifcfg-eth0
http://i.stack.imgur.com/1Jl6d.jpg
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.
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.
I installed CentOS, but it didn't automatically connect to the internet. Is that the normal behavior? I have Ethernet Broadband Router DI-604 and WebStar DPX2203 series Cablemodem with EMTA . What should I do to connect to the internet?
Update:
A cousin told me my ethernet adapter or network board will depend on my motherboard. My computer upgrade document says the motherboard is GBabyte video onboard. I heard GBabyte's network adapters are GBabit or Realtek.
In CentOS, System -> Administration -> Network -> New -> Ethernet, first, only "Other Network Board" was listed, so I selected it and clicked Next, then there wasn't GBabit, but there was Realtek, so I selected Realtek.
I heard with Net Virtua selecting dhcp the things first answered asked me to tell first answerer are automatically configured.
So I tried Realtek with dhcp
, but eth0
wasn't found.
See asterisks:
we didn't upgrade that time, the motherboard is Asus. /sbin/lspci -v
shows that the Ethernet controller is Atheros L2, subsystem is Asustek.
ifconfig output:
lo Link encap:Loopback Local
inet end.: 127.0.0.1 Masc:255.0.0.0
endereço inet6: ::1/128 Escopo:Máquina
UP LOOPBACKRUNNING MTU:16436 Métrica:1
RX packets:2509 errors:0 dropped:0 overruns:0 frame:0
TX packets:2509 errors:0 dropped:0 overruns:0 carrier:0
colisões:0 txqueuelen:0
RX bytes:2650372 (2.5 MiB) TX bytes:2650372 (2.5 MiB)
virbr0 Link encap:Ethernet Endereço de HW 00:00:00:00:00:00
inet end.: 192.168.122.1 Bcast:192.168.122.255 Masc:255.255.255.0
endereço inet6: fe80::200:Firefox:fe00:0/64 Escopo:Link
UP BROADCASTRUNNING MULTICAST MTU:1500 Métrica:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
colisões:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:7306 (7.1 KiB)
xenbr0 Link encap:Ethernet Endereço de HW 00:00:00:00:00:00
UP BROADCASTRUNNING NOARP MTU:1500 Métrica:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
colisões:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
dhclient output:
bash: /sbin/dhclien: Arquivo ou diretório não encontrado
[root@localhost deltrem]# /sbin/dhclient
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
/sbin/dhclient-script: configuration for xenbr0 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: xenbr0: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for veth3 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: veth3: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for vif0.3 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: vif0.3: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for veth2 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: veth2: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for vif0.2 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: vif0.2: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for veth1 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: veth1: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for vif0.1 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: vif0.1: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for veth0 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: veth0: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for vif0.0 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: vif0.0: Arquivo ou diretório não encontrado
/sbin/dhclient-script: configuration for virbr0 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: virbr0: Arquivo ou diretório não encontrado
Listening on LPF/xenbr0/00:00:00:00:00:00
Sending on LPF/xenbr0/00:00:00:00:00:00
Listening on LPF/veth3/00:00:00:00:00:00
Sending on LPF/veth3/00:00:00:00:00:00
Listening on LPF/vif0.3/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Sending on LPF/vif0.3/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Listening on LPF/veth2/00:00:00:00:00:00
Sending on LPF/veth2/00:00:00:00:00:00
Listening on LPF/vif0.2/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Sending on LPF/vif0.2/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Listening on LPF/veth1/00:00:00:00:00:00
Sending on LPF/veth1/00:00:00:00:00:00
Listening on LPF/vif0.1/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Sending on LPF/vif0.1/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Listening on LPF/veth0/00:00:00:00:00:00
Sending on LPF/veth0/00:00:00:00:00:00
Listening on LPF/vif0.0/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Sending on LPF/vif0.0/fe:Firefox:Firefox:Firefox:Firefox:Firefox
Listening on LPF/virbr0/00:00:00:00:00:00
Sending on LPF/virbr0/00:00:00:00:00:00
Sending on Socket/fallback
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on veth3 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on vif0.3 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on veth2 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on veth1 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on vif0.1 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 3
DHCPDISCOVER on vif0.0 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on veth1 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on vif0.1 to 255.255.255.255 port 67 interval 12
DHCPDISCOVER on vif0.0 to 255.255.255.255 port 67 interval 11
DHCPDISCOVER on veth2 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on veth3 to 255.255.255.255 port 67 interval 20
DHCPDISCOVER on vif0.3 to 255.255.255.255 port 67 interval 15
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 11
DHCPDISCOVER on veth1 to 255.255.255.255 port 67 interval 21
DHCPDISCOVER on veth2 to 255.255.255.255 port 67 interval 11
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 16
DHCPDISCOVER on vif0.0 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 17
DHCPDISCOVER on vif0.1 to 255.255.255.255 port 67 interval 21
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 21
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on vif0.3 to 255.255.255.255 port 67 interval 12
DHCPDISCOVER on veth2 to 255.255.255.255 port 67 interval 19
DHCPDISCOVER on veth3 to 255.255.255.255 port 67 interval 15
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on vif0.0 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on veth1 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on vif0.3 to 255.255.255.255 port 67 interval 16
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on vif0.1 to 255.255.255.255 port 67 interval 20
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 11
DHCPDISCOVER on veth3 to 255.255.255.255 port 67 interval 10
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on veth2 to 255.255.255.255 port 67 interval 17
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 17
DHCPDISCOVER on vif0.0 to 255.255.255.255 port 67 interval 16
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on veth1 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on vif0.3 to 255.255.255.255 port 67 interval 10
DHCPDISCOVER on veth0 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on veth3 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on xenbr0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on vif0.1 to 255.255.255.255 port 67 interval 2
DHCPDISCOVER on vif0.2 to 255.255.255.255 port 67 interval 2
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
/sbin/dhclient-script: configuration for veth2 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: veth2: Arquivo ou diretório não encontrado
Update:
Installing Atheros L2. make install says:
make -C /lib/modules/2.6.18-194.el5xen/build SUBDIRS=/home/deltrem/l2/src modules
make[1]: Entrando no diretório `/usr/src/kernels/2.6.18-194.el5-xen-i686'
CC [M] /home/deltrem/l2/src/at_main.o
In file included from /home/deltrem/l2/src/at.h:30,
from /home/deltrem/l2/src/at_main.c:28:
/home/deltrem/l2/src/kcompat.h:1084: error: redefinition of typedef ‘irq_handler_t’
include/Linux/interrupt.h:67: error: previous declaration of ‘irq_handler_t’ was here
make[2]: ** [/home/deltrem/l2/src/at_main.o] Erro 1
make[1]: ** [_module_/home/deltrem/l2/src] Erro 2
make[1]: Saindo do diretório `/usr/src/kernels/2.6.18-194.el5-xen-i686'
make: ** [default] Erro 2
Take a look here too:
What happens when you try to connect?
Are you able to connect to or ping the router?
What is the logical IP configuration (the CentOS box's IP address, netmask, broadcast address, route; similar info for the router)?
What about the physical hookup? What cables are connected to what ports, and what's the hardware configuration? (E.g., crossover or straight cable? And hooking up a 10BaseT half-duplex card to a GigE only port will not work regardless of the cable.)
Check these two commands:
ifconfig eth0 192.168.122.10 netmask 255.255.255.0 broadcast 192.168.122.255 up
route add default gw 192.168.122.1