Virtualbox sometimes can be a little annoying to configure, for example you need to discard saved states before enabling a NAT adapter and other annoyances. Here’s how to properly add internet access to all your virtual Linux machines indefinitely.
Pre-Requisites: Enable Ethernet Adapter And Discard Saved States
1. Shut down your machine
2. Before you continue make sure the ethernet adapter that VirtualBox installs is enabled. For some reason I disabled it the last time, so I had to re-enable it before I could proceed:
3. IMPORTANT: You have to discard any and all saved states before proceeding
4. Finally, you can select the CentOS / Ubuntu / Linux machine and click on the Settings button
5. Select Network and check the option Enable Network adapter – Attached to NAT
6. Confirm and start the machine
Testing Your Internet Access
7. Click the ethernet icon at the top right and make sure it’s actually turned on. By default this may be turned off:
8. Now open up the terminal and run a command like dig google.com or ping google.com to see if you get a response:
If you’re still having problems establishing a connection, you may have to forward some ports. Make sure your router is properly configured and for testing purposes remove all switches that may have problems with NAT. It is entirely possible that some routes are not properly configured in your router and/or that some switches are causing issues. Unfortunately you can’t always rely on the default configuration and have to tweak a few settings.
Also make sure to verify your DNS gateways. For additional troubleshooting information, please read this.