Is it possible to route all subdomain requests regardless of top level domain to a given ip with dnsmasq?
I would like to get something like this to work.
address=/dev.*/127.0.0.1
So any production url if prefixed with dev will route to my dev server.
So any tld such as mysite.mobi or mysite.com if prefixed with dev. will still route to 127.0.0.1
So far I have tried the following with no luck
address=/dev./127.0.0.1
address=/dev*/127.0.0.1
address=/dev.#/127.0.0.1
address=/dev#/127.0.0.1
address=/#dev#/127.0.0.1
Any help would be great
Not prefixed but postfixed, I've done the following on Xubuntu (on 14.04):
# install "dnsmasq"
sudo apt-get install dnsmasq
# create a configuration file for using .dev as tld
sudo nano /etc/dnsmasq.d/devtld.conf
# add "address=/dev/127.0.0.1" and save the changes
# restart the service after configuring
sudo /etc/init.d/dnsmasq restart
Ensuring that any URL ending in ".dev" is routed to 127.0.0.1 aka localhost.
For example, after above configuration the following are equivalent:
http://localhost:8080
http://127.0.0.1:8080
http://www.example.com.dev:8080
http://subdomain.example.com.dev:8080
Related
I am setting up a new machine. I have it configured to use a Sites folder and localhost to access it. Using Apache, everything installed via Homebrew.
Sites folder
site1
site2
In the browser
localhost/site1/index.html
localhost/site2/index.html
That part works fine.
The problem is that site1 and site2 think localhost is the root folder (which it is) but I want them to think localhost/site1 and localhost/site2 are the root folders for those sites.
Is this something I can do with /etc/hosts or some other trickery?
It turns out this is a combination of /etc/hosts and Apache VirtualHosts. Here are the steps I took:
Establish the directories where you want to serve them from (this will become your DocumentRoot). In my case /Users/myusername/Sites/site1
Edit your /etc/hosts file to include your new "domain name" (this will become your ServerName). In my case site1.com
127.0.0.1 site1.com
::site1.com
Create an Apache Virtual Host ... there are different ways to go about this, but I used Homebrew to install Apache, so for me, there is a file here: /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf. I copied the examples provided using DocumentRoot and ServerName as noted above.
Update this file /opt/homebrew/etc/httpd/httpd.conf to uncomment this line
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
Restart Apache
I'm trying to set up my local web development environment to map all .test domains to 192.168.10.10 IP. The problem is that I find all the tutorials extremely confusing.
Here's what I did already:
I installed dnsmasq using Homebrew with brew install dnsmasq command.
I put address=/.test/192.168.10.10 to /usr/local/etc/dnsmasq.conf.
I'm not sure what to do with the resolver. I have an /etc/resolv.conf file containing nameserver 172.20.10.1 (I don't know where it comes from) and then some tutorials say to create /etc/resolver/test file and putting nameserver 127.0.0.1 there.
Here's where I'm lost. First of all, which resolver should I use? The resolv.conf file or /etc/resolver/test? If that's the latter one, should I edit out the resolv.conf? And also, should I put nameserver 127.0.0.1 or nameserver 192.168.10.10? I don't understand if that's supposed to be the IP of my local machine (127.0.0.1) or my web dev machine (192.168.10.10).
Please help me to understand it better.
I'd like to point all *.test domains to my Laravel Homestead machine on 192.168.10.10. I used to have it working with *.dev domains, but after new *.dev policy implemented by Chrome 63, I prefer to change it to *.test.
I fail to understand how local DNS works, as it seems to use trillion different configs and caches. What I did is:
Making sure 192.168.10.10 with HTTP Host set to me.test works. It works.
In /usr/local/etc/dnsmasq.conf, I do have an entry address=/.test/192.168.10.10 (I also tried with 127.0.0.1)
In /etc/resolver/test file, I put nameserver 127.0.0.1 - it used to work this way with /etc/resolver/dev. I still don't understand why it's 127.0.0.1 and not 192.168.10.10. I tried both anyway.
Clearing DNS cache with sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache
Restarting dnsmasq with sudo launchctl stop homebrew.mxcl.dnsmasq; sudo launchctl start homebrew.mxcl.dnsmasq.
Trying to visit http://me.test/.
It doesn't work. The domain will take forever to be loaded and nothing happens.
What am I doing wrong?
My OS is High Sierra, dnsmasq installed via homebrew.
I don't use dnsmasq, but I believe you want to edit /usr/local/etc/dnsmasq.conf and have listen-address=127.0.0.1 set so dnsmasq is listening on that IP, but have address=/.test/192.168.10.10 so that .test is routed to 192.168.10.10.
Then make sure System Preferences -> Advanced you have 127.0.0.1 as the first DNS server entry for your connection.
Make sure you're restarting dnsmasq every time you edit the configuration file.
i'm using wamp 5, windows XP. i have edited my host file in my local disk like the code below and it works
127.0.0.0 example.com
but i'd like to redirect to a particular folder, if i change it to the code below, it dont work
127.0.0.0/main/site example.com
how to redirect example.com to 127.0.0.0/main/site locally in my PC?
btw, i dont want to install any new software to solve this prob
You need to create a Virtual Hosts
Leave the HOST file as
127.0.0.1 example.com
When you define a Virtual Host you also tell it which folder is its DocumentRoot so that will send it to the right place when you use the address example.com in the browser.
Check out wampserver.com
How can i run local tests ( with mamp ) that have urls of this kind : www.example.com instead of http://localhost:8888/install.folder
Thank you
If your tests are truely local, you may simply add an alias in your hosts file (/etc/hosts on linux). This alias will cause your computer to resolve www.example.com as 127.0.0.1 (localhost).
If you wish to use this outside of your computer, you will need to purchase a domain, and set its DNS up to forward to your IP address (and open the appropriate port in your router to forward to your computer).
If you don't want to have to include the port number (':8888'), change the port that your server is being hosted on to the default (80). This may be done through the server's configuration file by changing the 'Listen' directive.
If you do not want to have to add the '/drupal' path, add an 'Alias' directive to redirect the user from the root path ('/') to '/drupal'. You may also change the 'DocumentRoot' to drupal.
You will need to add an entry to your hosts file like this:
127.0.0.1 www.example.com
Note: this will not keep you from having to enter the port number or directory - it will only allow you to use a host alias for the host name itself.