FreeBSD Cannot Connect To The Internet [DNS issue]

By Leonard Cucos •  Updated: 08/05/21 •  3 min read

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

FreeBSD Cannot Connect To The Internet: ping IP works. Source: nudesystems.com

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

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

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

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

Test the Internet Connection in FreeBSD

ping google.com
FreeBSD Cannot Connect To The Internet: ping google.com [fixed]. Source: nudesystems.com
freebsd-update fetch
FreeBSD Cannot Connect To The Internet: System updates [fixed]. Source: nudesystems.com

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.

pkg install desktop-installer
FreeBSD Cannot Connect To The Internet: pkg [fixed]. Source: nudesystems.com

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

Leonard Cucos

Leonard Cucos is an engineer with over 20 years of IT/Telco experience managing large UNIX/Linux-based server infrastructures, IP and Optics core networks, Information Security [red/blue], Data Science, and FinTech.

medyum