****## Instructions
- Attendance will be checked at the beginning of the Lab class
- Login credentials:
- Username:
student - Password:
Siit@1992
- Username:
- The ✔ sign identifies exercises
- Some exercises require a TA's signature to check your result
- After finishing all exercises, show this Lab Sheet to a TA to get the full score
- You will have a 10-minute quiz towards the end of the Lab class (or when appropriate)
Exercise 1: Using Shell via Terminal Emulator
1.1 Shell and Terminal Emulator
- Shell: A program that takes keyboard commands and passes them to the operating system to carry out
- When using a graphical user interface, we need a terminal emulator to interact with the shell
- To open a terminal: Search for it on the Ubuntu desktop and double click on Terminal
1.2 Understanding the Shell Prompt
When you see: seksan@ubuntu:~$
seksanidentifies the log-in user name$is called a shell prompt- The
$sign denotes a user-level account - If a root or super-user is logging in, the shell prompt will be represented by the
#sign
- The
- The directory where we currently are is shown in front of the
$sign- The
~sign means our default directory, which is/home/UserName - We can check where we are by typing
pwd
- The
1.3 Exiting Terminal
- To exit from Terminal, type
exitand press Enter
Exercise 2: Navigating in the Linux System
2.1 Filesystem Tree
- Like Windows, Linux organizes files in a hierarchical directory structure
- Files are organized in a tree-like pattern of directories (folders)
- The first directory in the filesystem is called the root directory (
/) - The root directory contains files and subdirectories, which contain more files and subdirectories, and so on
Filesystem structure:
/
├── bin/
├── dev/
├── etc/
├── usr/
│ ├── bin/
│ ├── man/
│ ├── lib/
│ ├── local/
│ ├── sbin/
│ └── share/
├── home/
├── lib/
├── sbin/
├── tmp/
└── var/
├── log/
└── tmp/
2.2 Current Working Directory
- To display the current working directory, use:
pwd(print working directory)
2.3 Listing Directory Contents
- To list files and directories in the current working directory:
ls
✔ Exercise:
$ pwd
# Record what you see
$ ls
# Record what you see2.4 Changing the Current Directory
- To change working directory:
cdfollowed by the pathname - Pathname: The route we take along the branches of the tree to get to the directory we want
- Pathnames can be specified in two ways:
Absolute Pathnames
- An absolute pathname begins with the root directory (
/) - Follows the tree branch by branch until the path is completed
✔ Exercise:
$ cd /usr/games
$ pwd
# Record what you see
$ ls
# Record what you seeAnalogy: Absolute paths are like giving someone your complete address starting from the country: "Thailand, Bangkok, SIIT Campus, Building 2, Room 101". No matter where you are, this address always works.
Relative Pathnames
- A relative pathname starts from the current working directory
- Uses special symbols:
.(dot) = current directory..(dot dot) = parent directory
Examples:
-
cd ..- Go to the parent directory- Note: There is a space between
cdand.. - Example: If you're in
/usr/games, typingcd ..takes you to/usr
- Note: There is a space between
-
cd ./ChildDirectory- Go to a child directory- Example: If you're in
/usr, typingcd ./gamestakes you to/usr/games
- Example: If you're in
Exercise 3: Exploring the Commands
3.1 Showing Command History
- To see commands used in the past:
history
3.2 Recall Previous Typing
- Press the UP arrow key to recall what you have typed previously
3.3 Commands' Options and Arguments
- Commands are often followed by one or more options (modify behavior) and arguments (items upon which the command acts)
- Most commands look like this:
Analogy: Think of a command like ordering food: "coffee" is the command, "-large" is the option (size), and "with milk" is the argument (what to add).
3.4 Getting a Command's Documentation
- Use either
helpormanto know how to use a command - Note: Many commands support only
helpormanbut not both
The help command:
- Example: To know how to use the
cdcommand
$ help cdThe man command:
- Example: To know how to use the
lscommand
$ man lsAnalogy:
helpandmanare like instruction manuals.helpgives you a quick guide, whileman(manual) gives you the full detailed documentation.
Exercise 4: More with the Command ls
4.1 Displaying Contents of a Specific Directory
- Type the command:
ls /PathNames
✔ Exercise:
$ ls /usr/games
# Record the result4.2 Displaying Contents in Long Format
- Type the command:
ls -l
Understanding the output:
For example, consider the line:
-rwxr-xr-x 1 root root 1563 May 6 2015 espdiff
- 1st field (
-rwxr-xr-x) - Access permissions of this file/directory (explained in Exercise 7) - 2nd field (
1) - Number of links of this file/directory to others - 3rd field (
root) - File/directory owner's name - 4th field (
root) - Group name that owns this file/directory - 5th field (
1563) - Size in bytes - 6th - 8th fields (
May 6 2015) - Month, date, year that this file/directory was modified - 9th field (
espdiff) - Name of this file/directory
4.3 More ls Options
| Option | Long Option | Description |
|---|---|---|
-a | --all | List all files, even those with names that begin with a period, which are normally not listed (i.e., hidden) |
-d | --directory | Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents |
-F | --classify | This option will append an indicator character to the end of each listed name (for example, a forward slash if the name is a directory) |
-h | --human-readable | In long format listings, display file sizes in human-readable format rather than in bytes |
-l | Display results in long format | |
-r | --reverse | Display the results in reverse order. Normally, ls displays its results in ascending alphabetical order |
-S | Sort results by file size | |
-t | Sort by modification time |
Exercise 5: Manipulating Files and Directory
Important: Assume that now you are at your home directory /home/student
- Note: You will see
~in front of your shell prompt$when you are at your home directory
5.1 Creating Directories
The command mkdir is used to create directories:
- Creating a directory:
mkdir DirName - Creating multiple directories:
mkdir DirName1 DirName2
✔ Exercise:
# Create the directories L, NewDir2, and NewDir3 in your home directory
# Show the result to a TA and get the signature
TA's Signature: ________________________Analogy:
mkdiris like creating new folders on your desktop. You can create one folder or multiple folders at once by listing their names.
5.2 Copying Files and Directories
The command cp is used to copy files or directories:
Copying a file to the current working directory:
$ cp /PathName/file .(Note: there is a dot at the end representing the current directory)
Copying a file in the same directory:
$ cp file1 file2Copying a file from the current directory to another directory:
$ cp file /Pathname/filename✔ Exercise:
# Copy the file dmesg to the directory NewDir1 as a name dmesg_copy
# Show that there is a file name dmesg_copy in the directory NewDir1 to a TA
TA's Signature: ________________________Analogy:
cpis like using Ctrl+C and Ctrl+V. You copy a file from one location and paste it to another location, optionally giving it a new name.
- Note: There are more options and ways to copy files and directories, which are not shown here
5.3 Moving Files
The command mv is used to move files within a directory or to another directory:
$ mv file /PathName/DirName✔ Exercise:
# Move the files dmesg and dmesg_copy from the home directory to the directory NewDir2
# Show that there are the files dmesg and dmesg_copy in the directory NewDir2 to a TA
TA's Signature: ________________________Analogy:
mvis like cutting and pasting (Ctrl+X, Ctrl+V). The file is removed from its original location and placed in the new location.
- Note: There are more options and ways to move files and directories, which are not shown here
5.4 Removing Files and Directories
The command rm is used to remove/delete files and directories:
Removing files:
$ rm /PathName/FileNameRemoving directories:
$ rm -r /PathName/DirName✔ Exercise:
# Remove the files (passwd and passwd_copy) and the directories (NewDir1, NewDir2, NewDir3) from your home directory
# Show that there are no more such files and directories to a TA
TA's Signature: ________________________Analogy:
rmis like dragging files to the trash/recycle bin and emptying it permanently. Be careful - unlike Windows, there's no recycle bin to recover from!
- Note: There are more options and ways to remove files and directories, which are not shown here
Exercise 6: Other Important Commands
6.1 Viewing File Contents
- The command
lessis used to view text files - In a Linux system, there are many files that contain human-readable text
- The command
lessprovides a convenient way to examine them
Syntax:
$ less FileName- Note: Press
qto quit thelessprogram
Analogy:
lessis like opening a text file in read-only mode. You can scroll through and read it, but you can't edit it. Press 'q' to close the viewer.
6.2 Display Texts on the Terminal
The command echo is used to print texts on the terminal:
To print texts without quotes:
$ echo YourSentenceTo print texts with double quotes:
$ echo "Your Sentence"Analogy:
echois like a parrot - it repeats exactly what you tell it to say. Useful for displaying messages or checking variable values.
Exercise 7: File Permissions
7.1 Reading, Writing, and Executing
- Access rights to files and directories are defined in terms of:
- Read access
- Write access
- Execution access
To see your files and directories:
$ ls -lUnderstanding File Attributes:
The first 10 characters of the listing are the file attributes:
-rwxr-xr-x
- First character: File type
- Remaining nine characters: File mode (read, write, execute permissions)
- Permissions for: file's owner, file's group owner, and everybody else
File Types
| Attribute | File Type |
|---|---|
- | A regular file |
d | A directory |
Permission Attributes
| Attribute | Files | Directories |
|---|---|---|
r | Allows a file to be opened and read | Allows a directory's contents to be listed if the execute attribute is also set |
w | Allows a file to be written to or truncated; however, this attribute does not allow files to be renamed or deleted. The ability to delete or rename files is determined by directory attributes | Allows files within a directory to be created, deleted, and renamed if the execute attribute is also set |
x | Allows a file to be treated as a program and executed. Program files written in scripting languages must also be set as readable to be executed | Allows a directory to be entered; e.g., cd directory |
Permission Attribute Examples
| File Attributes | Meaning |
|---|---|
-rwx------ | A regular file that is readable, writable, and executable by the file's owner. No one else has any access |
-rw------- | A regular file that is readable and writable by the file's owner. No one else has any access |
-rw-r--r-- | A regular file that is readable and writable by the file's owner. Members of the file's owner group may read the file. The file is world readable |
Analogy: File permissions are like locks on doors. 'r' means you can look through the door, 'w' means you can change what's inside, and 'x' means you can enter (for directories) or run (for programs). The three groups (owner, group, others) are like having different keys for the homeowner, family members, and guests.
7.2 Change File Mode
- To change the mode (permissions) of a file or directory:
chmod - We use octal numbers to set the pattern of desired permissions
Octal to Permission Mapping:
| Octal | Binary | File Mode |
|---|---|---|
| 0 | 000 | --- |
| 1 | 001 | --x |
| 2 | 010 | -w- |
| 3 | 011 | -wx |
| 4 | 100 | r-- |
| 5 | 101 | r-x |
| 6 | 110 | rw- |
| 7 | 111 | rwx |
✔ Exercise:
# Follow the example below:
# Copy a file "/var/log/dmesg" and change its permissions so that only the owner can read and write
$ cp /var/log/dmesg .
$ ls -l
$ chmod 600 dmesg
$ ls -l
# Show that you have changed the permissions of the file dmesg to a TA
TA's Signature: ________________________Understanding the chmod example:
chmod 600 dmesgmeans:- Owner: 6 = 110 = rw- (read + write)
- Group: 0 = 000 = --- (no permissions)
- Others: 0 = 000 = --- (no permissions)
Analogy: Think of chmod like setting a combination lock. Each number (0-7) represents a different level of access. 6 (rw-) is like having both a key and ability to change the lock, 4 (r--) is just looking through a window, and 0 is being completely locked out.
Exercise 8: IMUNES Tutorial
8.1 Understanding User Interface Layout of IMUNES
To start IMUNES:
$ sudo imunes(If it fails, you may need to start docker first using sudo service docker start)
IMUNES GUI components:
- Canvas: Workspace in the middle
- Menubar: On the top
- Toolbox: On the left side
- Statusbar: At the bottom
Working modes:
- Edit mode (default): Build and configure network topologies
- Execute mode: Network simulation
The toolbox contains tools for building network topologies and adding annotations:
- Available in edit mode
- In execute mode, tools (except Select tool) are shaded and cannot be used
Building the Network Topology
Link:
- A tool used to create network links between nodes
L2 - Link layer nodes:
- LAN switch: A link layer element that forwards incoming packets to connected nodes using the table of destination addresses and its ports
- External interface: Provides the possibility to connect a virtual node with the physical interface (e.g., to give the node access to the Internet)
L3 - Network layer nodes:
- External connection: Provides the possibility to connect your host PC with a virtual node by creating an interface on your computer
- Router: A network layer element capable of packet forwarding using routes obtained by dynamic routing protocols (available through quagga or xorp by default installation or any other standard FreeBSD routing daemon)
- Host: A network layer element that does not forward packets and has static routes. It starts standard network services via portmap and inetd
- PC: A network layer element that does not forward packets and has static routes. Unlike host, it does not start any network services
- NAT64: A router node capable of enabling translation between IPv4 and IPv6 protocols using a form of network address translation (NAT)
The View Menu
Contains options for showing/hiding links and nodes parameters on the canvas:
- Icon size: Change the size (normal or small) of all network elements
- Show [network element parameter]: Show or hide information such as interface names, IPv4/IPv6 addresses, etc.
- Show Topology Tree: Show or hide the tree with a list of all network topology elements
- Show Background Image: Show or hide background image
- Show Annotations: Show or hide annotations (text, oval, rectangle)
- Show Grid: Show or hide grid
- Zoom In, Zoom Out: Magnify or reduce the size of the display
- Themes: Choose one of the themes from the submenu
The Experiment Menu
Used to start and terminate an experiment. Also enables attaching to a running experiment:
- Execute: Start an experiment and switch to execute mode. IMUNES creates and configures the virtual network. All events during that process will be shown in the statusbar
- Terminate: Terminate an experiment and switch to edit mode. IMUNES will shut down all network elements and terminate active services on each node. Termination is finished when the message about successful cleanup shows up in the statusbar
- Restart: Terminate and restart the running experiment
- Attach to experiment: Opens a window with the list of running experiments on the current computer. Allows resuming running experiments
8.2 How to Build, Configure and Simulate Simple Network Topology
Scenario:
- Personal computers (office-pc1 and office-pc2) from network
192.168.1.0/24are connected to LAN switch (office-switch) - LAN switch is connected to router (office-router)
- Server (office-host) from network
192.168.2.0/24is directly connected to the router - Personal computers from the first network have route only to network
192.168.2.0/24 - Server from the second network has the default route
- RIP routing is enabled on the router to serve and receive dynamic route updates
8.2.1 Adding and Deleting Network Elements
To draw a node:
- Click on the corresponding node tool
- Click on the workspace to place it
To connect nodes:
- Click on the Link tool
- Click and hold on the source node
- Go to the destination node
Exercise:
- Draw a router, a host, a LAN switch, and two PCs
- Using the Link tool:
- Connect the LAN switch to the router
- Connect each PC to the LAN switch
- Connect the host directly to the router
8.2.2 Configuring a Simple Network
Although preconfigured parameters are usually sufficient, we will set up our own parameters:
To open the network element configuration window:
- Right-click on the network element
- Select the "Configure" label from the menu
Configuration steps:
Switch:
- Change node name to
office-switch
PC/HOST:
- Change host node name to
office-host - Change PC node names to
office-pc1andoffice-pc2 - To change IPv4 address:
- Left-click on the "Interfaces" tab
- Select interface
eth0from the list of interfaces - Change the IPv4 address field
- Click "Apply"
- Set host IPv4 address to
192.168.2.5/24 - Set PC IPv4 addresses to
192.168.1.5/24and192.168.1.7/24 - IP address fields require CIDR notation (IPv4 address followed by
/and network length)
Static routes:
- PCs and Hosts use static routing
- Preconfigured routing table contains only the default route
- Every static route consists of:
- Destination network: IP address followed by
/and network prefix - Next hop network interface IP address: IP address without
/and without network prefix
- Destination network: IP address followed by
Static route configuration:
- Add static route on
office-pc1andoffice-pc2:- For network
192.168.2.0/24 - Through gateway
192.168.1.1
- For network
- On
office-host:- Change default gateway address to
192.168.2.1
- Change default gateway address to
Router:
- Change node name to
office-router - Set IPv4 addresses on network interfaces:
192.168.1.1/24on interfaceeth0192.168.2.1/24on interfaceeth1
8.2.3 Start the Experiment
After the network topology is completely built and properly configured:
- Start experiment with: Experiment > Execute from menubar
- IMUNES will switch from edit mode to execute mode
- IMUNES creates and configures the virtual network (takes a few seconds)
- All events during the process will be shown in the statusbar
- If successful, status bar shows "exec mode" with experiment ID
8.2.4 Test Network Connectivity
After starting the experiment, test the connection:
Select node and open shell to execute commands:
Check interface information:
$ ifconfigTest connection from office-pc1 to office-host:
$ ping 192.168.2.5- If no problem, you should see reply from office-host
Test connection from office-host to office-pc2:
$ ping 192.168.1.7- If no problem, you should see reply from office-pc2
✔ Exercise:
# Show that you have completed all tasks to a TA
TA's Signature: ________________________After finishing:
- Terminate the experiment: Experiment > Terminate
- You can save the topology with all configuration: File > Save
Bash Commands Summary
Navigation Commands
pwd- Print working directory (show current location)ls- List directory contentsls -l- List in long format (detailed view)ls -a- List all files (including hidden)cd <directory>- Change directorycd ..- Go to parent directorycd ~- Go to home directory
File/Directory Manipulation
mkdir <dirname>- Create directorycp <source> <destination>- Copy files/directoriesmv <source> <destination>- Move or rename files/directoriesrm <filename>- Remove filerm -r <dirname>- Remove directory recursively
File Viewing
less <filename>- View file contents (pressqto quit)echo <text>- Display text on terminal
Information Commands
history- Show command historyhelp <command>- Get help for a commandman <command>- Get manual page for a command
Permissions
chmod <mode> <file>- Change file permissions- Example:
chmod 600 file(owner: rw-, group: ---, others: ---)
- Example:
System Commands
exit- Exit terminalifconfig- Show network interface configurationping <address>- Test network connectivity
Difference Between cd ./home, cd /home, and cd home
1. cd /home - Absolute Path
- Starts with
/(root directory) - Goes to
/homedirectory from the root - Works regardless of your current location
- Like giving a complete address: "Start from the country level, go to the home folder"
Example:
# No matter where you are:
$ pwd
/usr/local/bin
$ cd /home
$ pwd
/homeAnalogy: It's like typing a complete GPS coordinate or full address. No matter where you currently are in the world, this address will take you to the exact same location.
2. cd ./home - Relative Path with Explicit Current Directory
./means "current directory"- Goes to
homefolder inside your current directory - Only works if
homefolder exists in your current location - Like saying: "From where I am right now, go to the home folder"
Example:
$ pwd
/usr
$ cd ./home # Looks for /usr/home
# If it exists, you go to /usr/home
# If it doesn't exist, you get an error
$ pwd
/usr/homeAnalogy: It's like saying "Go to the coffee shop in THIS building." It only works if there's a coffee shop in your current building.
3. cd home - Relative Path (Shorthand)
- Same as
cd ./homebut without the./ - Goes to
homefolder inside your current directory - The
./is implied/assumed - Most commonly used form for relative paths
Example:
$ pwd
/usr
$ cd home # Same as cd ./home
$ pwd
/usr/homeAnalogy: It's like saying "Go to the coffee shop" when you're already inside a building. Everyone assumes you mean the coffee shop in the current building.
Quick Comparison Table
| Command | Type | Meaning | Works From Any Location? |
|---|---|---|---|
cd /home | Absolute path | Go to /home from root | ✅ Yes |
cd ./home | Relative path | Go to home in current directory | ❌ No (only if home exists here) |
cd home | Relative path | Go to home in current directory (shorthand) | ❌ No (only if home exists here) |
Key Symbols Summary
| Symbol | Meaning | Example |
|---|---|---|
/ | Root directory OR path separator | /home/student |
~ | Home directory | cd ~ goes to /home/username |
. | Current directory | cd ./folder |
.. | Parent directory | cd .. goes up one level |
- | Previous directory | cd - goes to last location |
References
- W. E. Shotts, The Linux Command Line: A Complete Introduction, No Starch Press, 2012
- IMUNES tutorial guide: https://imunes.net/dl/guide/