Problem scenario
On a CentOS server running in VirtualBox, networking is not working. You cannot ping the default gateway or get to the internet. When you try to ping something, you get the error message in a terminal "connect network is unreachable." What should you do?
Solution
In Oracle VirtualBox, go to Devices -> Network Settings. Make sure the adapter is attached to "Bridged Adapter".
Go to the CentOS terminal and run this: sudo ls /etc/sysconfig/network-scripts/
View the content of the file that you find (e.g., ifcfg-enp0s3). The "ONBOOT=" stanza should look like this:
ONBOOT=yes
The BOOTPROTO stanza should look like this:
BOOTPROTO=dhcp
Finally reboot the VM or restart the networking services for the changes to take effect.