Using Linux

From Daelphinux
Jump to: navigation, search

Introduction

The Linux operating system is one of the most widely used operating systems today. Although it may seem like there are more Windows computers or Macs based on a perusal of your local Starbucks, almost all servers run on Linux. In fact, we need one of those very servers in our homelab! In this tutorial we will cover building a simple infrastructure machine, and installing and configuring a Network control service (DHCP). This is a long one. Feel free to take breaks after each major step in the process.

Objectives

After this tutorial, you should be able to:

  • Apply knowledge from previous tutorials by installing Ubuntu Server in a newly configured VM
  • Update the Ubuntu Server OS
  • Install the DHCP Server package
  • Discuss Linux Package Management
  • Explain the purpose of some simple Linux Commands
  • Set up a Virtualbox Internal Network
  • Add a Network Interface to a virtual machine

Pre-Requisites

Tutorials

At this point, you will need to have completed the Configuring a Virtual Machine and Installing an Operating System Tutorials. These skills will be tested during this tutorial.

Requirements

Software

You will need the Ubuntu Server 20.04 ISO from the Homelab Tutorials page.

Hardware

We will be creating a new virtual machine, so you will need to make sure you have

  • 1024 MB RAM free (1GB)
  • 50GB HDD Space
  • At least 2 free logical cores

Total Utilization

At this point our total hardware utilization should be around

  • 5 GB RAM
  • 70 GB HDD Space
  • About 4 Logical cores

Discussion and Process

Services and Servers

At this point you should generally understand that Operating Systems are specialized applications that interface between the user and the hardware. It takes the user's input, and renders it for the machine. It then takes the machine's statements, and renders them for the user. Operating systems generally exist to provide a number of services. In this context, services are applications that respond to specific requests in a predictable way. In general, communication over a network happens between clients and servers.

 +------------+                  +------------+    
 |            | <-----Request--- |            |    
 |   Server   | --Response-----> |   Client   |    
 |            | <-----Request--- |            |    
 +------------+ --Response-----> +------------+

This Request/Response cycle is a fairly common process. A Client will make a request of a server, and the server will respond:

  • Request
    • Response

A Basic DHCP Request example:

  • Client: I need an IP Address, can anyone help me?
    • DHCP Server: Yes, I can help. Would you Like an IP Address?
  • Client: Yes, I am requesting an IP Address!
    • DHCP Server: Here is your IP Address. I have associated it with your MAC address

In this example, a client system is requesting a new IP address on the network. The Dynamic Host Configuration Protocol (DHCP) service is offering the system an IP address it does not know to be in use. The system running the DHCP service is referred to as the DHCP Server.

Network Management

In this example we have discussed the DHCP service and what it does, but not why it does it. The DHCP service is necessary to ensure that IP addresses are not re-used on the network. Discussing the importance, and even a primer on the topic of, subnetting is well outside the scope of this tutorial, but know that we will be using a DHCP server to enforce and isolate a subnet. Ultimately, we will use a fairly common private subnet (the 192.168.1.0/24 subnet). This subnet has a mask of 255.255.255.0. The IP Addresses we want to offer are going to be 192.168.1.117-217. The Infrastructure server will have a static IP of 192.168.1.17.

Perhaps more importantly, the DHCP server will be absolutely necessary in making sure our vulnerable machines are able to communicate on the internal VirtualBox Network.

Virtual Machine Parameters and Operating Systems

For this we will need a virtual machine with

  • 1024 MB RAM
  • 50 GB Virtual Disk
  • 2 Virtual Processors

Once you have configured that, you will need to install the Ubuntu Server operating system. I recommend following the [Ubuntu Server Install Guide] from Canonical.

Will you walk me through this process?

No, but I feel like you deserve an explanation why. We configured a virtual machine and installed an operating system in previous tutorials. I know you have been exposed to the thought processes and basic understanding of how it all works. You can go back and review these tutorials to get an idea on how to proceed if you feel stuck. You can also post on the [Forums] if you have a question that you have put thought into.

Adding a Network Adapter to a Virtual Machine

While we have Ubuntu Server installing we can start configuring the Driver vm to have a second network adapter. This will allow the Driver VM (and once Ubuntu is installed to the Infrastructure VM we will add another adapter there too) to communicate with both a NAT internet-enabled network and a secure internal only network. To do that, open the "Settings" window of the Driver VM.

  1. Go to the Network Settings tab
    NetworkAdapter-01.png
  2. Select the "Adapter 2" tab
    NetworkAdapter-02.png
  3. At this point we will need to
    1. Enable the Adapter
    2. Connect it to the internal network named "intnet"
    3. Press "Ok"
      NetworkAdapter-03.png
  4. This will enable the network adapter connected to "intnet".

Once your Ubuntu Server installation is complete, you will need to repeat these exact steps for the Infrastructure machine.

