Homestead: Resolve host fails due to wrong nameserver

Created on 11 Nov 2018  路  9Comments  路  Source: laravel/homestead

Versions

  • Vagrant: Vagrant 2.2.0
  • Provider: Virtualbox Version 5.2.20 r125813 (Qt5.6.3)
  • Homestead: v7.19.0

Host operating system

macOS Sierra

Homestead.yaml

---
ip: "192.168.10.10"
memory: 4096
cpus: 2
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

sites:
    - map: foo.test
      to: /home/vagrant/Code/foo/web
      php: "7.1"
    - map: bar.test
      to: /home/vagrant/Code/bar/web
      php: "7.1"
    - map: apple.app
      to: /home/vagrant/Code/apple/web

Vagrant destroy & up output

GitHub Gist

Expected behavior

Expects the box to be able to resolve domains, listed within the homestead.yaml file.
curl --head foo.test should print the following:

vagrant@homestead:~$ curl --head foo.test
HTTP/1.1 500 Internal Server Error
Server: nginx/1.15.0
Date: Sat, 10 Nov 2018 23:58:17 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0

(It returns 500 due to missing db import after vagrant destroy)

Actual behavior

The box is not able to resolve the domains within the box.
curl --head foo.test return the following:
curl: (6) Could not resolve host: foo.test

Steps to reproduce

  1. Update everything to latest release
  2. Destroy the box and up it

My research

So I was working on a project, witch required project A to communicate serverside with project B. That means the server would have to know it鈥檚 domain internal, so it can look it up and serve the result.

I found out, that my /etc/resolv.conf is diffrent from my colleagues Homestead boxes, after days of research.

Before changing anything, only my old .app domains would resolve correct, witch I found very strange.
.test& .localwould just fail.

The content of my file:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53

Here鈥檚 one of my colleagues resolv.conf file:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.2.3

I tried to change this to 10.0.2.3, and it fixed all my issues!

However this is overridden after every restart of the box.

Is this due to a buggy systemd-resolved, or is it just me who has this issue? A other fix for now can be to write all my domains into the servers etc/hosts as well, but that鈥檚 not a nice fix.

Most helpful comment

just checked my /etc/resolv.conf and I also have 127.0.0.53. I'm also on MacOS.

This seems new, as I'm pretty sure my old box had 10.0.2.3.

I've been having possibly a different issue where I can't access the sites on Homestead after the machine has gone to sleep, unless I destroy && up the box.

All 9 comments

Without being able to see https://gist.github.com/sulfo/1047dccc1d0f41d5d5d4aa6bf9cfc989#file-log-txt-L78-L81 I can't say for sure.

But I'm near 90% sure it's not the cause (unless that script does anything with your network settings in the VM).

I'm somewhat comfortable saying it sounds like this is a MacOS probblem, but without others reporting it, it may be something limited to your mac. Until we get more people reporting this you can add the following to your after.sh to set the nameserver every time you provision the box:

sudo sed -i "s/nameserver 127.0.0.53/nameserver 10.0.2.3/" /etc/resolve.conf
sudo service networking restart

I鈥檓 updating it tomorrow with full text. However it鈥檚 just the same going for all my 25 domains, so nothing fancy...

I鈥檝e used homestead the past 3 years (thanks for the great work btw), and it鈥檚 the first time the VM鈥檚 nameserver is screwing it up.

The most weird part is that my old .app domains resolve correct.

I will give the command a try tomorrow. Thanks!

I added the following line in after.sh

sudo sed -i "s/nameserver 127.0.0.53/nameserver 10.0.2.3/" /etc/resolv.conf

The fix works for now, until we know what is going on. I'm more than happy to help you with more info if needed.

Thanks for the update!

just checked my /etc/resolv.conf and I also have 127.0.0.53. I'm also on MacOS.

This seems new, as I'm pretty sure my old box had 10.0.2.3.

I've been having possibly a different issue where I can't access the sites on Homestead after the machine has gone to sleep, unless I destroy && up the box.

I am also still experiencing this issue. Trying to build two services that need to talk to each other and found that impossible until I changed the nameserver in /etc/resolv.conf from 127.0.0.53 to 10.0.2.3. Why is this happening?

Also, is there a better solution than updating after.sh within the Homestead library? Something more permanent? As far as I know this has been an issue for a few versions of OS X and Homestead so its been around a while. I have no idea why this is a problem on OS X, but I would really like to not have to deal with this anymore.

I was experiencing something similar and none of this worked for me. If anyone isn't able to resolve the issue with the after.sh fix, you may want to try editing the /etc/hosts file inside vagrant. Adding any projects that need to communicate with each other there worked for me.

@realripley00 have you still been experiencing this issue even with the newest scripts? we recently added some code in the provisioning that adds /etc/hosts entries for all of your sites.

@browner12 I am still experiencing it. I noticed that it looks like the vagrant-hostsupdater is failing and that's why I manually added the projects in the vagrant hosts file. I'm not sure, but I imagine it has something to do with the fact that I updated from a really old version of Homestead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexdover picture alexdover  路  4Comments

teleclimber picture teleclimber  路  3Comments

leandroruel picture leandroruel  路  4Comments

Quix0r picture Quix0r  路  4Comments

svpernova09 picture svpernova09  路  5Comments