MacOS X – Associating a name to an IP Address

Last update on May 12, 2009 11:33 AM by jak58
Published by jak58

MacOS X – Associating a name to an IP Address






What you should know


Please note: this is only valid until MacOSX 10.4, NOT for MacOSX 10.5 (Leopard)

MacOSX is a BSD system, the first thing that we think is:
"Easy, I'll change my files /etc/hosts"

This is a good thought, but unfortunately by default on OS X, this file is never taken into account.

Name resolution via the NetInfo Manager. There are several methods to ensure that the file /etc/hosts should be taken into account before or after the NetInfo Manager, but since NetInfo works well, as much use, especially as it simplifies troubleshooting when all information is in one place!

Use this step


Here is the method in command mode that is not so complicated and has the merit that it can be done without necessarily having physical access to the machine (via SSH).

Everything goes from a bash terminal (/Applications/Utilities/Terminal)

It must first retrieve the current configuration:

$ mkdir -p ~/hosts
$ cd ~/hosts
$ nidump hosts / > hosts.conf.ori


Copy the file to retain the original configuration (. Ori)
$ Cp hosts.conf.ori hosts.conf 



Again, make the desired changes in the hosts.conf.
You should add a line and not to modify existing lines unless you know what you are doing!

Once modified, you must reload the file into NetInfo (as root, so using sudo)
$ sudo niload hosts . < hosts.conf




If everything goes without error (otherwise, you must either correct the error in the file hosts.conf or redo the manip with. Ori), restarting the search service name:
$ sudo killall -HUP lookupd

Now you have to test it

Example


Lets make a test: Associating www.ccm.net to www.commentcamarche.net (194.169.240.130)
$ ping www.ccm.net
ping: cannot resolve www.ccm.net: Unknown host
$ mkdir -p ~/hosts
$ cd ~/hosts
$ nidump hosts / > hosts.conf.ori
$ cp hosts.conf.ori hosts.conf    
$ cat hosts.conf
::1     localhost
255.255.255.255 broadcasthost
127.0.0.1       java.localhost
127.0.0.1       php.localhost
127.0.0.1       mysql.localhost
$ echo "194.169.240.130 www.ccm.net" >> hosts.conf
$ cat hosts.conf
::1     localhost
255.255.255.255 broadcasthost
127.0.0.1       java.localhost
127.0.0.1       php.localhost
127.0.0.1       mysql.localhost
194.169.240.130 www.ccm.net
$ sudo niload hosts . < hosts.conf
$ sudo killall -HUP lookupd
$ ping -c4 www.ccm.net
PING www.ccm.net (194.169.240.130): 56 data bytes
64 bytes from 194.169.240.130: icmp_seq=0 ttl=56 time=29.936 ms
64 bytes from 194.169.240.130: icmp_seq=1 ttl=56 time=30.622 ms
64 bytes from 194.169.240.130: icmp_seq=2 ttl=56 time=30.053 ms
64 bytes from 194.169.240.130: icmp_seq=3 ttl=56 time=30.566 ms

--- www.ccm.net ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 29.936/30.294/30.622/0.303 ms


And now, to remove this definition, it is not enough to look through niload file hosts.conf.ori. Indeed, in addition niload works.

Here's how to use the command niutil to delete the entry www.ccm.net

$ sudo niutil -destroy . /machines/www.ccm.net


Remember lookupd reload after each change! (sudo killall-HUP lookupd)
Best answers for « MacOS X – Associating a name to an IP Address » in :
Command to detect your IP address! ShowCommand to detect your IP address! Command for Windows 2000 / XP / Vista Command for Windows 95/98 Command for Linux IP address (Internet Protocol) is a numerical identification to detect your computer on a network. It is used to...
Having a static IP address under Ubuntu 8.10 ShowHaving a static IP address under Ubuntu 8.10 To have a fixed IP persistent: Configure manually the interfaces For a fix IP (10.0.0.1 on your eth1 interface) use: To make use of dynamic IP (e.g eth0): DNS NetworkManager is a...
What is your IP address? ShowWhat is your IP address? What is an IP address? How to know your IP address? For Windows 2000/ Windows XP/ Windows Vista users For Windows 95/ Windows 98 users By using online tools What is an IP address? When a PC is connected to...
Download IP Traffic Monitor ShowIP Traffic Monitor monitors all network connections on the computer where it is installed. The program shows you detailed information, such as the remote IP address, host name if available, details of inbound and outbound traffic. Advantage It...
IP address spoofing ShowIP address spoofing "IP address spoofing" is a technique that involves replacing the IP address of an IP packet's sender with another machine's IP address. This technique lets a pirate send packets anonymously. It is not a question of changing the...
IP Address ShowWhat is an IP address? Computers communicate over the Internet using the IP protocol (Internet Protocol), which uses numerical addresses, called IP addresses, made up of four whole numbers (4 bytes) between 0 and 255 and written in the format...
DNS (Domain Name System) ShowWhat is DNS? Each computer directly connected to the Internet has at least one specific IP address. However, users do not want to work with numerical addresses such as 194.153.205.26 but with a domain name or more specifically addresses (called...