CSIS 4222 Computer Networking Lab 3 – IP Addresses and DHCP

5 downloads 121 Views 440KB Size Report
In this exercise you will set up a DHCP server and examine its interaction with clients ... All of the lab computers have been configured to use DHCP to get an IP  ...
CSIS 4222 Computer Networking Lab 3 – IP Addresses and DHCP Copyright © 2000-2002 by John F. Cigas Last modified for Stockton College by Michael Olan (February 2011)

Purpose In this exercise you will set up a DHCP server and examine its interaction with clients on a shared network. You will implement a single IP network with multiple servers, and also look at implementing different IP networks on the same physical network and the problems that creates. There are things that will behave strangely in this exercise - keep an eye out for them!

Reference 

man pages for dhcpd, dhcpd.conf, dhcpd.leases

Background In the previous exercises, all the computers in the lab were treated the same. Today, we start distinguishing between client computers and server computers. We will start to treat the lab as a bunch of little networks, each with one server and several clients. You will be doing some tasks only on a server and other tasks only on the clients. It will be necessary to work in groups of 3 or 4 to complete today's lab. There may be times that the network interface will need to be restarted. Switching a NIC on and off is done by entering these commands as root: ifconfig eth0 up ifconfig eth0 down ifconfig eth0  reports the status of interface eth0 All of the Ubuntu installations in the lab include a DHCP server. Check to see if it is running with this command: ps aux | grep dhcpd The ps command lists running processes. Since the list can be rather long, grep is used to just show lines that contain dhcpd. If the server is running, you will see a line that describes this.

1. Record DHCP behavior for reference Before we start changing IP addresses and creating all kinds of confusion, we'll get a record for posterity of how DHCP works when it is working correctly.     

On one client computer, stop the network interface. On another client, start capturing packets with Wireshark. On the first client, start the network interface again. On the first client, make sure you can ping another computer On the second client, stop capturing.

Be sure that you can identify the DHCP traffic from the client. The bootp filter will show only DHCP packets, but you might still see packets from other clients in the lab. One way to be sure you see the right ones is to also filter on the unique MAC address of the client’s interface (substitute the last two pairs of MAC address digits for xx:yy – these will most likely be unique in the lab so that the entire MAC won’t have to be used): bootp and eth.addr[4:]==xx:yy There should be 2 DHCP related packets for renewing the IP address on the client (or possibly 4 if it gets a new address). You might need to use the command dhclient eth0 on the clients to request an IP address from the DHCP server. Save this packet trace to a file, named dhcpgood. You'll be able to reload this file into Wireshark to review this behavior if necessary.

2a. Prepare the clients If the DHCP server is running, shut it down with the following command as root: /etc/init.d/dhcp3-server stop All of the lab computers have been configured to use DHCP to get an IP address, so the clients are ready to go. For your information, use System  Preferences  Network Connections and edit the Wired entry. In the IPv4 Settings tab note that the Method is set to Automatic (DHCP). Leave it like this and exit from the configuration tool.

2b. Prepare the server From now on, we’ll be using private IP networks. Today, each group will configure a subnet of the 192.168.1.0/24 network. The servers will have static IP address on the network that they are serving. We’ll need 5 networks, which requires adding 3 additional bits to the network numbers (this would support 8 subnets but we’ll only use 5). Each group should select their server’s IP address from the table: Server IP Host range Since this IP address will have to be different from all other DHCP servers in the lab, write your server's IP address on the board so that other groups will know that this address is in use.

192.168.1.1

2 — 30

192.168.1.33

34 — 62

192.168.1.65

66 — 94

192.168.1.97

98 — 126

192.168.1.129

130 — 158

To configure the IP address, as root, edit the file /etc/network/interfaces. Add the following lines (substitute the IP address selected above on the third line): auto eth0 iface eth0 inet static address 192.168.1.X netmask 255.255.255.224

The first line says to start the eth0 interface automatically. The second line says that it will have a static Internet address. The third line is the IP address. The fourth line is used to separate the network address from the host address. Run the following command as root to restart networking with the new configuration. /etc/init.d/networking restart Check that eth0 has the correct IP address. Then make sure that you can ping at least one other server in the room and another server can ping you.

3. Configure a DHCP server Remember you will only configure a DHCP server (dhcpd) on your server computer, not on the clients. Getting a DHCP server working involves four steps: 1) Create a configuration file which tells the server how to behave. 2) Create a file for storing lease information. 3) Start the server. 4) Enable the server to be started automatically whenever the computer is booted. (Do this after everything is working.) All of this was done during installation of the DHCP package except for some specific settings in a configuration file. The most basic way to do this is by editing the file /etc/dhcp3/dhcpd.conf. To be safe, make a backup copy of this file before making any changes. About 40 lines down will be a very basic sample subnet declaration that was created during installation. Remove the comment markers on each line and edit it to look like this (replace X with the number used in the server’s IP address minus 1, i.e. 0, 32, 64, 96, 128. Replace Y1 and Y2 with the values from the Host Range from the table on the previous page.): subnet 192.168.1.X netmask 255.255.255.224 { range 192.168.1.Y1 192.168.1.Y2; } After saving the file, have the changes take effect by starting/restarting the DHCP server as root with the command /etc/init.d/dhcp3-server restart If the server fails to start because of errors in the configuration file, correct them and try

4. Monitor your server Use Wireshark on your server and on a client to watch the network traffic. Have a client computer request an IP address by running the command dhclient eth0 Note where it get offers for IP addresses and if it now get their IP addresses from your server. Repeat this for all the clients and keep track of which ones get their addresses from which servers. Can you see any pattern? If none of your clients get a new IP address, try deleting the file /var/lib/dhcp3/dhclient.leases on the clients and then repeat the steps above. (Even if they all do, delete the file on at least one of the clients.) Check the /var/lib/dhcp3/dhcpd.leases file on your server to see which IP addresses it has given out.

5. Serve your own clients It is entirely possible that your DHCP server won’t have given out any IP addresses yet. The current configuration of DHCP servers leaves all policy decisions to chance. Next we’ll configure the server to specifically respond to your own clients by listing their MAC addresses and fixed IP addresses. First make another backup copy of dhcpd.conf just in case something goes wrong and you need to get back to where you were before. The format for the new entries in the dhcpd.conf file is: host client1 { hardware ethernet aa:bb:cc:dd:ee:ff; fixed-address 192.168.1.X; } where client1 is the name to associate with the host, aa:...:ff is the MAC address, y is the same number as before, and X is a value in the host range for your subnet. Use the command hostname on the clients to find their names. You’ll need to save the file and restart your DHCP server for the change to take effect. Make sure that each of your clients can get a fixed IP address from your server. But your clients may still get their IP address from another server. If so, check the manual pages for dhclient.conf and look at the sample near the end for a way to prevent this.) Make sure the clients can ping at each other and the server. Also try to ping computers outside your immediate network. This kind of network arrangement can be a little unstable. It is definitely not the way one would configure a network in practice and next time we’ll do it the right way.