Networking and Linux
Networking and Linux
BASIC NETWORKING
-------------------------------------------------------------------------
Network: A group of interconnected devices (computers, routers, switches, etc.)
that communicate.
- LAN (Local Area Network): A network in a small geographical area, like a home
or office.
- WAN (Wide Area Network): A network spread over a large area, such as the
internet.
Networking Protocols:
---------------------
- TCP/IP (Transmission Control Protocol/Internet Protocol): The foundation of
internet communication.
- HTTP/HTTPS: Used for web browsing.
- DNS (Domain Name System): Translates domain names (e.g., google.com) into IP
addresses.
- DHCP (Dynamic Host Configuration Protocol): Automatically assigns IP addresses
to devices.
IP Addressing:
--------------
- IPv4 (e.g., 192.168.1.1): 32-bit address format.
- IPv6 (e.g., 2001:db8::ff00:42:8329): 128-bit address format for a larger
address space.
- Private IP: Used within a LAN (e.g., 192.168.1.x).
- Public IP: Used for internet communication.
Network Models:
---------------
OSI Model (7 Layers):
1. Physical
2. Data Link
3. Network
4. Transport
5. Session
6. Presentation
7. Application
--------------------------------------------------------------------------------
-
PROTOCOLS WITH PORT NUMBER
--------------------------------------------------------------------------------
-
1. FTP (File Transfer Protocol) - Port 21 - Used for file
transmission.
2. SMTP (Simple Mail Transfer Protocol) - Port 25 - Used for email exchange.
3. TELNET - Port 23 - Allows remote command-
line access.
4. DNS (Domain Name Systems) - Port 53 - Converts domain names to
IP addresses.
5. HTTP (Hypertext Transfer Protocol) - Port 80 - Used for web browsing.
6. HTTPS (Hypertext Transfer Protocol Secure) - Port 443 - Secure version of
HTTP.
7. RDP (Remote Desktop Protocol) - Port 3389 - Remote desktop access.
8. SSH (Secure Shell) - Port 22 - Secure remote access.
--------------------------------------------------------------------------------
-
IP ADDRESS AND ITS TYPES
--------------------------------------------------------------------------------
-
Class Starting IP Ending IP Default Subnet Mask Usage
--------------------------------------------------------------------------------
-
Class A 1.0.0.0 126.255.255.255 255.0.0.0 Large
networks (Govt, Large Companies)
Class B 128.0.0.0 191.255.255.255 255.255.0.0 Medium-
sized networks
Class C 192.0.0.0 223.255.255.255 255.255.255.0 Small
networks (Home, Office)
Class D 224.0.0.0 239.255.255.255 N/A
Multicasting
Class E 240.0.0.0 255.255.255.255 N/A
Experimental and Reserved Use
IPv6 Example:
2011:0bd9:75c5:0000:0000:6b3e:0170:8394
--------------------------------------------------------------------------------
-
LINUX
--------------------------------------------------------------------------------
-
1. pwd -- Present working directory.
2. sudo -i -- Go to root directory.
3. cd -- Change directory.
4. mkdir (folder name) -- Create folder/directory.
5. rm -r (folder name) -- Remove directory.
6. cp (file1) (file2) -- Copy file.
7. mv (file1) (file2) -- Move or rename file.
8. rm (file) -- Remove file and delete file.
9. find (filename) -- Find a file.
10. locate (filename) -- Find file using the database.
-----------------------------------------------------------------------------
File Permission and Ownership
-----------------------------------------------------------------------------
11. ls -lrt -- View file permissions.
12. chmod (permissions) (file name)
Example: chmod 755 file1 -- Change file permission.
13. chown [user]:[group] [file] -- Change ownership.
14. chgrp [group] [file] -- Change group ownership.
-----------------------------------------------------------------------------
File Viewing & Editing
-----------------------------------------------------------------------------
15. cat (file1) -- View file contents.
16. less (file1) -- View file with navigation.
17. more (file1) -- View file page by page.
18. head -n (num) (file1) -- Show first 'n' lines.
19. tail -n (num) (file1) -- Show last 'n' lines.
Example: tail -n 5 file1
20. nano (file1) -- Open file in Nano editor.
21. vim (file1) -- Open file in Vim editor.
(For exiting Vim: press Esc, then type :wq)
22. tree -- Show directory structure.
23. cat ygminds | grep welcome -- Edit inside file.c
-----------------------------------------------------------------------------
User Management
-----------------------------------------------------------------------------
22. whoami -- Show current user.
23. who -- Show logged-in users.
24. id -- Show user ID.
25. adduser (user) -- Add new user.
26. deluser (user) -- Delete user.
27. passwd (user) -- Change password.
28. usermod -aG (group) (user) -- Add user to a group.
29. groups (user) -- Show user groups.
-----------------------------------------------------------------------------
Process Management
-----------------------------------------------------------------------------
30. ps aux -- Show all running processes.
31. top -- Display real-time system tasks.
32. kill (process id) -- Kill process by ID.
33. killall (process) -- Kill process by name.
34. pkill (process) -- Kill process by name.
------------------------------------------------------------------------------
Disk Usage & Storage
------------------------------------------------------------------------------
35. df -h -- Show disk usage (human-readable).
36. lsblk -- Show all storage devices.
-------------------------------------------------------------------------------
Package Management
-------------------------------------------------------------------------------
37. apt update -- Update package list.
38. apt upgrade -- Upgrade all packages.
39. apt install (package name)
Example: apt install tree -- Install package.
40. apt remove (package) -- Remove package.
--------------------------------------------------------------------------------
System Monitoring
--------------------------------------------------------------------------------
41. uptime -- Show system uptime.
42. free -m -- Show memory usage.
43. vmstat -- Show system performance.
44. iostat -- Show CPU & disk usage.
--------------------------------------------------------------------------------
Compression & Archiving
--------------------------------------------------------------------------------
45. tar -cvf archive.tar (directory) -- Create tar archive.
46. tar -xvf archive.tar -- Extract tar archive.
47. zip -r archive.zip (directory) -- Create zip archive.
48. unzip archive.zip -- Extract zip file.
--------------------------------------------------------------------------------
-
SSH & Remote Access (Very Important)
--------------------------------------------------------------------------------
-
49. ssh user@host -- Connect to remote server.
50. ssh -p (port) user@host -- Connect with custom port.
--------------------------------------------------------------------------------
---
Additional File Manipulation
--------------------------------------------------------------------------------
---
51. grep "text" (file) -- Search for text in file.
52. awk '{print $1}' (file) -- Print first column.
53. sed 's/old/new/g' (file) -- Replace text in file.
54. sort (file) -- Sort file contents.
---------------------------------------------------------------------------
Important Linux Commands
---------------------------------------------------------------------------
55. wget <link to file> -- Download file or webpage (HTML format).
58. wget -c <link to file> -- Allow interrupted download.
59. cal -- Display a calendar in the terminal.
60. top -- Task manager.
--------------------------------------------------------------------------------
Networking Commands
--------------------------------------------------------------------------------
61. ifconfig -- Display network interfaces.
62. hostname -i -- Display IP address.
63. ping google.com -- Test network reachability.
64. traceroute google.com -- Print route packets take.
65. tracepath google.com
66. netstat -- Show network statistics.
67. ss -- Display socket information.
68. nslookup google.com -- Query DNS record.
69. dig google.com -- More detailed DNS record.
70. nmap google.com -- Discover open ports.
71. arp -- View and manage ARP cache.
--------------------------------------------------------------------------------
Good to Know Commands
--------------------------------------------------------------------------------
72. mtr google.com -- Combination of ping and traceroute.
73. df -i -- Display inodes usage.
74. htop -- Interactive and colorful task manager.
75. whois google.com -- Information about domain.
76. hostnamectl -- Control system information.
77. watch <command> -- Execute command every 2 sec.
78. rsync [options] source [destination] -- Sync files.
79. which <command> -- Shows location of command.
80. lscpu -- Detailed CPU info.
81. jobs -l -- Show jobs running in background.
82. ps aux | grep nginx -- Pipe output of first command as input to
second.
83. chmod -R 744 Scripting/ -- Change permissions recursively for a
directory.
84. cat /etc/passwd -- List users.
85. cat /etc/group -- List groups.
86. gpasswd -M user1,user2,user3 groupname -- Add multiple users to a group.
87. apt autoremove -- Remove unnecessary packages.
88. locate <filename> -- Search file/directory in the database.
89. find [path] [options] [expression] -- Find file in real-time.
90. man <command> -- Display manual for a command.
91. ping -c 5 ygminds.com -- Send and receive only 5 packets.
92. load average 1min 5min 15min -- Show system load averages.
93. yes > /dev/null & -- Increase CPU load.
94. cut [options] [file] -- Extract specific portions of text from a file.
95. diff/comm file1 file2 -- Compare two files line by line.
96. who -- Show who is logged in.
97. whatis <command> -- Display one-line information about a command.
98. wc filename -- Show line, word, and character count of a
file.
99. ln originalFile hardlink -- Create a hardlink.
100. ln -s originalFile softlink -- Create a softlink.
101. init 0 -- Shutdown the system.
102. init 6 -- Reboot the system.
103. apt list --installed | grep <package_name> -- List installed packages.
104. cd . -- Remain in the same directory.
105. cd ~ or cd -- Move to the home directory.
106. cd ../../.. -- Move back 3 directories.
107. date -- Display todayâs date (time in UTC; India is
+05:30 hrs).
--------------------------------------------------------------------------------
---------------------------------------------------------------------------
SHELL SCRIPTING
---------------------------------------------------------------------------
To be continued... stay tuned