FreeBSD Cannot Connect To The Internet [DNS issue]

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. 

Symptoms

  • Pinging Google’s DNS server IP at 8.8.8.8 works, however pinging google.com will return the “Unknown host” output.
FreeBSD Cannot Connect To The Internet: ping IP works. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: ping IP works.
  • 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.

FreeBSD Cannot Connect To The Internet: updates don't work. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: updates don’t work.
  • 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 […]” 

FreeBSD Cannot Connect To The Internet: pkg doesn't work. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: pkg doesn’t work.

Fixing The DNS issue in FreeBSD

  1. 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.

su -
  1. Edit the  /etc/resolv.conf file by using the ee text editor available by default in FreeBSD.
cd /
ee /etc/resolv.conf
Configure address resolution in FreeBSD. Source: nudesystems.com
Configure address resolution in FreeBSD
  1. Locate the nameserver field. As you can see, the nameserver is configured as localhost, respectively the 172.0.0.1 IP. 
Configure address resolution in FreeBSD - nameservers [Original file]. Source: nudesystems.com
Configure address resolution in FreeBSD – nameservers [Original file]
  1. Change the nameserver 172.0.0.1 IP to your localdomain. In my case, the 192.168.40.2 IP.
Configure address resolution in FreeBSD - nameservers [Method 1]. Source: nudesystems.com
Configure address resolution in FreeBSD – nameservers [Method 1]

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 172.0.0.1.

Configure address resolution in FreeBSD - nameservers [Method 2]. Source: nudesystems.com
Configure address resolution in FreeBSD – nameservers [Method 2]
  1. 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.

FreeBSD Cannot Connect To The Internet: save resolv.conf. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: save resolv.conf.

Test the Internet Connection in FreeBSD

  • Test the new address resolution configuration by pinging google.com as following:
ping google.com
FreeBSD Cannot Connect To The Internet: ping google.com [fixed]. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: ping google.com [fixed].
  • Perform a freeBSD system update using the following command:
freebsd-update fetch
FreeBSD Cannot Connect To The Internet: System updates [fixed]. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: System updates [fixed].

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
FreeBSD Cannot Connect To The Internet: pkg [fixed]. Source: nudesystems.com
FreeBSD Cannot Connect To The Internet: pkg [fixed].

Wrapping Up

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.