Topic 4.1
IP Addresses, Interfaces & DNS
In one line
Every machine on a network has an address, every request to a domain name gets resolved to one of those addresses first, and a handful of commands let you inspect both directly from the terminal.
Think of it like this
An IP address is like a house's street address — a precise, numeric location. A domain name (google.com) is like a business's NAME — memorable for humans, but ultimately just a lookup that resolves to the actual street address (IP) before anything can actually be delivered there.
Key ideas
- 01
ip addr(the modern command,ifconfigbeing the older, now-deprecated equivalent) shows every network INTERFACE on the machine and its assigned IP address(es) —lois always the loopback interface (127.0.0.1, the machine talking to itself), and interfaces likeeth0orens5represent real physical or virtual network connections. - 02
A PRIVATE IP address (typically starting with
10.,172.16.–172.31., or192.168.) is only reachable within its own local network — this is exactly the range Docker's own networking topics used for containers on a bridge network. A PUBLIC IP is reachable from the wider internet, and a server usually has one specifically to be reachable at all from outside. - 03
DNS (Domain Name System) is the internet's phone book — it translates a domain name into an IP address.
nslookup <domain>or the more moderndig <domain>both perform this lookup directly and show you the result, along with genuinely useful metadata like which DNS server answered and how long the record is cached for (its TTL). - 04
/etc/hostsis a plain text file that lets you MANUALLY map a hostname to an IP address, bypassing DNS entirely for that specific name — genuinely useful for local development (pointingmyapp.localat127.0.0.1) or testing how your app behaves against a specific IP before a real DNS change propagates. - 05
ping <host>sends a small network packet and waits for a reply, measuring round-trip time — the classic, simplest first check for 'is this host even reachable at all,' though some servers are deliberately configured to not respond to ping for security reasons, so a lack of response doesn't always mean the host is actually down.
Code & diagrams
A connection string's hostname never touches the network directly — it's resolved to an IP first, every time.
All read-only, safe to run anywhere with a network connection.
# See your machine's network interfaces and IP addresses
ip addr
# Resolve a domain name to an IP address
dig google.com +short
# or, if dig isn't installed:
nslookup google.com
# Check reachability (Ctrl+C to stop)
ping -c 4 google.com
# See your own manual hostname overrides
cat /etc/hosts
# Check your machine's own public IP (via an external service)
curl -s ifconfig.meExplain it without notes
Why does a request to a domain name usually involve a DNS lookup before any actual data can be sent?
What's the practical difference between a private IP address and a public one?
Practice
Run ip addr on your own machine and identify which interface has your actual working IP address versus the loopback interface.
Use dig (or nslookup) to resolve two or three different domain names and compare the IP addresses each one returns.
Trade-offs
- ↔
DNS lookups add a small amount of latency to every first connection to a new host (cached afterward per the TTL) — for latency-critical internal service-to-service communication, some systems bypass DNS lookups per-request by connecting to a cached IP or using a service mesh, trading DNS's flexibility (changing where a name points without redeploying anything) for raw speed.
Done when you can
I can find my machine's own IP addresses with ip addr.
I understand the difference between a private IP and a public IP.
I can use dig or nslookup to resolve a domain name manually.