IP addresses & DNS

Computer Science · Networking

Question 1 of 10

0

    Which protocol does the ping command use to send echo requests?

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    IP addresses & DNS explained

    An IP address is a number that identifies a device on a network, and the Domain Name System (DNS) turns easy-to-remember names, such as example.com, into those numbers. Together they let your device find the computer that hosts a website when you type its name.

    IPv4 addresses are written as four numbers from 0 to 255 separated by full stops, such as 192.168.1.10. Each number takes 8 bits, so an IPv4 address is 32 bits long. That allows about 4.3 billion addresses, which is not enough for every device, so IPv6 was introduced with 128-bit addresses written in hexadecimal groups.

    Addresses beginning 192.168 are private and are used inside many home networks. A router connects the private network to the internet and uses its own public address when talking to the outside world.

    DNS is a distributed system of servers. When you type www.example.com, your device asks a DNS server for the matching IP address, then connects to that address. Answers are stored in caches so that repeat lookups are faster.

    A common mistake is to think a domain name identifies a single computer. One domain can point to several IP addresses, and one IP address can host many websites.

    Worked example

    Convert the first number of 192.168.1.10, which is 192, into 8-bit binary, then find how many IPv4 addresses are possible.

    1. 192 = 128 + 64, so in 8 bits it is 11000000.
    2. An IPv4 address has four numbers of 8 bits each, so it is 4×8=324 \times 8 = 32 bits long.
    3. The number of possible addresses is 232=42949672962^{32} = 4294967296.

    Key facts

    • The practice questions cover IPv4 and IPv6, public and private addresses, DHCP, NAT, subnet masks, and DNS records (A, CNAME, PTR) with TTL values.
    • A subnet mask shows which bits of an address identify the network and which identify the host. The mask 255.255.255.0 has 24 ones followed by 8 zeros, written /24.
    • If there are hh host bits, there are 2h2^h addresses in the subnet. The first (all host bits 0) is the network address and the last (all host bits 1) is the broadcast address. Neither can be given to a device, so there are 2h−22^h - 2 usable addresses.
    • To find the network address, write the address and the mask in binary and AND them: a result bit is 1 only if both bits are 1.
    • DHCP gives a device its IP address automatically. NAT lets many private addresses share one public address.

    Worked example 2

    A device has the address 192.168.1.10 and the mask 255.255.255.0. Find the network address, the broadcast address and the number of usable host addresses.

    1. The mask has 24 network bits, so 32−24=832 - 24 = 8 host bits.
    2. The first three numbers are all covered by 255, so they stay the same. The last number: 10 is 00001010 and 0 is 00000000. ANDing gives 00000000, which is 0.
    3. Network address: 192.168.1.0.
    4. Broadcast address: set all 8 host bits to 1, which gives 255. So 192.168.1.255.
    5. Total addresses: 28=2562^8 = 256. Usable: 256−2=254256 - 2 = 254.

    Worked example 3

    A device has the address 192.168.1.130 and the mask 255.255.255.192. Find the network address, the broadcast address and the number of usable hosts.

    1. Write the last number of the mask in binary: 192=128+64192 = 128 + 64, so it is 11000000. That is 2 bits, so the mask has 24+2=2624 + 2 = 26 network bits (/26) and 32−26=632 - 26 = 6 host bits.
    2. The last number of the address: 130=128+2130 = 128 + 2, so it is 10000010.
    3. AND with 11000000 gives 10000000, which is 128. Network address: 192.168.1.128.
    4. Set the 6 host bits to 1: 10111111 is 128+63=191128 + 63 = 191. Broadcast address: 192.168.1.191.
    5. Total addresses: 26=642^6 = 64. Usable: 64−2=6264 - 2 = 62.
    6. Usable range: 192.168.1.129 to 192.168.1.190.

    Worked example 4

    A website changes its A record to a new IP address at 12:00:00. The record has a TTL of 300 seconds. A resolver cached the old record at 11:58:00. Until what time can users of that resolver still be sent to the old server, and for how long after the change?

    1. The TTL tells a resolver how long it may keep a cached record. The resolver cached the record 120 seconds before the change (11:58:0011{:}58{:}00 to 12:00:0012{:}00{:}00 is 2 minutes).
    2. The record expires at 11:58:00+300 s=12:03:0011{:}58{:}00 + 300\text{ s} = 12{:}03{:}00.
    3. Time left after the change: 300−120=180300 - 120 = 180 s, which is 3 minutes.
    4. Until 12:03:00 the resolver may keep returning the old IP address. After that it asks again and gets the new one.

    This is why people lower a TTL before moving a site: shorter caches mean a faster switch. Different resolvers cached at different times, so users see the change at different moments.

    Common mistakes

    • Giving the number of usable hosts as 2h2^h. Remember to take away the network and broadcast addresses.
    • Counting the mask bits wrongly. 255 is 8 ones, 192 is 2 ones and 6 zeros.
    • Mixing up the network bits (fixed) and the host bits (change between devices).
    • Thinking a domain name is one computer. A domain can have several IP addresses.
    • Saying DNS delivers the web page. It only gives the address.
    • Forgetting that a CNAME points to another name, not to an IP address.

    Exam tips

    • Always convert the interesting number to 8-bit binary and show it. The AND step is where the marks are.
    • Check: the network address must have all host bits 0 and the broadcast all 1.
    • For subnet size, write 2h2^h first, then subtract 2.
    • For DNS caching questions, quote the TTL and say that the old record stays until the TTL runs out.
    • Mention private ranges such as 192.168.x.x only when they are relevant, and say NAT is what connects them to the internet.

    What you will practise

    100 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • An IP address:
    • IPv4 uses:
    • DNS converts:
    • IPv6 was created because:
    • A DNS resolver:
    • How many bits does an IPv6 address contain?
    • Which IPv4 address is the loopback address used to refer to the local machine?
    • What does a DNS A record store?

    …and 92 more.