9 Build a Simple Local Area Network with DHCP

Mathew J. Heath Van Horn, PhD

A Local Area Network (LAN) has many definitions depending on who you speak to.  They can be defined by geography, function, or electrical connections.  In this book, we typically use the term “LAN” to specify a few end devices connected to the same switch.  This is a gross oversimplification of LANs, but simplification is helpful when exploring larger concepts.  Consider how we use logs to represent exponential equations or ask veterans in the audience to stand for recognition. Both actions are simplifications of greater meaning.

In this lab, we show you how to make a fundamental LAN with DHCP that won’t stress your host machine’s resources.

Learning Concepts

  • Create a functional LAN with:
    • 1 switch
    • 2 PCs
    • 1 DHCP server

Prerequisites

Deliverables

  • None – this is a preparatory lab for other labs

resources

Contributors and Testers

  • Jacob M. Christensen, C.I.S. Student, ERAU-Prescott
  • Julian Romano, C.I.S. Student, ERAU-Prescott
  • Cody Shinkyu Park, Honeywell Software Engineer, ERAU-Prescott Alumni
  • Evan Paddock, Cybersecurity Student, ERAU-Prescott
  • Dante Rocca, Cybersecurity Student, ERAU-Prescott
  • Sawyer Hansen, Cybersecurity Student, ERAU-Prescott

Phase I – Inital Setup

Initial setup involves creating a workspace, segmenting that workspace, and then labeling the components.

By the end of the this chapter, your network should look like the following:

GNS3 environment
Figure 1 – Final GNS3 network
  1. Ensure you have completed the prerequisites before starting the lab
  2. Open Oracle VirtualBox Manager
  3. Make a full clone of the TinyCoreLinux VM
    1. Right-click on the machine and select Clone (Figure 2)
    2. Rename it to “TC-red” and select the option to generate new MAC addresses (Figure 3), then click Next
    3. Select Full Clone, then click Finish
  4. Right-click on the TC-red VM and click on settings (Figure 4)
  5. Navigate to “Network” and change the network adapter 1 settings to Generic Driver and UDPTunnel, then click OK (Figure 5)
  6. Start GNS3 and start a new blank project.  Name it anything you like, but for this example, we are calling it Simple LAN
  7. Add the TC-red VM to the GNS3 appliances – Change its symbol to a Red Server
  8. In the GNS3 toolbar ribbon, click on the Draw a Rectangle tool and click the workspace to place a rectangle (Figure 6)
  9. You can use the mouse to resize the rectangle at any time
  10. Change the properties of the rectangle by right-clicking on the edge and selecting Style (Figure 7)
    1. Some people use a fill color and some don’t (Figure 8)
    2. Change the border color to a primary color (we are using red)
    3. Change the Border width to 6 px
    4. Click apply, then click ok
  11. GNS3 uses layers for its graphics.  Generally, the shapes are at a higher layer than the connectors.  This means that anything you put into the box risks not being seen.  So you can change the box’s layer now or at any time by right-clicking on the shape and selecting Lower one layer (Figure 9)
  12. Place the following inside the red rectangle
    1. Ethernet Switch
    2. Two (2) VPCS
    3. TC-red VM
  13. Connect the devices to the switch
  14. Use the note tool – next to the shape tool – to add a new note of “Red Network 192.168.1.0/24”
  15. Use the note tool to add a new note of “.250” next to the TC-Red VM (Figure 10)
  16. Start all devices

Phase II – Configure DHCP on TC-red VM

Tiny Core Linux comes with a DHCP service.  However, we will have to type quite a bit to make it work.  When you are finished with this lab, you may want to use these instructions to create a default TC-DHCP VM that you can clone whenever you need a lightweight DHCP server.

