Skip to content

Lab02: The Application Layer Part 1 -- Web Servers and DNS

Learning Goals

Goals for this week's lab

  • Create a basic network topology in GNS3
  • Use the command line interface to perform basic network-related tasks such as setting IP addresses and testing connectivity between hosts
  • Run web and DNS servers to learn about
    • Hypertext Transfer Protocol (HTTP)
    • Ports, layers, and packets
    • Network & service configuration as well as address resolution

In this lab, you will first get familiar with the GNS3 network emulator that we will use for most labs in this course and then dive into the specific application layer principles and protocols you read about in Chapter 2 of the book.


Launching GNS3 and Creating a Basic Network

In today's lab, we're going to use the GNS3 network emulator which you installed to your computers the previous week. This tool allows us to easily and visually create networks whose components we can configure by accessing their respective command line interface. Start by connecting to your VMs by using the ssh ntnu_server command. Then launch the GNS3 program from the desktop and create a new empty project.



You can add various devices like network switches and hosts, as well as links between them from the menus on the left. After adding the devices, you can control their state using the controls at the top as outlined in the figure.



Try to create a minimal topology that consists of two dierctly connected hosts by dragging instances of the ubuntu-host onto the main panel, and then interconnecting their eth0 interfaces by consecutively clicking on the Add a link button and the two hosts. The result should look as follows.



By starting all devices using the green button at the top, the respective containers are launched. Once they are running, you can access their terminal by double-clicking the respective device in the topology.

Tip

If you close the terminal of a container, the container itself will turn off and you will have to turn it back on by right-clicking the device and pressing start.

Beware

Containers are stateless by design, so restarting the container will also lead to a complete loss of any files and configuration changes on it.


Networking with Two Computers

The main goal of this exercise is to get familiar with basic network configuration commands using the simple two-host network topology we created earlier.

Note

We will learn more about IP addresses and subnets in Chapter 4, hence the commands related to these are provided in this exercise.

Configuring the Network Interfaces

On ubuntu-host-1

Perform the following steps to set the IP address of the eth0 interface to 10.0.0.1.

  1. Remove any unwanted address or routes on eth0 with the command ip addr flush dev eth0.
  2. Add an IP address and respective mask to the interface eth0 using the command ip addr add 10.0.0.1/24 dev eth0.
  3. Use the command ip addr show eth0 to verify that your IP address has been successfully set.
  4. Use the command ip link set up dev eth0 to “turn on” the interface, in case it is down.
On ubuntu-host-2

Repeat the configuration steps from ubuntu-host-1, setting its IP address to 10.0.0.2.

Remember: You need to have “root” (administrator) privileges in order to change/add an IP address. For the containers in the GNS3 environment, this is always the case as indicated by the command prompt starting with the # sign as opposed to the $ sign you see for instance as the netlab user on the host VM.

Verifying Your Configuration

After configuring the two hosts, continue with the following steps.

  1. Verify that both nodes have connectivity with the ping command. First, by ping-ing ubuntu-host-2’s IP address from ubuntu-host-1 and afterwards ubuntu-host-1’s IP address from ubuntu-host-2.
Tip

The basic syntax of the ping command is ping <destination_ip_address>, e.g., ping 10.0.0.2. The output contains per-packet statistics if there is a route to the target network and the target address can be reached or an error message otherwise. You can use Ctrl+C to stop sending packets.

  1. You can also capture packets that traverse your network using the Wireshark tool we’ve seen during the lecture. To do so, right-click the link, hit “start capture”, make sure that “Start the capture visualization program” is checked, and confirm with “OK”.

Lab Exercises

Please read each exercise entirely before starting to solve it.

Remember: Your report should include the main commands and configurations necessary to complete each exercise. Do not forget to take notes while solving the exercises so you do not have to repeat them.


A) Web Server, Ports, HTTP

Initializing the Environment

We will use the two-host topology defined in the introduction, using one host as client and one as server. Before you continue, make sure that the two hosts can reach each other by using ping.

Running a Web Server

  1. As mentioned before, one host will take the role of the client and one that of the server. On the server (ubuntu-host-2 with IP 10.0.0.2), navigate to the /var/www folder and inspect its contents.

  2. You can run a simple Python-based HTTP server in your current working directory by issuing the command python3 -m http.server 80. This will instruct python to run the http.server module with 80 as its first argument, indicating which port the HTTP server should listen to. 80 is the standard port number for HTTP. You can learn more about commonly used port numbers here.

Tip

You can use the combination Ctrl-C to stop the server application and regain control of the console.

