After a fresh FreeBSD install in VMware or VirtualBox, you may encounter an issue where FreeBSD cannot connect to the Internet. Therefore when trying to ping a domain name [e.g., google.com], perform a system update, or install new packages via pkg, the system will return a DNS error.
I encountered this issue with FreeBSD 13 installs on VMware as well as VirtualBox.
This DNS issue is caused by a nameserver misconfiguration in the /etc/resolv.conf file and was initially reported here.
This troubleshooting tutorial will take about 5 minutes to complete if you have minimal experience with FreeBSD and a maximum of 30 seconds if you are an experienced user.
The DNS problem was not encountered when installing FreeBSD 13 on hardware but if you experience the symptoms below, this is a fix you might want to try.
- Pinging Google’s DNS server IP at 220.127.116.11 works, however pinging google.com will return the “Unknown host” output.
- When trying to update/upgrade the system with pkg, FreeBSD will return the following output:
“Looking up update. FreeBSD.org mirrors… none found. Fetching public key from update. FreeBSD.org […] failed. No mirrors remaining, giving up […] If unsupported, FreeBSD must be upgraded by source.”
- When using pkg to install a new package, FreeBSD will return the following output:
“pkg: Error fetching http://pkg.FreeBSD.org/FreeBSD:13 […]. Address resolution failed […]”
Fixing The DNS issue in FreeBSD
- Luckily, this DNS resolution fix in FreeBSD is simple and straightforward. Log in on FreeBSD using your root account.
If you are already logged in using your normal user, type in the terminal the following command to switch to the root user. When prompted, type your root account password.
- Edit the /etc/resolv.conf file by using the ee text editor available by default in FreeBSD.
cd / ee /etc/resolv.conf
- Locate the nameserver field. As you can see, the nameserver is configured as localhost, respectively the 18.104.22.168 IP.
- Change the nameserver 22.214.171.124 IP to your localdomain. In my case, the 192.168.40.2 IP.
Alternatively, you can simply uncomment the first nameserver line with your local domain IP [your VMware/VirtualBox DNS server IP] and comment/remove the line with nameserver 126.96.36.199.
- Save the modified /etc/resolv.conf file.
Hold the ESC key and pressing ENTER. Select a) save changes and hit the ENTER key to save the new configuration.
Test the Internet Connection in FreeBSD
- Test the new address resolution configuration by pinging google.com as following:
- Perform a freeBSD system update using the following command:
NOTE: If there are any new updates in your FreeBSD system, you can proceed further with updates installation by using the freebsd-update install command.
- Use pkg to install a FreeBSD package, e.g., desktop-installer.
pkg install desktop-installer
In most cases when FreeBSD cannot connect to the Internet, VMware, VirtualBox, or otherwise, this issue is caused by some DNS misconfiguration in your system.
This tutorial shows you not only fix a DNS issue but also help you learned where the address resolution configuration is located in FreeBSD, in case you face similar issues in the future.
I hope this helps! If so, do me a favor and share this guide around on the Internet – I genuinely appreciate it!
But most importantly, stay safe.