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
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# 126.96.36.199 rhino.acme.com # source server
# 188.8.131.52 x.acme.com # x client host
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 http://www.badweb2.net 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
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
Now youâ€™ll get response from different IPs. Itâ€™ll be hard for visitor to track the whole thing.