Q:

How IP resolves a hostname?

I understand that the job of IP in the TCP stack, when dealing with an outgoing message, is to resolve an IP address from a host name and add this address as a header.
Is this process that IP goes through equivalent to using a tool like nslookup for a given hostname?

A:

Your understanding is incorrect. IP doesn't know anything about device names, it only deals with IP addresses.
An application can query a DNS server or a hosts file to resolve a name into an IP address.  This must be done prior to using IP to forward a packet since IP can only use an IP address. Tools, like you mention, and other applications, such as browsers, query a DNS server (requires you have the IP address of a DNS server configured) or use a hosts file to resolve the name to an IP address.

