We have a Vagrant set-up running Ubuntu 12.04 as the guest OS across our team where the host OS is Windows 7 or 8. What I'd like to be able to do is to is to get the hostname of the Windows host machine and append this to the Vagrant hostname during setup e.g.
config.vm.hostname = <windows hostname>-web
This is because we have several developers connecting to external services from their local dev machines and if we all have the same hostname set (as the Vagrant file is source controlled and is the same for everyone) then in the logs for these external services we can't differentiate who made what request to the service. I thought if we were able to dynamically get the hostname from the host OS it would be a good way to identify individual guest OSes running on each developers machine.
Is this possible and if so what is the best way to achieve it?
In Windows, the environment variable COMPUTERNAME holds the hostname.
Since Vagrantfile is actually a Ruby script, you can set the hostname like this:
config.vm.hostname = "#{ENV['COMPUTERNAME']}-web"
On OSX ENV['COMPUTERNAME'] will evaluate to nil so you could use this to set the hostname on any Windows/*nix system:
config.vm.hostname = "#{ENV['COMPUTERNAME'] || `hostname`[0..-2]}-web"
Update: I never realized that Windows has a hostname command. At least Windows 7 does. I don't know how far back it goes. So you could simply use the following on all systems:
config.vm.hostname = "#{`hostname`[0..-2]}-web"
I used this technique but I had to modify the expression somewhat.
If hostname returns an FQDN like it does on the Mac, the original didn't quite work.
Below is Working solution for both Mac and Windows.
config.vm.hostname = "#{`hostname`[0..-2]}".sub(/\..*$/,'')+"-web"
Related
I'm currently testing a few websites on Ubuntu Server installed on Oracle VM Virtual Box on a Windows 11 machine.
I need to type an IP address to access these sites (eg: 192.168.xxx.xxx).
Is it possible to use something like a domain name to access them instead of using an IP address? Like mysite1.com, mysite2.com etc.
I'm not using domain names booked on godaddy or some place like that. Just names for local testing. How can it be done in this scenario? Everything is installed on the same machine.
Add your sites to /etc/hosts file like this:
192.168.... mysite.domain
Yes, you can go to /etc/hosts and apply IP you are using and the domain name you want:
Example.
Open with:
sudo nano /etc/hosts
apply:
192.168.x.x mysite.com
And restart server.
TRY CLEAN CACHE
sudo apt-get install nscd
AND NOW
sudo service nscd restart
or
sudo service dns-clean
To restate your setup, you have one Ubuntu server guest VM (in VirtualBox) running on Windows 11. Because you mentioned the 192.168.x.x IP range I will assume the guest VM is on a "bridged" vbox network adapter that any device on your local network can ping. I also have to assume the IP address(es) you are using are successfully connecting you from your Windows 11 host to your Ubuntu guest. Is all this correct? Does your VM have a desktop and a web application that can reach popular sites on the internet? Does the Ubuntu OS use DHCP or a static IP assignment?
The short answer is yes, you can use domain names instead of IP addresses. If you are not successful connecting to the IP address, switching to domain names will not help you. You have to have all the network dependencies satisfied first.
To choose a domain name for testing;
You should take a look at RFC 6761. Specifically at secion 6; 6.1 - 6.5
https://www.rfc-editor.org/rfc/rfc6761.html
.in-addr.arpa.
10.in-addr.arpa. 21.172.in-addr.arpa. 26.172.in-addr.arpa.
16.172.in-addr.arpa. 22.172.in-addr.arpa. 27.172.in-addr.arpa.
17.172.in-addr.arpa. 30.172.in-addr.arpa. 28.172.in-addr.arpa.
18.172.in-addr.arpa. 23.172.in-addr.arpa. 29.172.in-addr.arpa.
19.172.in-addr.arpa. 24.172.in-addr.arpa. 31.172.in-addr.arpa.
20.172.in-addr.arpa. 25.172.in-addr.arpa. 168.192.in-addr.arpa.
.test.
.localhost.
.invalid.
.example.com.
.example.net.
.example.org.
You may have to create/modify the \windows\system32\drivers\etc\hosts file that Windows uses to intercept asking DNS for IP/host mapping. If you are using a linux/unix client, the /etc/nsswitch.conf AND /etc/hosts files could override DNS for you. This may or may not be in the same location on Windows 11 but as of Windows 10 21H2 it was still there.
I'm setting up a local dev environment, as part of this I need to redirect a domain name (including all subdomains) to a local IP address.
I have achieved this on Linux using dnsmasq with this line in the config:
address=/example.com/10.0.19.12
This looks like it will also work on OS X, but I now need the same effect on Windows. How would I get a Windows machine to do this too?
We need to share VMs with Linux, MacOS and Windows hosts. However, for Linux and MacOS, NFS sharing is recommended, but for Windows, NFS sharing is not supported.
Is there are way to detect the that host OS is Windows and disable NFS shares?
Vagrant 1.2.5
This has actually already been taking care of as of Vagrant 1.2.5, see Option for NFS is not silently ignored on windows hosts and the respective commit b2d1a26 (NFS request is silently ignored on Windows):
#__synced_folders.each do |id, options|
# Ignore NFS on Windows
if options[:nfs] && Vagrant::Util::Platform.windows?
options[:nfs] = false
end
end
Previous Workaround
If you aren't able to upgrade you might want to try Ryan Seekely's Vagrant and using NFS only on non Windows hosts:
Well, since a Vagrantfile is nothing but a Ruby script, we can just
use Ruby! At the top of the Vagrantfile define:
def Kernel.is_windows?
# Detect if we are running on Windows
processor, platform, *rest = RUBY_PLATFORM.split("-")
platform == 'mingw32'
end
And then when configuring your shared folder:
nfs = !Kernel.is_windows?
config.vm.share_folder "myfolder", "/srv/www/myfolder.com/", "../", :nfs => nfs
Please note that I haven't actually tested this particular solution, but have been using a conceptually similar approach myself before, albeit using Vagrant::Util::Platform.windows? as in the official commit (don't have it handy right now ...).
I have a question for all you Vagrants and TDD'ers out there,
How can I make a Vagrant Ubuntu VM send autotest / guard notifications to a Windows 7 or OS X host?
Details:
I'm trying to build my ultimate road-warrior development environment, so that I can jump between computers, OS's, and countries without worrying about reconfiguring my environment all the time. I'm using Vagrant to make disposable VMs that mirror our production environment, and letting me jump from my work computer (Windows 7) to my home computer (OS X) with minimal hassle.
I am trying to configure my Vagrant Ubuntu VM for use with Test-Driven Development (TDD), and make use of autotest / guard utilities to automatically run my tests on save, and display the results as desktop notifications on the host. I run the Vagrant VM in headless mode, so there is no desktop to receive the notifications, so I need them forwarded to the host.
I have a couple of leads, like using Growl's remote notifications (for receiving, but I don't know how to send them from the Ubuntu VM), or hacking Growl, but I thought that this problem must have been addressed by others out there.
Found a way to make it work on Windows 8 host and Ubuntu vagrant box:
Install gem ruby_gntp in rails.
Add to Guardfile:
`notification :gntp, :sticky => false, :host => '192.168.0.77', :port => '23053', :password => 'yourpassword'`
192.168.0.77 is the IP of host machine, you can find it by running ipconfig.
23053 - standard port for growl.
Install growlforwindows and set network subscription to Vagrant box( help)
with host 10.0.2.2, port 23053 and password yourpassword
10.0.2.2 - default IP of vagrant box gataway, you can confirm it by running netstat -rn in vagrant ssh.
Finally you can run guard -p and start tests.
If you get error 'refused', then it's wrong IP in Guardfile, for example this happens if I set gateway IP of windows machine instead of local IP.
If you get error 'Notiffany register filed', then it's wrong ip in growlforwindows.
Well, why don't just forward all the tests' output to a file, then connect via SSH and see the results?
Basically tail -f command comes handy here.
I am trying to connect to a TCP socket on a Windows XP machine using the computer name from an iPad.
I've tried using:
getaddrinfo(hostName, 4097, &hints, &res0);
This fails when hostName = "MyHost" and succeeds when hostName = "192.168.0.4"
I've tried using AsynchSockets with the same results using:
[mySocket connectToHost:hostName onPort:4097 error:nil];
The XP machines do just fine connecting using:
Winsock.RemoteHost = "MyHost" for VB
and
MySocket->Connect("MyHost", 4097); for C++
How do I do something similar on the iPad using Xcode?
You're going to need an SMB client library for iOS. Here's a place to start:
http://38leinad.wordpress.com/2011/03/23/windows-filesharing-library-for-ios/
If it works with direct IP and doesn't with a hostName 'MyHost'
this most probably means that 'MyHost' isn't getting resolved (to an IP) on iPad.
For example: there's a file called hosts (usually c:\windows\system32\drivers\etc\hosts)
on an XP machine - where a host name like MyHost can have it's IP defined.
A line "192.168.0.4 MyHost" would do just that.
It seems you can't edit hosts file on non-jailbroken iPad: Can I edit an iPad's host file?
But here you can find a way around this.