Day 2: Linux Commands & Network Configuration

Welcome to Day 2 of Linux Training 🚀

In Day 1, we learned Linux fundamentals, installation, and boot process.
Today, we dive into the most important part of Linux administration — Command Line Operations and Network Configuration.

Mastering commands is essential for every:

  • Linux Administrator

  • DevOps Engineer

  • Cloud Engineer

  • System Engineer


📋 Agenda – Day 2

  • Introduction to Linux Commands

  • File Management Commands

  • Process Management Commands

  • System Administration Commands

  • Network Commands

  • Network Configuration (RedHat, Ubuntu, Azure)

  • Network Configuration using NMTUI


🖥 Introduction to Linux Command Line

The Linux Command Line Interface (CLI) allows users to interact directly with the operating system.

Why CLI is important?

✔ Faster than GUI
✔ Required for servers
✔ Enables automation
✔ Essential for troubleshooting
✔ Used in cloud & DevOps environments


📂 File Management Commands

📁 Directory Commands

List files and directories

[root@rocky8 ~]# ls anaconda-ks.cfg data [root@rocky8 ~]#

[root@rocky8 ~]# ls -l total 4 -rw-------. 1 root root 1177 Mar 7 2023 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Sep 9 21:23 data [root@rocky8 ~]#
[root@rocky8 ~]# ls -la total 28 dr-xr-x---. 3 root root 147 Sep 9 21:23 . dr-xr-xr-x. 17 root root 224 Mar 7 2023 .. -rw-------. 1 root root 1177 Mar 7 2023 anaconda-ks.cfg -rw-------. 1 root root 21 Mar 7 2023 .bash_history -rw-r--r--. 1 root root 18 Mar 15 2021 .bash_logout -rw-r--r--. 1 root root 176 Mar 15 2021 .bash_profile -rw-r--r--. 1 root root 176 Mar 15 2021 .bashrc -rw-r--r--. 1 root root 100 Mar 15 2021 .cshrc drwxr-xr-x. 2 root root 6 Sep 9 21:23 data -rw-r--r--. 1 root root 129 Mar 15 2021 .tcshrc [root@rocky8 ~]#
[root@rocky8 ~]# ls -ld */ drwxr-xr-x. 2 root root 6 Sep 9 21:23 data/ [root@rocky8 ~]#
[root@rocky8 ~]# ls -lh total 4.0K -rw-------. 1 root root 1.2K Mar 7 2023 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Sep 9 21:23 data [root@rocky8 ~]#
[root@rocky8 ~]# ls -lrt total 4 -rw-------. 1 root root 1177 Mar 7 2023 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Sep 9 21:23 data [root@rocky8 ~]#

Change directory
[root@rocky8 ~]# cd /var/log/
[root@rocky8 log]# cd
[root@rocky8 log]# cd ..


Create directory
[root@rocky8 ~]# mkdir linux
[root@rocky8 ~]# mkdir -p 2026/sept/sunday


Show current path
[root@rocky8 sunday]# pwd
/root/2026/sept/sunday
[root@rocky8 sunday]#

Remove directory
[root@rocky8 ~]# rmdir data/

📄 File Operations

# VI Editor
1. Open the file

[root@rocky8 ~]# vi myself.txt

2. Enter Edit Mode
Press one of the following keys to start typing: i — Insert text before the cursor r — Replace a single character under the cursor 3. Return to Command Mode Press Esc to exit edit mode.

4. Saving and Quitting

ActionCommand
Save file:w
Quit:q
Save and quit:wq
Quit without saving:q!
Displays the entire contents of the file directly to the terminal screen
[root@rocky8 ~]# cat myself.txt Name: Vallabh Darole Profession: Technical Specialist Linux at Hexaware Technologies Experience: 19 years Experience on Linux administration [root@rocky8 ~]#

Prints the specified text
[root@rocky8 ~]# echo "Currently working Hexaware since 5 year"

Appends the text string to the end of myself.txt
[root@rocky8 ~]# echo "Currently working Hexaware since 5 year" >> myself.txt

Overwrites myself.txt with the new text string
[root@rocky8 ~]# echo "Vallabh Darole has start new career as DevOps administration " > myself.txt

Change file timestamps
[root@rocky8 ~]# ls -l myself.txt -rw-r--r--. 1 root root 977 Sep 9 21:41 myself.txt [root@rocky8 ~]# touch myself.txt [root@rocky8 ~]# ls -l myself.txt -rw-r--r--. 1 root root 977 Sep 9 21:45 myself.txt [root@rocky8 ~]#

