Practice Exercise: Network Addresses and DNS
Objective
Explore network addresses, DNS (Domain Name System), and related commands in Linux.
Task 1: Understanding IP Addresses
- Open a terminal window.
- Use the
ifconfig
orip addr
command to display the IP addresses assigned to your network interfaces. - Identify your system's IP address, subnet mask, and gateway address.
[intern@intern-a1t-inf-lnx1 ~]$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether f2:d0:95:0d:20:04 brd ff:ff:ff:ff:ff:ff inet 192.168.64.2/24 metric 100 brd 192.168.64.255 scope global dynamic enp0s1 valid_lft 52945sec preferred_lft 52945sec inet6 fd76:221f:c594:440:f0d0:95ff:fe0d:2004/64 scope global dynamic mngtmpaddr noprefixroute valid_lft 2591977sec preferred_lft 604777sec inet6 fe80::f0d0:95ff:fe0d:2004/64 scope link valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:d8:29:4d:a9 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever
Task 2: Resolving Domain Names with nslookup
- Run the
nslookup
command followed by a domain name (e.g.,nslookup www.example.com
). - Observe how
nslookup
provides the IP address associated with the given domain name. - Try resolving the IP address of different domain names.
[intern@intern-a1t-inf-lnx1 ~]$ nslookup www.example.com Server: 17.7.7.7 Address: 17.7.7.7#53 Non-authoritative answer: Name: www.example.com Address: 93.184.216.34 [intern@intern-a1t-inf-lnx1 ~]$ nslookup 8.8.8.8 Server: 17.7.7.7 Address: 17.7.7.7#53 Non-authoritative answer: 8.8.8.8.in-addr.arpa name = dns.google. Authoritative answers can be found from:
Task 3: Checking DNS Resolution with ping
- Use the
ping
command followed by a domain name (e.g.,ping www.google.com
). - Confirm that you can reach the domain's IP address and receive responses.
- Experiment with different domain names and observe the responses.
[intern@intern-a1t-inf-lnx1 ~]$ ping www.google.com PING www.google.com (142.250.189.228): 56 data bytes 64 bytes from 142.250.189.228: icmp_seq=0 ttl=118 time=238.259 ms 64 bytes from 142.250.189.228: icmp_seq=1 ttl=118 time=359.562 ms 64 bytes from 142.250.189.228: icmp_seq=2 ttl=118 time=381.336 ms ^C --- www.google.com ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 238.259/326.386/381.336/62.946 ms
Task 4: Editing the Hosts File
- Open the
/etc/hosts
file in a text editor with administrative privileges (e.g.,sudo nano /etc/hosts
). - Add an entry that maps a custom hostname to a specific IP address.
- Save the file and exit.
- Test DNS resolution for the custom hostname using
ping
.[intern@intern-a1t-inf-lnx1 ~]$ sudo vim /etc/hosts Password: ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost [intern@intern-a1t-inf-lnx1 ~]$ echo "170.187.198.132 itsm" | sudo tee -a /etc/hosts 170.187.198.132 itsm [intern@intern-a1t-inf-lnx1 ~]$ cat /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 170.187.198.132 itsm [intern@intern-a1t-inf-lnx1 ~]$ ping itsm PING itsm (170.187.198.132): 56 data bytes 64 bytes from 170.187.198.132: icmp_seq=0 ttl=51 time=663.426 ms 64 bytes from 170.187.198.132: icmp_seq=1 ttl=51 time=394.493 ms 64 bytes from 170.187.198.132: icmp_seq=2 ttl=51 time=525.758 ms ^C --- itsm ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 394.493/527.892/663.426/109.802 ms
Task 5: Configuring DNS Servers
- Open the
/etc/resolv.conf
file in a text editor with administrative privileges. - Add DNS server IP addresses using the
nameserver
directive (e.g.,nameserver 8.8.8.8
). - Save the file and exit.
- Use
nslookup
to resolve domain names with the newly configured DNS servers.[intern@intern-a1t-inf-lnx1 ~]$ cat /etc/resolv.conf # This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8). # Do not edit. # # This file might be symlinked as /etc/resolv.conf. If you're looking at # /etc/resolv.conf and seeing this text, you have followed the symlink. # # This is a dynamic resolv.conf file for connecting local clients to the # internal DNS stub resolver of systemd-resolved. This file lists all # configured search domains. # # Run "resolvectl status" to see details about the uplink DNS servers # currently in use. # # Third party programs should typically not access this file directly, but only # through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a # different way, replace this symlink by a static file or a different symlink. # # See man:systemd-resolved.service(8) for details about the supported modes of # operation for /etc/resolv.conf. nameserver 127.0.0.53 options edns0 trust-ad search . [intern@intern-a1t-inf-lnx1 ~]$ cat /etc/resolv.conf ..... nameserver 8.8.8.8 nameserver 127.0.0.53 options edns0 trust-ad search . ..... [intern@intern-a1t-inf-lnx1 ~]$ nslookup www.example.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: www.example.com Address: 93.184.216.34 Name: www.example.com Address: 2606:2800:220:1:248:1893:25c8:1946
Task 6: Investigating Domain Ownership with dig
- Run the
dig
command followed by a domain name (e.g.,dig example.com
). - Examine the information provided, including domain registrar and contact details.
- Try
dig
with different domain names.[intern@intern-a1t-inf-lnx1 ~]$ dig www.example.com ; <<>> DiG 9.11.36-RedHat-9.11.36-9.el8 <<>> www.example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38255 ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;www.example.com. IN A ;; ANSWER SECTION: www.example.com. 82031 IN A 93.184.216.34 ;; Query time: 168 msec ;; SERVER: 139.162.10.8#53(139.162.10.8) ;; WHEN: Tue Oct 03 05:57:43 UTC 2023 ;; MSG SIZE rcvd: 60 [intern@intern-a1t-inf-lnx1 ~]$ dig www.google.com ; <<>> DiG 9.11.36-RedHat-9.11.36-9.el8 <<>> www.google.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25799 ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 213 IN A 142.250.4.104 www.google.com. 213 IN A 142.250.4.105 www.google.com. 213 IN A 142.250.4.103 www.google.com. 213 IN A 142.250.4.147 www.google.com. 213 IN A 142.250.4.99 www.google.com. 213 IN A 142.250.4.106 ;; Query time: 0 msec ;; SERVER: 139.162.10.8#53(139.162.10.8) ;; WHEN: Tue Oct 03 05:58:01 UTC 2023 ;; MSG SIZE rcvd: 139
Conclusion
In this lab exercise, you've explored network addresses, DNS resolution, and related commands in Linux. You've learned how to view your system's IP configuration, resolve domain names to IP addresses using nslookup
, verify DNS resolution with ping
, manually map hostnames to IP addresses in the /etc/hosts
file, configure DNS servers, and investigate domain ownership using dig
. Understanding these network operations is crucial for effective Linux system administration.