Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the below dev. environment.

  • Hardware:- Windows 7, 32bit, HP Laptop.
  • Software:- CentOs 6.5 running on VirtualBox 4.3.10.

In a nutshell The problem is that I can't access the internet and localhost at the same time in my VirtualBox. Example:

HOST ONLY ADAPTER

If I have my VirtualBox adapter set to Host Only. ifconfig eth0 shows me the below configuration:

#ifconfig eth0
Link encap:Ethernet  HWaddr 08:00:27:81:0F:EA
inet addr:192.168.57.162  Bcast:192.168.56.255  Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe81:fea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:342 errors:0 dropped:0 overruns:0 frame:0
TX packets:362 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:37176 (36.3 KiB)  TX bytes:66580 (65.0 KiB)

And cat /etc/resolv.conf shows the below:

#cat /etc/resolv.conf
[root@localhost dd.com]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 212.98.41.104
nameserver 194.290.66.07 

Now, with those above settings. If I check http://192.168.57.162 I can see all is working. Nginx, Php ... all is fine. The problem here is that, if I wanted to install a package with yum install ... or yum update or even ping google.co.uk gives me error. Example:

[root@localhost myProject]# ping google.co.uk
ping: unknown host google.co.uk

So, I tried to switch to NAT Adapter.

NAT ADAPTER

Now, with NAT. I if I do ifconfig eth0 I see the below config:

 #ifconfig
Link encap:Ethernet HWaddr 08:00:27:81:0F:EA
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr:fe80::a00:27ff:fe81:fea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX pacakets:434 errors:0 dropped:0 overruns:0 frame:0 
TX Packets:445 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:1000
RX bytes:47366 (46.2 KiB TX bytes:76674 (74.8Kib)

Now, you would assume if I typed 10.0.2.15, 127.0.0.1, localhost or even http://10.0.2.15 I would be able to see my server running or my web pages. But, No! Nothing shows up. I get an error message, as if I was trying to access a page that did not exist. I've even adjusted my hosts file. But nothing. I can't even access CentOs using putty. But, weird enough I can install packages, ping server and all..

So, I tried to use two adapters, but sadly whichever is set Adpater 1 only seems to work, as if the Adapter 2 is being ignored. So, overall with these settings, I can either only install packages but not see my server, or vise versa.

I am looking for alternative that will allow me to see my localhost and install pacakges at the same time using only one adapter.

EDIT

According to metacom's answer I added a port into the NAT adapter as below.

enter image description here

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Either add a port formard to the NAT setup, or run bridged networking. Port forwarding below port 1024 will not work according to http://www.virtualbox.org/manual/ch06.html#network_nat

In bridged mode, it essentially creates a virtual ethernet interface in software, appearing as another machine of the LAN.

share|improve this answer
    
How do I add port forward? I have no idea, as I am kinda new in this. However, I have tried bridged mode several times. It gives me a Failed error when initializing the eth0 interface –  Bimlik Apr 6 at 17:53
    
"To configure Port Forwarding you can use the graphical Port Forwarding editor which can be found in the Network Settings dialog for Network Adaptors configured to use NAT. Here you can map host ports to guest ports to allow network traffic to be routed to a specific port in the guest." The host port must be >1024, i.e. host port 8080 guest port 80 –  metacom Apr 6 at 18:01
    
Thanks. I feel like today is the day I will fix this error. But, unfortunately, I am a bit lost. I have edited my answer to include a snapshot of the settings. I have done as you suggested and rebooted network, disabled iptabes, and I can see my ifconfig eth0 show 10.0.2.15 as my hosts IP. But I can't access it. I can't browse the page using any ip address. Can you checkout the image and tell me if I am doing something wrong –  Bimlik Apr 6 at 18:22
    
Edit that to add host as 127.0.0.1 and guest ip as 10.0.2.15 –  metacom Apr 6 at 18:50
    
On and Off. I have tried to have a fully working CentOs for 7-8 months now. And today, I've finally finished. You have no idea how much you've saved me. You are a godsend. I finally tried 127.0.0.1:8080 and was able to access my host file on NAT adapter. I will work on to remove the port number 8080. Thanks a Million. –  Bimlik Apr 6 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.