Q: 1. Create a file called "exercise04answers.txt"
A:
e.g.
touch exercise04answers.txt
Q: 2. At the top of the file, use the label as defined before.
A:
as before
 
Q: 3. Put on a line the word "lab" by itself, then work on lab exercises 1-5 below. List all the relevant commands and arguments that you had to use in the lab exercises. Put in comments to show why you did something (this can help your mark even if you did something wrong).
A:
in sequence
  1. In my directory on the course linux server (my username is "gj"), is a directory called "public_html/dropbox". In this location, create a directory the name of which is your studentid. Set the permissions on this directory to only allow yourself all permissions (i.e. make sure that nobody else on the system can get into this directory). Create a link called "mysyslog" into your directory, link it to the file called "syslog" in "public_html/". Make sure you can read its contents. From here on, all lab exercises should take place in the directory you have just created (i.e. any new files you create have to go in there).
    # go to the directory, so I don't have to type so much
    cd ~gj/public_html/dropbox/
    
    # create directory, where my studentid is 01234567890
    mkdir 01234567890
    
    # set the permissions as indicated with chmod
    chmod 700 01234567890
    
    #link the file
    ln ../syslog 01234567890/mysyslog
    
    #go to the directory
    cd 01234567890
  2. From mysyslog, select all those lines that have to do with firewall rules, example:
    Feb 13 20:20:33 idallen-home1 kernel: Shorewall:net2all:DROP:IN=eth0 OUT= MAC=00:80:c8:4b:b7:75:00:04:e2:50:08:96:08:00 SRC=4.164.5.254 DST=192.168.9.198 LEN=908 TOS=0x00 PREC=0x00 TTL=117 ID=17592 PROTO=UDP SPT=13111 DPT=1026 LEN=888
    But do not select any other lines. Put these lines in a file called firewall.log You may not use an editor or cut and paste.
    # we look for "Shorewall"
    grep Shorewall mysyslog > firewall.log
  3. How many lines are there in firewall.log? How many different source IP addresses are there in firewall.log? How many different destination IP addresses? How many different source ports? How many different destination ports? Find an efficient way to get these numbers (counting on your fingers is not efficient!).
    # How many lines
    wc -l firewall.log
    
    # How many different source IP addresses
    cut -d' ' -f9 firewall.log | sort -u | wc -l
    
    # How many different destinateion IP addresses
    cut -d' ' -f10 firewall.log | sort -u | wc -l
    
    # How many different source ports
    cut -d'=' -f13 firewall.log | sort -u | wc -l
    
    # How many different destination ports
    cut -d'=' -f14 firewall.log | sort -u | wc -l
  4. Create a file called "partgroup", the contents of which are selected from the GIDs from the first 20 lines of the password file. Make sure the list is sorted in reverse numerical order, and remove the highest and lowest number. You may not use an editor, or copy and paste to create this file. (Build your command pipeline!) Explain what every part of the pipeline does (or is supposed to do).
    # first 20 lines, GID only (fourth field), sort reverse numeric,
    # remove the last line, remove the first line, redirect to "partgroup"
    head -20 /etc/passwd | cut -d: -f4 | sort -rn | head -19 | tail -18 > partgroup
  5. List all the umask setting so that when you create a file, you end up with permissions r---w-rw-. List all the umask settings so that when you create a directory, you end up with permissions r-x-wxrw-.
    240, 241, 250, 340, 341, 350, 351
    and
    241
Q: 4. Put on a line the word "book3" by itself, then answer questions 1-6, 8-11 and 14, from the book, chapter 3, pages 72-73.
A:
in sequence
Q: 5. Put on a line the word "book5" by itself, then answer questions 2-4, 6-10, 12, 16, chapter 5, pages 134-136.
A:
in sequence