Notes on Network Configuration in VirtualBox After a CentOS 7 Minimal Install
As the title says. You can also refer to these blog posts for the configuration:
http://www.unixarena.com/2015/04/rhel-7-network-management-nmcli-or-nmtui.html
http://www.arthurtoday.com/2013/07/ubuntu-guest-enables-nat-and-hostonly-adapter.html
First, a quick note on VirtualBox: if all you want is for the VM to reach the external network without connecting to the physical host, the default NAT already does the job;
if you only want the VM to reach the physical host but not the outside network, you can use the “Host-only” adapter.
And in general, if you want both the VM and the physical machine to be on the same subnet, you should choose the “Bridged Adapter.” Then, if there’s a DHCP server (typically your wireless access point or router), they can be on the same subnet: you can talk to your VM, and it can also reach the external network, just like your physical host.
So if you want the VM and the physical machine to be able to reach each other, the “Bridged Adapter” is one option; another is to give the VM two network adapters—one NAT and one “Host-only” adapter. Once both are set up, the VM can reach both inside and outside, though strictly speaking it isn’t on the same LAN as the physical host.
The example below uses the second approach—NAT + Host-only adapter. I’ll first show how to set up a VM in VirtualBox, then how to configure things in CentOS 7. So let’s get started!
1. VirtualBox configuration
First install VirtualBox (obviously). Click “New,” choose Linux as the type and RedHat 64bit as the version. Here I named it CentOS7, as shown. Once set, click Next.
Set the memory size. Here we set it to 1024MB, as shown. Once set, click Next.
Now create a virtual hard disk. Here we choose “Create a virtual hard disk now,” as shown, and click Create.
Set the hard disk file type. Here I’ll create a VDI—after all, it’s natively supported by VirtualBox, so it may cause fewer problems. That said, feel free to choose another disk format, as shown.
Choose dynamic allocation. Dynamic allocation means the space given at the start doesn’t immediately consume a fixed amount of disk space like a fixed-size disk would; instead it grows as your disk usage increases (note: it won’t shrink, unless you take other actions—which are strongly discouraged and risky), up to the maximum of the fixed size. Here we choose dynamic allocation.
Set the disk size to 8G. Since Linux doesn’t take up much space, there’s no need to make it large; here we just go with the suggested 8G.
Once done, we return to the original screen, where we’ll see the VM has been created—but before booting we still need a few more settings.
- Insert the CentOS image you want to install
Select the VM, click the “Settings” button to enter the settings screen, and click “Storage.” Under storage, we’ll see two controllers, one IDE and one SATA. The one under IDE is the optical drive; click it, then click the small disc icon on the right, select your ISO file, and insert it.
- Configure the second network adapter
Still in the settings screen, choose “Network.” You’ll see four adapters. Adapter 1 is already set to NAT, so we don’t need to configure it again, as shown.
If you want to add the adapter but keep it disconnected for now, you can click Advanced, where there’s a “Cable Connected” checkbox—unchecking it is equivalent to unplugging the network cable, as shown.
Switch to Adapter 2, check “Enable Network Adapter,” and from the dropdown choose the “Host-only” adapter. It will auto-fill the name—no need to change it. Then click Advanced and, under Promiscuous Mode, choose “Allow All.” Once all settings are done, click OK to save.
(Note: I later tested that choosing “Deny” also let them ping each other fine. After looking into it, I confirmed that “Allow All” is needed when you use a bridged adapter, because at that point you need to receive all kinds of MAC packets for it to work correctly.)
2. After starting the VM, install CentOS
I won’t say much here—there’s plenty of info online, and installation now has a GUI, so it’s not too hard.
3. After installing CentOS, use nmtui (NetManager-TextUI) to configure
Once booted, log in with the root credentials you created during installation (or your own account). Having root privileges makes things easier here, so I’ll demo with root.
First confirm that you can’t ping the external network 8.8.8.8, then type “nmtui” to enter the settings page.
Choose “Edit a connection.”
You’ll see two interfaces inside. Select each and enter “<Edit…>”.
Since we’re configuring everything via DHCP, there’s no need to set a static IP. Confirm both IPv4 and IPv6 are set to Automatic, then check “Automatically connect,” and it will connect to the network automatically after a reboot.
Type “service network restart” to restart the network service so the correct settings take effect.
Release the mouse from the VM (the default should be the right Ctrl key), open CMD, and type “ipconfig /all.” You’ll see a network interface like the one below, from which you can get the physical host’s IP—we’ll use it for testing shortly.
Type “ping 8.8.8.8” and “ping 192.168.56.1” to test connectivity to the outside and to the physical host. By default Linux keeps pinging, so press Ctrl+C to cancel.
Type “ip a,” and you’ll see a 192.168.56.101 on the same subnet as 192.168.56.1. We’ll use this IP later to test from the physical host.
Release the mouse from the VM, open the CMD from before, and type “ping 192.168.56.101”—it pings through as well.
Try connecting over SSH—OK, all done!
Note: when pinging 192.168.56.1 from the VM, you may get no response. That’s likely a Windows Firewall setting—open the firewall settings and enable the ICMPv4 and ICMPv6 responses, as shown.





