NOTE: Most errors encountered by testers were due to typos.  Be careful and everything should work fine.

  1. Navigate to the TC-Red VM and open a terminal (Figure 11)
  2. Configure the ethernet interface with a static IP address
    1. Open a new configuration file by typing

      > sudo vi /opt/eth0.sh

    2. You will see a lot of tildes (~) which means a blank document
    3. Press i to activate insert, and type the following in the file (Figure 12)

      # fast storage device may need a delay on boot for the settings to take
      # adjust the following sleep statement if needed
      sleep .2

      #kill the dhcp client for eth0
      sleep 1
      if [ -f /var/run/udhcpc.eth0.pid ]; then rm /var/run/udhcpc.eth0.pid;
      sleep 0.1
      fi

      #configure the interface eth0
      ifconfig eth0 192.168.1.250 netmask 255.255.255.0 broadcast 192.168.1.255 up

      #start the DHCP server process once the interface is ready with the IP add
      sleep .1
      sudo udhcpd /etc/udhcpd.conf &

    4. Press esc to exit the edit mode
    5. Press the full colon : followed by wq  (this means write out – old school save file – and quit)

      :wq

    6. Now type in the command line

      > sudo chmod 777 /opt/eth0.sh

    7. Followed by

      > sudo /opt/eth0.sh

    8. You can check if interface eth0 is configured (Figure 13) by typing

      > ifconfig

  3. Create a DHCP configuration file
    1. Type

      > sudo vi /etc/udhcpd.conf

    2. In this new file, press i to insert and type the following

      start 192.168.1.100
      end 192.168.1.200
      interface eth0
      option subnet 255.255.255.0
      option router 192.168.1.250
      option lease 43200
      option dns 192.168.1.250
      option domain local

      NOTE: These settings mean the following

      Statement Setting Meaning
      Start 192.168.1.100 This is the first possible IP address that can be given out to end devices asking for an IP address
      Stop 192.168.1.200 This is the last possible IP address that can be given out to end devices asking for an IP address
      interface eth0 This is the network interface that will be looking for DHCP requests
      option subnet 255.255.255.0 The IPv4 subnet mask used for this network (192.168.1.0)
      option router 192.168.1.250 This is the IP address of the gateway router to leave the local LAN
      option lease 43200 The amount of seconds between lease refresh – this is 12 hours
      option dns 192.168.1.250 DNS should use this gateway router
      option domain local DNS requests will resolve locally first before using the gateway
    3. When finished typing, (Figure 14) press escape followed by

      :wq

    4. Then start the DHCP Daemon by typing

      sudo udhcpd /etc/udhcpd.conf

    5. Verify if the DHCP process is running by typing the following

      sudo netstat -anp

    6. You should see a listening line like this:   udp  0  0  0.0.0.0:67    0.0.0.0:*   1413/udhcpd (Figure 15)
  4. Remember, Tiny Core Linux has limited persistence, so we have to add our DHCP configuration file to the list
    1. Gain change permissions to the bootlocal file by typing

      sudo chown root:staff /opt/bootlocal.sh
      sudo chmod 775 /opt/bootlocal.sh

    2. Now add the persistence by typing the following

      sudo echo ‘etc/udhcpd.conf’ >> /opt/.filetool.lst
      sudo echo ‘opt/eth0.sh’ >> /opt/.filetool.lst
      sudo echo ‘opt/eth0.sh &’ >> /opt/bootlocal.sh
      filetool.sh -b

    3. You should get a confirmation like in (Figure 16)
    4. Now reboot TC-red to verify the settings were retained by typing the following at the command line
      1. Static IP is configured (Figure 13)

        ifconfig

      2. DHCP server is running (Figure 15)

        sudo netstat -anp

Phase III – Verify hosts are getting IP addresses

We can never be certain that our VPCS are getting IP addresses until we try it.

  1. Navigate to the GNS3 workspace
  2. Right-click on a VPCS console and type

    ip dhcp

  3. You should get a response of an IP address between 192.168.1.100 – 192.168.1.200 (Figure 17)
  4. Note the IP address and use the GNS3 note tool to add the IP address to the Workspace (Figure 18)

NOTE: Most errors encountered by testers were due to typos.  Be careful and everything should work fine.

Final Note – you can change the DHCP configuration any time by modifying IP addresses.  For instance if our network was 20.20.0.0/16 and we knew our gateway router was 20.20.20.254, we would change are settings to the following:

Purpose Lab IP Address Possible Modification
Network ID 192.168.1.0 20.20.0.0
subnet mask 255.255.255.0 255.255.0.0
Static IP (this DHCP Server) 192.168.1.250 20.20.20.1
Option Router (gateway or next-hop) 192.168.1.250 20.20.20.254
start – the first available IP address for DHCP 192.168.1.100 20.20.20.50
stop – the last available IP address for DHCP 192.168.1.200 20.20.20.99
Option DNS (the gateway if DNS cannot be resolved locally) 192.168.1.250 20.20.20.254
lease time (in seconds) 43200 ( =12 hours) 21600 (= 6 hours)
End of Lab
List of Figures for Print Copy
Picture of commands
Figure 2 – Cloning a VM

 

Picture of commands
Figure 3 – Renaming and resetting MACs

 

Picture of commands
Figure 4 – Adjust settings for TC-Red

 

Picture of commands
Figure 5 – Adjust NIC to generic

 

Picture of commands
Figure 6 – Drawing a rectangle

 

Picture of commands
Figure 7 – Changing rectangle style

 

Picture of commands
Figure 8 – Changing rectangle color
Picture of commands
Figure 9 – Send rectangle back a layer

 

Picture of commands
Figure 10 – Add a note

 

Picture of commands
Figure 11 – Open a terminal

 

Picture of commands
Figure 12 – Create a settings file for the NIC

 

Picture of commands
Figure 13 – Verify the NIC configurations are correct

 

Picture of commands
Figure 14 – Configure DHCP

 

Picture of commands
Figure 15 – Perform a netstat check

 

Picture of commands
Figure 16 – Add persistance

 

Picture of commands
Figure 17 – Ensure devices are getting DHCP

 

Picture of commands
Figure 18 – Add a note to the workspace

 

 

License

Icon for the Creative Commons Attribution 4.0 International License

Mastering Enterprise Networks Copyright © 2024 by Mathew J. Heath Van Horn, PhD is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book