Redirect URL on Windows (local dev environment) - windows

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?

Related

Use a domain like name to access a test site instead of an IP address

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.

Change the name of the Mounted Drive on Mac OS X using applescript

I am mounting a drive on mac os using applescript.
tell application "Finder"
try
mount volume "http://user:pwd#196.145.75.18/mydrive/page.apsx/webdav"
end try
end tell
I am getting drive name as 'webdav' and on the sidebar in shared section I am getting the server address(196.145.75.18) as drive name.
I want to change both of them as 'mydrive'.
Does anyone know how it can be done using applescript? if can not be done using applescript then is there any other way to do this?
What you're doing is the equivalent of using the Finder's "Connect To Server..." command in the Go menu. If you use an IP address there, you're also going to see an IP address in the sidebar. There's no way to change that.
If your target server is on your LAN and has Bonjour/mdns (e.g. OS X, Windows with Bonjour Print Services or iTunes installed, or Linux with avahi-daemon installed), you can instead use "myserver.local" for an address. You can also put "local" as a search domain in your DHCP server (usually your router, but could be OS X Server for example), or manually into your network settings on your client machine(s), to just use "myserver" without ".local".
Or, if your target server is on the WAN, and you have a DNS server for mydomain.com (usually your registrar provides one, or you can host your own with, for example, OS X Server or a router firmware like DD-WRT), you can create a machine (A) record for "myserver.mydomain.com" for that IP address. In your DHCP server (typically your router, but it could be OS X Server), put "mydomain.com" in the DNS search domains; or, if it's a laptop that needs to work in multiple places, put it in manually into the network settings on your client machine(s). Then you don't have to enter the FQDN for an address when you connect, just "myserver".
bash:
mkdir /Volumes/webdav
mount_afp http://user:pwd#196.145.75.18/mydrive/page.apsx/webdav /Volumes/webdav
or more likely:
sudo mkdir /Volumes/webdav
sudo mount_afp http://user:pwd#196.145.75.18/mydrive/page.apsx/webdav /Volumes/webdav
Case 1 in applescript:
do shell script "mkdir /Volumes/webdav"
do shell script "mount_afp http://user:pwd#196.145.75.18/mydrive/page.apsx/webdav /Volumes/webdav"
To use sudo in applescript, you need to create dialog box to type in password etc.

Vagrant: Get name of host OS

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"

how to access vagrant box "guest machine" from host machine?

I am using puphpet.com tool to set up Vagrant boxes.
Now , I am able to ssh to it and open the IP on the browser but I can not get to access the VHost I set up earlier through puphpet.
I have edited my hosts file (/etc/hosts ) "using OSX" to serve the IP 2.168.56.101 to lab.dev. Now it works fine but I can not access the virtual machine on the guest machine !!!!.
I am using PHP Laravel framework and I need to access the server name which points to /var/www/lab.dev/public/. I would appreciate very detailed answer as I am really new to all of this
Detailed Instructions
Visit PuPHPet.com to build your Vagrantfile.
Configure your Shared Folder Pairs. This is under "Deploy Target > Locally".
Let's assume this directory structure on your OS/X machine:
/Users/unrivaled/Documents/laravel-project (project files go here)
/Users/unrivaled/Documents/laravel-project/public (the web root files)
Folder Source represents the location on your main computer (the "host" operating system), where your source files reside; for example: /Users/unrivaled/Documents/laravel-project The Folder Source must be on your OS/X machine, exactly where your Laravel files are.
Folder Target represents the location on your virtual computer (the "guest" operating system), where you want Vagrant to make them visible to the web server; for example: /var/www/lab The Folder Target can be anywhere that Apache or Nginx, in the virtual machine, can reach it.
Folder Source (local machine) == Folder Target (virtual machine)
/Users/unrivaled/Documents/laravel-project (local machine) == /var/www/lab (virtual machine)
Configure your web server. Your Server Name can be anything you want; in this example, let's use "lab.dev". Configure your Server Alias; in this case, use "www.lab.dev." Your Server Name (or an alias) must match your entry in your /etc/hosts file; see below. Configure your Document Root. This is the folder on your virtual machine where your website files will go and the files that will be served by Nginx or Apache. This value must be at, or below, the Folder Target defined from Step 4; for example, /var/www/lab/public.
Notice in the example how we are giving the web server access to /var/www/lab/public? This actually refers to /Users/unrivaled/Documents/laravel-project/public on your local OS/X system, thanks to the "Shared Folder Pairs" configured in Step 2., above.
Generally, configure everything else in PuPHPet as you see fit.
Run vagrant up to get your virtual machine up and running. If it doesn't work at this stage, you need to resolve any problems before going on.
Determine your virtual machine's IP address. Use vagrant ssh to log into the virtual machine, and then ifconfig should work for this. Do not rely on the IP address defined in PuPHPet. Your virtual machine provider will likely override this value, and you need to know the actual, in-fact IP address.
On your main host computer (not the virtual machine), edit your /etc/hosts file: sudo nano /etc/hosts, adding the server's IP address, followed by the Server Name (or a Server Alias) defined in Step 5, above.
How It Works
Once you have a working web server using the settings in this example, you can view your website by going to lab.dev. Your browser in OS/X will resolve lab.dev to the proper IP address of your server by way of the /etc/hosts file. It then requests your web page from that IP address, where the server matches the requested resource, "lab.dev," to the appropriate Server Name or Server Alias that matches. The files in the Document Root for that server name (/var/www/lab/public) will be processed by the web server.
In summary, your server's IP address in the local /etc/hosts file matches your server's IP address in the virtual machine; your server's name in the local /etc/hosts file matches your Server Name (or Server Alias) in the web server on the virtual machine; the path name to your project source files on your local computer (Folder Source) maps to the Target Directory on the virtual machine; and finally, a subdirectory of that target directory (public) corresponds to the Document Root for the web server.

Sending autotest / guard desktop notifications from Vagrant Ubuntu VM to host (W7 and OS X)

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.

Resources