Interacting with the Web Server

  1. With the server application running, we can access the content it serves. Instead of using a browser, we can use command line tools like curl to connect to the server and download HTML pages or other files that are offered.

  2. From the host (ubuntu-host-1 if you're following the same naming and addressing scheme), try curl 10.0.0.2 (which is shorter but equivalent to curl http://10.0.0.2/, more clearly showing the underlying HTTP request process that curl performs; similar to how a browser would automatically prepend http:// to the URL when you type it into the address bar). Observe the output and relate it to the content you saw in step 1. Investigate how you can download the file example.html.

  3. On ubuntu-host-2, stop the server application, rename example.html to index.html, and restart the server application. Re-run the curl commands from the client from the previous step and discuss the differences in the output. What happens if you try requesting a page that does not exist?

Capturing HTTP Traffic

  1. Following the instructions from the introduction, start a traffic capture on the link between the client and the server.

  2. With Wireshark open, run the previous curl commands again and discuss the HTTP traffic that appears.

    • What kind of information is exchanged between client and server in the HTTP messages in each direction? You can read about HTTP request methods, HTTP status codes, and HTTP request headers for more information.
    • Click on an HTTP packet and check the detailed view in the lower half of the Wireshark window. Taking a look at these details, what can you tell about the protocol stack that is used here? Refer back to chapter 1.5.1 in the book and map the protocols you find to the different layers.
    • Compare how the traffic changes when you request example.html and lipsum.txt. What could be the reason?
Hint

Compare the size of the two files and recall what we discussed about packets.

Changing Ports

  1. Going back to the server, stop the application and re-run it using a different port. For instance, python3 -m http.server 8000. How does this change the output at the client trying to curl? Find out how to point curl to a specific port, e.g., by consulting its manual.

B) DNS

Import and Topology

Before starting, you have to download the GNS3 project with the topology for the lab. Take note of the location you save it to.

For today's lab, we're going to use a project that comes with several pre-configured components. To get started and make sure that changes are applied within GNS3, close any running instances of GNS3 and launch it again.

Upon launching GNS3, you will be prompted to create a new project. You can close this window, as we are going to import our own project. To import the project, navigate to the File tab in the upper left corner and select Import portable project in the dropdown menu.



Navigate to the location in the file system where you saved the project you just downloaded, and open it.

You will be presented with a network topology that consists of three routers (R1-R3), a switch, and three hosts, corresponding to a client, a DNS server, and a (web) server. A schematic overview of the network topology is provided in the graphic below. The graphic shows network interface names alongside their configured IP addresses, their interconnections, and uses the same colors to highlight interfaces that are on the same subnet.



Note

We will use this topology in a future lab exercise about routing and learn the details about the functionality of switches vs routers and their roles in packet delivery. For the present exercise, the main point is that the DNS server, client, and web server can reach each other with their respective IP address.

DNS Server and Client-Side Nameserver Settings

To get started with this step, let the server machine run its web server in the usual way.

root@server:/# cd /var/www/
root@server:/var/www# python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...

From the client, confirm that you can download the web site from the server with curl 10.168.1.2.

Our goal for this part is to use DNS to enable the client to reach the server through the more human-readable address ttm4175.com rather than its IP address.

Open a console on the dns host and navigate to /etc/bind. This is the home of configuration files related to the BIND 9 DNS server that runs on this host.

  1. Inspect the file named.conf.local. The zone defines the portion of the namespace for which this machine is responsible. Inside the zone definition, file points to the file that contains the actual DNS records for the zone. Use the BIND 9 documentation or any other source to find the meaning of the type master part of the configuration.

  2. Take a look at the file that is referenced in the above configuration. Go through the file and discuss the broad meaning of the various entries. Feel free to consult online resources.

  3. You can make DNS requests from the client to the DNS server by invoking the nslookup utility that we used in the past. Issue the commands nslookup ttm4175.com, nslookup ttm4175.com 10.240.1.2, and curl ttm4175.com at the client. Explain the different outputs you get.

  4. Back in GNS3, start a capture on the link between the client and the switch. Re-run nslookup ttm4175.com 10.240.1.2 and discuss the DNS packets you see. What transport protocol does DNS use, and what types of queries and responses do you see? How many of each are being sent?

  5. To add our DNS server as the default nameserver for the client, open a console on the client and use a text editor such as nano to add the following line to /etc/resolv.conf:

nameserver 10.240.1.2
  1. Run nslookup ttm4175.com and curl ttm4175.com again and document what happens.

  2. Suppose the DNS server becomes unreachable, but the web server is still reachable over the network, and you already know the server's IP address from earlier in the exercise. Would curl ttm4175.com still succeed? Would curl 10.168.1.2 still succeed? Explain the difference, and what it tells you about how DNS relates to the underlying IP routing you configured earlier in the lab.

End-to-End Scenario

  1. For your report, describe what happens in the network when you download the page "ttm4175.com" (e.g., when you use curl ttm4175.com). You can explain, step by step, the requests and answers from the client to the server and back. This should include the IP addresses, protocols, and involved devices / services. You can also provide screenshots to illustrate and highlight your explanations.