Setting up the Infrastructure Server

After all of these network adapters are configured we will need to configure a DHCP service on a system in our homelab. The Infrastructure system is designed for just that! To install the DHCP service we will need to install the DHCP Server package, configure it, and test it. At the end of this section, we will break down each command run in the terminal and the purpose and meaning of the configuration file.

Installing and Configuring the DHCP Server Package

  1. Log into your Ubuntu Server CLI
  2. Run `sudo apt install isc-dhcp-server` (Agree to install when requested by pressing enter)
  3. Using the `nano` text editor we will want to edit the /etc/dhcp/dhcpd.conf
    1. This is done by running 'sudo nano /etc/dhcp/dhcpd.conf' from the CLI
  4. At the bottom of this file add the following code:
    subnet 192.168.1.0 netmask 255.255.255.0 {
    option routers 192.168.1.17;
    option subnet-mask 255.255.255.0;
    option domain-search "home.lab";
    option domain-name-servers 192.168.1.17;
    range 192.168.1.117 192.168.1.217;
    }
  5. Press "ctrl+o" on your keyboard to save the file, and press enter to save the modified file.
  6. Press "ctrl+x" on your keyboard to exit the 'nano' text editor
  7. Run the following commands to start and allow the DHCP service to auto start
    1. sudo systemctl start isc-dhcp-server.service
    2. sudo systemctl enable isc-dhcp-server.service
  8. At this point, assuming everything is well you should be able to run 'sudo systemctl status isc-dhcp-server.service' and see that the service is running.

The service is now enabled, and ready to go, but it is not able to assign addresses on our local network yet. We still have to configure that network adapter.

Configuring the Network Adapter

To allow the DHCP server to assign addresses, it needs a network address itself. When we can not dynamically allocate IP addresses we can configure them to be static. In this section we will set the static IP address of the server. To do this, we will need to create a YAML file for netplan to assign the appropriate IP.

We know that our network's IP address space is 192.168.1.0/24. This means we will need an IP address that starts with 192.168.1.x, where x is our client's specific IP. For this infrastructure machine, we will use 192.168.1.17.

Now, we will edit the YAML file.

  1. Navigate to /etc/netplan/
    #cd /etc/netplan
  2. List all of your network interfaces
    • Remember, at this point you should have two interfaces. One of these will be NAT'd and have an IP address, the other one will not.
    • You will need to determine which interface you need to configure with the static IP. See in the screenshot the interface without the IP (red), and the interface with the IP (green). (Ignore the "lo" interface, this is the loopback).
    1. The label for this interface is enp0s8, so this is the interface we need to configure.
      StaticIP01.png
  3. Create a new file called "99-internal.yaml"
    nano 99-internal.yaml
  4. Edit the file to contain the following
    network:
    
        ethernets:
            enp0s8:
                addresses:
                    - 192.168.1.17/24
  5. Review that your file resembles the screenshot below
    StaticIP02.png
  6. Save the file
    Ctrl+o
    Enter
    Ctrl+x
  7. At this point all that is left is to apply the configuration with the netplan command
    sudo netplan apply
  8. You can now validate the IP address
    ip addr
    • In the screenshot you can see the interface name (1) and the configured IP address (2)
      StaticIP03.png

Before we can test the DHCP service, we now need to configure our DHCP server to listen on the correct interface.

  1. Edit the default isc-dhcp-server configuration
    nano /etc/default/isc-dhcp-server
  2. In this file, set the "INTERFACESV4" key to have a value of the interface from above (enp0s8)
    INTERFACESV4="enp0s8"
  3. Save the file
  4. Reboot your infrastructure server
    sudo reboot NOW

Testing the Server

At this point our network should have a DHCP server on it to provide IP addresses to the individual systems on the network. We can test this by opening the Driver virtual machine and checking the IP addresses assigned to the interfaces. We should now see that the system has 2 interfaces with IP addresses. One should be the NAT adapter and will be associated with your home network. The other should be assigned an address in the range we configured on our Infrastructure server's DHCP service (192.168.1.117-192.168.1.217).

  1. Boot your driver machine and open the terminal application
  2. In the terminal application check the IP addresses:
    ip addr
  3. In the screenshot notice how the second ethernet interface (eth1) has an IP in our 192.168.1.117 range.
    StaticIP04.png

This means our DHCP server is working!

Next Steps

Next we are going to need to discuss some hierarchy of the Linux operating system and show you how to access some files that will be useful to you on your journey. Stay Tuned!

Optional Self-Study Questions

  1. What is the range of IP addresses that your network uses?
  2. What is the purpose of a DHCP server?
  3. What is APIPA? How is it used?
    1. How would this relate to us needing to create a static IP?
  4. How would you configure the IP range differently if you wanted to use a range of 10.0.175.0/24?
    1. What steps would you take?
    2. How many files would you need to edit?