Copy file/directory
[root@rocky8 ~]# cp myself.txt 2026/sept/sunday/ [root@rocky8 ~]# ls -l 2026/sept/sunday/ total 4 -rw-r--r--. 1 root root 977 Sep 9 21:46 myself.txt [root@rocky8 ~]#ls -l myself.txt -rw-r--r--. 1 root root 977 Sep 9 21:45 myself.txt [root@rocky8 ~]#
Move or rename
[root@rocky8 ~]# mv myself.txt 2026/ [root@rocky8 ~]# ls -l 2026/ total 4 -rw-r--r--. 1 root root 977 Sep 9 21:45 myself.txt drwxr-xr-x. 3 root root 20 Sep 9 21:33 sept [root@rocky8 ~]# ls 2026 anaconda-ks.cfg linux Remove file
[root@rocky8 2026]# ls myself.txt sept [root@rocky8 2026]# rm myself.txt rm: remove regular file 'myself.txt'? y [root@rocky8 2026]# ls sept [root@rocky8 2026]#
[root@rocky8 ~]# tree . ├── 2026 │   └── sept │   └── sunday │   └── myself.txt ├── anaconda-ks.cfg └── linux 4 directories, 2 files [root@rocky8 ~]# rm -rf linux/ [root@rocky8 ~]# rm -rf 2026/ [root@rocky8 ~]# tree . └── anaconda-ks.cfg 0 directories, 1 file [root@rocky8 ~]#

First 10 lines
[root@rocky8 ~]# head anaconda-ks.cfg #version=RHEL8 # Use graphical install graphical repo --name="Minimal" --baseurl=file:///run/install/sources/mount-0000-cdrom/Minimal %packages @^minimal-environment kexec-tools [root@rocky8 ~]#
Last 10 lines
[root@rocky8 ~]# tail anaconda-ks.cfg

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
[root@rocky8 ~]# tail -f /var/log/messages

Page view
[root@rocky8 ~]# more anaconda-ks.cfg
Scroll view
[root@rocky8 ~]# less anaconda-ks.cfg
Search text
[root@rocky8 ~]# cat /etc/passwd | grep game
games:x:12:100:games:/usr/games:/sbin/nologin
[root@rocky8 ~]#

📦 Compression Commands

tar (archiving utility)
[root@rocky8 ~]# tar -cvf backup.tar /etc/ssh/
[root@rocky8 data]# tar -xvf backup.tar

zip (package and compress (archive) files)
[root@rocky8 ~]# zip anaconda.zip anaconda-ks.cfg adding: anaconda-ks.cfg (deflated 44%) [root@rocky8 ~]# ls anaconda-ks.cfg anaconda.zip backup.tar data [root@rocky8 ~]# [root@rocky8 ~]# zip -r backup.zip data/

unzip [root@rocky8 data]# unzip anaconda.zip
[root@rocky8 data]# unzip backup.zip


bzip2 ( a block-sorting file compressor)
[root@rocky8 ~]# bzip2 anaconda-ks.cfg
bunzip2
[root@rocky8 data]# bunzip2 anaconda-ks.cfg.bz2

🔗 Sync Links 

An inode stores a file's metadata such as permissions, owner, size, timestamps,

and disk location. It does not store the filename or file contents.

Hard Link vs Soft Link

# Original file
[root@rocky8 data1]# touch csmt_station.txt

# Hard link
[root@rocky8 data1]#  ln csmt_station.txt vt_station.txt

# Soft link
[root@rocky8 data1]# ln -s csmt_station.txt signpost_to_csmt.txt

Check inode numbers:

[root@rocky8 data1]# ls -li
Example:
67147515 -rw-r--r--. 2 root root 0 Sep 10 10:26 csmt_station.txt
67147516 lrwxrwxrwx. 1 root root 16 Sep 10 10:26 signpost_to_csmt.txt -> csmt_station.txt
67147515 -rw-r--r--. 2 root root 0 Sep 10 10:26 vt_station.txt

Hard LinkSoft Link
InodeSameNew
Points toData/inodeFilename/path
Delete original✅ Still works❌ Breaks
Across filesystems❌ No✅ Yes
Directory❌ No✅ Yes

Easy memory trick:
👉 Hard link = same inode
👉 Soft link = shortcut to filename


⚙ System Administration Commands

Show system uptime
[root@rocky8 data1]# uptime

Show kernel and system information
[root@rocky8 data1]# uname -a

Show hardware information
[root@rocky8 data1]# dmidecode

Show kernel messages with readable timestamps
[root@rocky8 data1]# dmesg -T

Show command history
[root@rocky8 data1]# history

Show previously logged-in users
[root@rocky8 data1]# last

⚙️ systemctl  – In Brief

