Hostname-to-Address Mapping
Converting between hostnames and IP addresses is the most common use for DNS. DNS can perform forward lookups or reverse lookups. A forward lookup converts a hostname to an IP address. A reverse lookup identifies the hostnames associated with an IP address.
Software Development
When programming, there are four main functions used to perform DNS resolutions. These are provided by the resolver library and perform the actual hostname lookups. The resolver library may access a local hosts file, such as C:\Windows\System32\ Drivers\Etc\Hosts or /etc/hosts, DNS, LDAP, NIS, or other name resolution system. The calling program has no option to specify the name resolution method.
sethostent: This function initializes the DNS library. In some implementations, this function takes a Boolean parameter to indicate whether TCP or UDP should be used for the connection. This is the case for Linux and BSD. Other operating systems do not require sethostent or simply ignore any passed parameters. In general, sethostent should be called before performing any hostname lookups.
gethostbyname: This function performs a forward lookup. Given a hostname, it returns the network address(es) associated with the hostname.
gethostbyaddr: This function performs a reverse lookup. Given a network address, it returns the hostname (and aliases) associated with the address.
endhostent: After performing a hostname lookup, this closes the library call. If sethostent specifies a TCP connection, then this function closes the connection. Also, if a host's file was used for the hostname lookup, then this call closes the file.
DNS (and other name resolution systems) provides a many-to-many mapping between hostnames and addresses. A single IP address may match a variety of hostnames, and a single hostname may map to a set of network addresses. The data structure returned by gethostbyname and gethostbyaddr provides a list of matches. In addition, hostname mapping may not be symmetrical. For example, the hostname chutney may resolve to 10.1.3.5, but a reverse lookup of 10.1.3.5 may not return chutney. This is common for servers that host many domain names.
In this tutorial:
- Domain Name System (DNS)
- DNS Common Uses
- Hostname-to-Address Mapping
- Common Lookup Tools
- Naming Confusion Attack Vectors
- Dotted Names
- Name Formatting
- Exploited Anonymity
- Mail Servers
- Sender Policy Framework Overloading
- Domain Keys Overloading
- DNS Protocol
- Packet Information
- Simple DNS Server
- Distributed Architecture
- Top Level Domain Servers
- Generic Top Level Domain (gTLD)
- Secondary Level Domain (SLD)
- Primary and Secondary Servers
- Caching Servers
- DNS Management
- DNS Direct Risks
- DNS Performance versus Security
- DNS Cache Poisoning
- Corrupt DNS Packets
- DNS Domain Hijacking
- DNS Server Hijacking
- Dynamic DNS
- Similar Hostnames
- Domain Renewals
- Hostnames
- Zone Transfers
- Host Listing
- DNS Fields
- Mitgation Option
- Technical Threat Mitigation
- Social Threat Mitigation
- Defining Trusted Replies