Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: A shell script to do DNS lookups in the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: A shell script to do DNS lookups in the Terminal
Authored by: TigerKR on Sep 21, '05 12:41:48AM

If you want, you can add a line to your hosts file, that later you can delete.

$ sudo echo "127.0.0.1 test.this.webserver.com" >> /etc/hosts

You should be able to see the affects of this change immediately (or you may need to close and reopen whatever internet enabled application you're using - your milage may vary).

For instance, if you're testing some web site that you're developing, you can start web sharing (apache) and then put your web development files in the apache default directory. And if you use absolute links (as opposed to relative links), they'll resolve to your machine (as long as you've set them to with the hosts file).

As always, when you're editing an important file, I recommend that you make a backup before editing the file with a command such as:

$ sudo cp /etc/hosts /etc/hosts.apple_default

If you need to go back to the original file simply execute:

$sudo cp /etc/hosts.apple_default /etc/hosts

Here's a bonus tip. If you get your IP address via DHCP and you don't want your ISP assigned hostname to show up in the terminal, you can add a line to your hosts file with your IP and whatever host name you want. Example:

$ sudo echo "10.0.0.13 rockinbox" >> /etc/hosts

And as long as 10.0.0.13 is your actual ISP assigned IP address, then your terminal will show up as:

rokinbox:~ username$

This will survive restarts, but not necessarily system updates, as the hosts file may be reformatted during a system update.



[ Reply to This | # ]
10.4: A shell script to do DNS lookups in the Terminal
Authored by: jmincey on Sep 21, '05 09:11:54AM

I'm afraid you've lost me on this. If one is using DHCP and uses no on-site router and instead gets his IP address from his ISP, then it is very unlikely to be of the 10-dot addressing format. Also, this IP address will most certainly NOT survive a restart of the computer except under very specific circumstances. Many users, depending on their connection type with their ISP, will not be assigned the same IP address.

---
Jeff Mincey



[ Reply to This | # ]
10.4: A shell script to do DNS lookups in the Terminal
Authored by: TigerKR on Sep 22, '05 01:31:58AM

>I'm afraid you've lost me on this. If one is using DHCP and uses no on-site
>router and instead gets his IP address from his ISP, then it is very unlikely to
>be of the 10-dot addressing format. Also, this IP address will most certainly
>NOT survive a restart of the computer except under very specific
>circumstances. Many users, depending on their connection type with their ISP,
>will not be assigned the same IP address.

You are correct, the 10.x.x.x range is for internal networks, however, I was using that as an example because I don't have the patience to type out every possible IP address combination. ; - )

Technically, you are also correct that most DHCP IP addresses are not guaranteed, however, many large broadband ISPs match IP addresses to MAC addresses, so your IP could change, but in reality, it never changes. For instance, my IP address on Comcast Broadband never changes, unless I use a different computer or a different network interface (ie: a second ethernet card).

In any event, my hint will not damage your computer or network connection in any way, because dns lookups start with the domain/host name first, not the IP address first. In the event that you were assigned a different IP address, my hint would simply not work, and your terminal host-name would revert to its ISP assigned host-name.

If someone else on your sub-net (another client of your ISP) got your old IP address, the worst case scenario would be that if you tried to use your /etc/hosts host-name to connect to yourself (it would never work outside of your computer because your /etc/hosts file does not exist on any other computer, nor is it published to any other computers), then you might be connected to that other computer on your sub-net, but its unlikely that anything would happen, unless your neighbor used the same software, services, usernames, and passwords a you use on your computer. ; - )

Thank you for posting your comments though, because I really should have been clearer and more explicit.

Cheers.



[ Reply to This | # ]