Domain redirection to localhost
What is this: When you enter http://www.yahoo.com in your address bar of browser, It wont go to http://www.yahoo.com rather it will show a custom page which is inside you pc not in Internet.
Why is this: Sometimes you may need to restrict your children from accessing site that contains adult content, violent pictures etc. Also web service developer may use it to simulate and debug web service host.
Tools: You need actually nothing. Only skill of editing files. A text editor will do. In Windows machine you can use notepad.exe. For Linux machine you can use vi, ed, ee etc.
How: There is a special file called `hosts` which contain about domain and ip address mapping information. The format is plain text. In Windows the file in “%SystemRoot%System32DriversEtc†directory and in Linux its in “/etc†directory. Here is a sample file content for my Windows XP Service pack 2.
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
Its almost same for Linux. This file is responsible to redirect any request to “localhost†domain to 127.0.0.1 IP. Yes, thats why you get ping response from 127.0.0.1 when you ping “localhostâ€.
Now open the file and add some alias to “localhost†entry. Like the following,
127.0.0.1 localhost badweb.com www.badweb2.net
When you are done saving the file. Ping “badweb.comâ€. You’ll get response from 127.0.0.1. Now whenever someone enters in any browser it will show the content of http://127.0.0.1/. If you don’t have any web server installed it will show a “page not found†page. And it serves our purpose as well. The surfer of badweb.com will always see the web is down. 😉
Disadvantage: The main problem is if you put “badweb.com†as alias it wont work for any sub domain of “badweb.comâ€. For example, If you put,
127.0.0.1 localhost badweb.com
Entering http://www.badweb.com/ wont redirect to http://127.0.0.1 also http://anysubdomain.badweb.com wont work too. To work around you have to put series of sub domains. Like this,
127.0.0.1 localhost badweb.com www.badweb.com anysubdomain.badweb.com
For this the entry will be too long. 🙁
Some addition: You can enhance it more by the following methods
- Installing a web server.
- Creating alias IP for your network device
Installing a web server will make you show a customized page. You can put a message there too. Like “Access deniedâ€. So unauthorized user will see your message every time they visit their page. Also you can put per domain customized page with a little knowledge of Javascript or PHP or URL rewrite.
If you can create alias of your own IP pinging the domain will get response from different IP and all of the IP are alias. Its just same web but IPs are different. if you use 176.16.16.[1-254] as you alias you can put some entry in hosts file like the follwing
127.0.0.1 localhost
176.16.16.1 badweb.com
176.16.16.4 www.badweb.com
176.16.16.2 badweb.net
176.16.16.3 verybadweb.com
Now you’ll get response from different IPs. It’ll be hard for visitor to track the whole thing.
Thats all.
Keep bluffing.
I absolutely understand what you have explained. In fact, I browsed throughout your other posts and I think that you are totally right. Congrats with this website.