Some of the topics covered by the LPIC-1 Exam 102 include an understanding of network ports, basic Bash scripting, and working with remote systems utilizing tools such as netcat. With the release of LPI’s LPIC-1 Exam 500 series, we have finished our training for the updated exam. Here’s a concept that is covered by the exam to get your feet wet, creating a simple web server!

To set up your own web server that displays a simple web page, follow these steps:

  1. On a CentOS 7 system, open up the firewall port for HTTP (note that firewalls are not covered under the LPIC-1 exams):
    sudo firewall-cmd –-permanent –-add-service=http
    sudo firewall-cmd –-reload
  2. Now we can install netcat on our server:
    sudo yum install nmap-ncat
  3. Once you have the application installed, we will use it to set up a simple server that will listen on port 80. We need to run the command with sudo as we will require elevated privileges to open up a network port:
    sudo nc -l -p 80
  4. On another terminal on your server (you can press Ctrl+F2 to open another tty session), use the ss command to verify that you have an application listening on port 80:
    sudo ss -tlpn | grep 80
  5. From the output, we can see that we have an application (netcat) listening for connections on TCP port 80. Now, from another Linux system (or another tty on the same host), use the nc command to make a connection to your server on port 80 (substitute the IP address of your server in the command):
    nc -v [IP of your server] 80
  6. Type in some text:
    hello
  7. Look at the output of your nc server command:
    [kenny@server ~]$ sudo nc -l -p 80 [sudo] password for kenny: hello
    The text we entered at the prompt is echoed back to us from our server.

Let’s take our little server instance one step further and have it display a web page for us. This part is not covered on the LPIC-1 exam, but the ability to write a loop in Bash and pipe the output of one command to another is covered. Besides, it doesn’t hurt to have a little fun.

To create the web page, complete the following:

  1. Press Ctrl+C on your client system to close your remote connection to the netcat server, and then do the same on your server to cancel your nc command.
  2. Create a script file named myserver.sh, and enter in the following contents:
    #!/bin/bash TEXT=”Welcome to my server!” while true do echo -e “HTTP/1.1 200 OK\n\n $TEXT” | nc -l -p 80 done
  3. Save and close this file, and grant it execute permissions:
    chmod u+x myserver.sh
  4. With the sudo command, run your script:
    sudo ./myserver.sh
  5. Open up a browser on a client computer, and enter in the URL of your server (using the IP address of your server):

    your-web-page

    Your web page!

There you go! You have just set up your own web server that displays a very simple web page, using tools and techniques that you will learn for the LPIC-1 exams! To stop your server, run the following commands from another tty session on your server:

sudo pkill myserver.sh

sudo fuser -k 80/tcp

This is a fun way to learn about different commands you can use to accomplish such a task. The netcat command is a wonderful program you can use to test and verify connections to remote systems, as well as set up simple servers to play around with. You would not want to use this as a production web server, but it is a fun exercise to use to verify that we can make connections to different ports on remote systems. Check out the LPIC-1: System Administrator – Exam 102 Course to dig deeper and sign up today for real hands-on experience with live servers to practice in.. we’ll walk you through it!

 

January Hands-On Training Content Launch

2 responses to “Using Your LPIC-1 Skills to Create a Simple Web Server”

    • Kenny Armstrong says:

      You are in fact, correct. You do NOT need a certification to build out a web server. What this post is meant to illustrate is some of the skills one would pick up in a course on a certification, and how they can be combined and applied to a simple project. I know numerous system administrators who do not have certifications and are highly skilled in Linux. The catch is, they had to prove themselves over and over again, whereas someone with a Linux certification would often get promoted before they do. This is not to say that this is how it always works, but it is quite common.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get actionable training and tech advice

We'll email you our latest articles up to once per week.