How to add entry to local /etc/hosts

2,945 views
Skip to first unread message

Eric Clemmons

unread,
Jun 13, 2012, 1:14:56 PM6/13/12
to vagra...@googlegroups.com
It seems that the majority of documentation out there *hints* at how you can use a plugin/middleware/whatever to perform this task, but I can't find anything that's a functional, simple example.

All I want is to read from my Vagrantfile:

    ...
    config.vm.host_name = "mysite"
    config.vm.network :hostonly, "33.33.33.2"
    ...

and do something stupidly simple upon create like:

    echo "#{config.vm.network.ip} #{config.vm.host_name}.dev" >> /etc/hosts

Why does this seem so difficult to achieve?


sbfaulkner

unread,
Aug 19, 2012, 10:26:06 PM8/19/12
to vagra...@googlegroups.com
I've just recently created a gem that takes care of this for you.


Cheers

--Brent

sbfaulkner

unread,
Aug 20, 2012, 1:33:49 PM8/20/12
to vagra...@googlegroups.com
what is not connecting?

are you not able to `ping app` from puppet and vice-versa?



On Monday, August 20, 2012 11:35:38 AM UTC-4, Matthew McMahand wrote:
Hey there,

I tried out your gem and am trying to get 2 VMs to connect to one another. From what I can tell, everything looks alright in my config and /etc/hosts file, but I can't seem to connect from one VM to another.
I connect from one VM to another VM via IP address, but using hostnames doesn't seem to be working. Should I be able to do this with just /etc/hosts files?

Here's a gist showing my Vagrantfile and /etc/hosts on each machine.


Any help would be appreciated.

Matthew McMahand

unread,
Aug 20, 2012, 4:08:45 PM8/20/12
to vagra...@googlegroups.com
Can't ping from either machine.

So I've got 2 VMs that I'd like to use puppet with. One machine will run a puppet server (puppet), and the other has a puppet agent (app).

The problem I'm running into is that the 2 machines can't reach one another via a hostname. So puppet can't connect to app, and vice versa.
Now I can reach each machine if I put in their ips, but not with the hostname.

One thing I've tried changing with succes is each of these lines in my Vagrantfile:

app_config.vm.network :hostonly, "33.13.13.01"

changing that line to 192.168.1.11/12 then allows me to ping each machine via that custom hostname that gets added to /etc/hosts.

So I guess I've solved my problem, but I'd like to know why it works with a 192.XX address and not the 33.XX one.

sbfaulkner

unread,
Aug 21, 2012, 1:17:56 PM8/21/12
to vagra...@googlegroups.com
I just experimented with this and the problem is that the ip addresses that you provided are actually invalid.

You should not specify leading 0s (ie. use "33.13.13.1" instead of "33.13.13.01")

In fact, on CentOS you can't even provision the server using that address (33.13.13.01)

Cheers

Matthew McMahand

unread,
Aug 23, 2012, 9:24:07 AM8/23/12
to vagra...@googlegroups.com
I don't know really know much about networking, so this really helps. Thanks sbfaulkner!
Reply all
Reply to author
Forward
0 new messages