systemctl is the command used to manage and control services on Linux systems using systemd.

# Check service status
[root@rocky8 data1]# systemctl status sshd
# Start service
[root@rocky8 data1]# systemctl start httpd
# Stop service
[root@rocky8 data1]# systemctl stop httpd
# Restart service
[root@rocky8 data1]# systemctl restart httpd
# Enable service at boot
[root@rocky8 data1]# systemctl enable httpd
# Enable and start immediately
[root@rocky8 data1]# systemctl enable --now httpd
# Disable service at boot
[root@rocky8 data1]# systemctl disable httpd
# Check if service is running
[root@rocky8 data1]# systemctl is-active httpd
# List failed services
[root@rocky8 data1]# systemctl --failed

🔄 Process Management Commands

Show running processes
[root@rocky8 data1]# ps

how all processes, sorted by CPU usage [root@rocky8 data1]# ps -aux --sort=-%cpu Show all processes, sorted by memory usage [root@rocky8 data1]# ps -aux --sort=-%mem Monitor processes in real time [root@rocky8 data1]# top Terminate a process [root@rocky8 data1]# kill <PID> Show open files and network connections [root@rocky8 data1]# lsof
Find which process is using a file [root@rocky8 data1]# lsof /var/log/messages Find which process is using a port [root@rocky8 data1]# lsof -i :80
Show processes and users using a file/system [root@rocky8 data1]# fuser -cu <file|directory>

🌐 Network Commands

Test connectivity
[root@rocky8 data1]# ping <host>

Show IP addresses/interfaces
[root@rocky8 data1]# ip addr

Show network connections (legacy)
[root@rocky8 data1]# netstat

Show TCP connections [root@rocky8 data1]# ss -tn Show UDP connections [root@rocky8 data1]# ss -un Show listening TCP ports [root@rocky8 data1]# ss -ltn Show listening UDP ports [root@rocky8 data1]# ss -lun Check a specific port [root@rocky8 data1]# ss -ltnp | grep :22 Show all connections with process information [root@rocky8 data1]# ss -tunap Show listening ports/connections [root@rocky8 data1]# ss -tulpn Remote login [root@rocky8 data1]# ssh user@<host> Copy files remotely [root@rocky8 data1]# scp file user@<host>:/tmp/ Synchronize files [root@rocky8 data1]# rsync -avz src/ dest/ Trace network path [root@rocky8 data1]# tracepath <host> Show IP addresses [root@rocky8 data1]# hostname -I

🌍 Network Configuration in RedHat / Rocky Linux (Manual Method)

Edit configuration file:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Example configuration:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8

Restart network:

# systemctl restart network (old method before rhel 7)
# systemctl restart NetworkManager

🌍 Network Configuration in Ubuntu (Netplan)

Edit file:

vi /etc/netplan/50-cloud-init.yaml

Example:

network:
  ethernets:
    ens160:
      addresses:
        - 192.168.2.223/24
      gateway4: 192.168.2.1
      nameservers:
        addresses:
          - 192.168.2.1
  version: 2

Apply configuration:

#netplan apply

🌐 Network Configuration Using NMTUI (Interactive Method)

Apart from manual configuration, Linux provides an interactive tool called nmtui (Network Manager Text User Interface).

This method is easier and reduces configuration mistakes.


🚀 Open NMTUI

nmtui

You will see options:

  • Edit a connection

  • Activate a connection

  • Set system hostname


📝 Configure Static IP Using NMTUI

Step 1: Edit Connection

  • Select Edit a connection

  • Choose your interface (example: ens160)

  • Click Edit

Step 2: Change IPv4 Configuration

  • Change from Automatic (DHCP)Manual

  • Add:

    • IP Address

    • Gateway

    • DNS Server

  • Enable:
    ✔ Automatically connect
    ✔ Available to all users

Save the configuration.


Step 3: Activate Connection

  • Go to Activate a connection

  • Deactivate and Reactivate the interface


🔄 Restart NetworkManager (If Needed)

systemctl restart NetworkManager

🔍 Verify IP Address

# ip addr

or

# nmcli device show

☁ Network Configuration in Azure Cloud

Steps:

  1. Login to Azure Portal

  2. Open Virtual Machine

  3. Go to Networking

  4. Select Network Interface

  5. Change IP Assignment → Static

  6. Save changes


📌 Day 2 Conclusion

Today we covered:

✔ Linux Command Basics
✔ File Management
✔ Process Management
✔ System Administration Commands
✔ Network Commands
✔ Static IP Configuration (Manual + Netplan)
✔ Network Configuration using NMTUI
✔ Azure Network Setup


No comments:

Post a Comment