I have a VirtualBox machine running CentOS 6.5. I've created 2 network adapters for it in VirtualBox's networking settings for the machine. The first is NAT which I want the guest to use to connect to the Internet and the second I set to Host-only which I will use to SSH and access web server from the host computer. This tutorial over at the VirtualBox forums is what I want to achieve but I can't seem to find the /etc/network/interfaces file on CentOS 6.5 so I presume configuration is done differently.

Having setup both NAT and Host-only adapters, I started the VM and did an ip addr show and I have 2 interfaces, eth0 and eth2 (I don't know why eth1 was somehow skipped). So I configure both ifcfg-ethX files in /etc/sysconfig/network-scripts, setting eth0 to be DHCP (for NAT) and eth2 to be static IP (for Host-only). For eth0, ONBOOT=yes while for eth2, ONBOOT=no. With this setup I can ping the Internet i.e. ping -c 3 www.google.com and it gets a response so I know I can connect to the Internet (while eth2 is down).

Next, I ifup eth2. From the host machine, I SSH using the static IP I've set and I can connect without issue. But when I do ping -c www.google.com this time around, it fails and I know I've lost my connection to the Internet even if eth0 is still up. Doing a route -n shows me a tabular output with eth2 taking up the first and last rows while eth0 is in between (sorry I can't post the actual output because I deleted the VM out of frustration...).

I've created a new CentOS VM and would like to proceed with the same set-up. My networking-fu is close to non-existent so I'm a n00b at it. I would like some tips on how to do it properly (i.e. how to set the NAT adapter to use eth0 and set the Host-only adapter to use eth1 and not eth2, how to make eth0 still usable even if eth1/eth2 is up and running).


So I've got the new VM up and running and it seems to work now if I have the first adapter set to host-only and the second adapter set to NAT. It's set up like so:

VirtualBox network settings

  • Network adapter 1: Host-only (vboxnet0 IP address is set to, network mask and DHCP is off)
  • Network adapter 2: NAT (DHCP)

CentOS VM /etc/sysconfig/network-scripts/ifcfg-ethX settings

# ifcfg-eth0

# ifcfg-eth2

Result of ip route  dev  eth2  proto  kernel  scope  link  src  dev  eth0  proto  kernel  scope  link  src  dev  eth0  scope  link  metric  1002  dev  eth2  scope  link  metric  1003
default via dev eth2

Result of ip addr

1:  lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00:00
     inet scope host lo
     inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
2:  eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
     link/ether 08:00:27:ec:6c:b9 brd ff:ff:ff:ff:ff:ff
     inet brd scope global eth0
     inet6 fe80::a00:27ff:feec:6cb9/64 scope link
        valid_lft forever preferred_lft forever
3:  eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
     link/ether 08:00:27:eb:73:ba brd ff:ff:ff:ff:ff:ff
     inet brd scope global eth2
     inet6 fe80::a00:27ff:feeb:73ba/64 scope link
        valid_lft forever preferred_lft forever
  • What's your default gateway?
    – spuder
    Commented Feb 17, 2014 at 2:37
  • @spuder For the host-only interface? If I recall correctly, vboxnet0 (host-only if) was set to so I guess that's what the default gateway was. I can't recall for the NAT interface.
    – baktin
    Commented Feb 17, 2014 at 4:57
  • If the problem still exists why don't you give us the output of ip route on the new VM...? And that of ip addr. Commented Feb 17, 2014 at 6:52
  • @HaukeLaging I've updated the question with the outputs you requested. It seems to work now, having the first adapter to host-only and the second to NAT. But I feel that this is a workaround...and I would like to know the best way to do this if I have set the first adapter to NAT and the second to host-only.
    – baktin
    Commented Feb 17, 2014 at 8:34
  • If you try to replicate this, use "ifconfig -a" to get MAC of eth2 that has to be used in HWADDR line. And you likely want to replace eth2 with eth1. As you likely will have eth1, not eth2 Commented Dec 1, 2014 at 11:03

2 Answers 2


I guess the problem is (or: was) that the gateway definition collides with DHCP. Somehow the interface order seems to influence that.

The basic problem is: How shall routing be done with two network cards? As I understand you the host-only card shall be used for connections to the host only. Thus you should not define any gateway for this interface at all. But maybe this works only if the first interface uses DHCP.

In addition you may consider avoiding DHCP completely. The NAT interface works with a static configuration, too.

  • 3
    Removing the Gateway for the host-only interface worked for me. Thanks.
    – baktin
    Commented Mar 12, 2014 at 16:40

I have a set up of

Adapter 1 = NAT = eth0
Adapter 2 = Bridged Adapter = eth1

Under Oracle Linux (RHEL/ CentOS) I run the Network Connections application
and set eth0 to a fixed IP address
and set eth1 to Automatic DHCP

When you do a ifconfig I see that both eth0 and eth1 have inet addresses set and communication from the HOST to GUEST work and from GUEST to Internet all work.

There have been times when I don't start VBOX for a while and I find the communication won't work. No idea.

Today I started the GUEST and no network connection (both ways) I restarted and it works.

Maybe to do with VBXO upgrades, I just don't know.

BTW: To communicate with Oracle DB set Port Forwarding on the NAT (eth0) from to Guest IP Port 1521. Do this from VBOX.

I also have my firewall disabled.

You must log in to answer this question.

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