Quicker than editing /etc/hosts (not suitable for younger readers)
AnthonyEnglish 270000RKFN Comments (8) Visits (20896)
To Add an Address-to-Host Name Mapping with the hostent command, here's the syntax:
hostent -a IPAddress -h hostname
Those flags are easy enough to remember:
-a is to add an IP address
-h is the hostname
The hostent command also lets you add aliases, and it won't let you add the same IP address twice. If you try to add an IP address that already exists, you'll get a message like this:
hostent: 0822-041 The IP address 192.168.2.5 already exists.
You won't get that sort of service by blindly appending a new line to /etc/hosts. And if your hosts file is unwieldy because you don't have a trustworthy DNS, you may remember to do a search for duplicates before you add the new host, but then again, you may not discover two entries for the same IP address until someone else does.
Yes, I know editing /etc/hosts is still the way you're used to. You're a command line sort of a guy, aren't you? (After all, your date of birth is before the Unix epoch, right?) Well, using the hostent command is still using the command line!
Horses for courses
The point I'm trying to make is that sometimes editing a file is the smartest and shortest way (usually, in fact!) but sometimes you're better to go for an alternative. I use a mixture of SMIT and the command line, depending on the function I have to do. I'm not averse to using GUI interfaces ... but don't tell anyone born before the epoch.