System Admin Basic
System Admin Basic
• Introductions of software.
• Types of software.
• How OS works.
• Famous OS.
• History of Linux
• License Rights.
What is Software
Types Of Software
• System Software.
• Application Software.
• Embedded Software.
System Software
The program directly related to the computer hardware and perform tasks
associated with controlling and utilizing computer hardware.
Application software
Application software are programs that help a user perform a specific job.
Eg.
Embedded software
• Microsoft Widows.
• Unix.
• Mac.
• Linux.
• Minix.
Since the C compiler that builds Linux and the main supporting user space
system tools and libraries originated in the GNU Project, initiated in 1983
by Richard Stallman, the Free Software Foundation prefers the name
GNU/Linux.
Before Linux
UNIX is much better, but its also expensive. Only for minicomputer for
commercial applications.
People was looking for a UNIX based operating system, which is cheaper and
can run on PC.
Both DOS, MAC and UNIX are proprietary, the source code of their kernel is
protected.
In 1983, Richard Stallman started the GNU project with the goal of
creating a free UNIX-like operating system. As part of this work, he wrote the
GNU General Public License (GPL).
By the early 1990s there was almost enough available software to create a
full operating system. However, the GNU kernel, called Hurd, failed to
attract enough attention from developers leaving GNU incomplete.
MINIX, a Unix-like system intended for academic use, was released by
Andrew S. Tanenbaum in 1987. While source code for the system was
available, modification and redistribution were restricted.
Minix was for class teaching only. No intention for commercial use.
It was put to the Internet and received enormous response from worldwide
software developers
By September 1991, Linux version 0.01 was released on the FTP server
(ftp.funet.fi) of the Finnish University and Research Network (FUNET). It had
10,239 lines of code.
Torvalds adopted the GNU General Public License (GPL) over his previous
self-drafted license, which had not permitted commercial redistribution.
In March 1992, Linux version 0.95 was the first to be capable of running X
Windows.
GNU Project
GNU software guarantees these freedom-rights legally (via its license), and is
therefore free software; the use of the word "free" always being taken to
refer to freedom.
In order to ensure that the entire software of a computer grants its users all
freedom rights (use, share, study, modify), even the most fundamental and
important part, the operating system (including all its numerous utility
programs), needed to be written.
Stallman decided to call this operating system GNU (a recursive acronym
"GNU's not Unix"), basing its design on that of Unix; however, in contrast to
Unix which was proprietary software, GNU was to be freedom-respecting
software (free software) that users can use, share, study and modify.
GNU
The GNU General Public License (GNU GPL or GPL) is the most widely used
free software license, which guarantees end users (individuals, organizations,
companies) the freedoms to use, study, share (copy), and modify the
software.
Software that ensures that these rights are retained is called free software.
The license was originally written by Richard Stallman founder of the Free
Software Foundation (FSF) for the GNU project.
Mascot of Linux
Linus Torvalds announced in 1996 that there would be a mascot for Linux, a
penguin.
This was due to the fact when they were about to select the mascot,
Torvalds did mention he was bitten by a Little Penguin on a visit to the
National Zoo & Aquarium, Canberra, Australia.
Tux is a penguin character and the official mascot of the Linux kernel.
Originally created as an entry to a Linux logo competition, Tux is the most
commonly used icon for Linux, although different Linux distributions depict
Tux in various styles.
The first person to call the penguin "Tux" was James Hughes, who said that
it stood for "(T)orvalds (U)ni(X)"
Advantages of Linux over Windows
Bugs are fixed quickly and help is readily available through the vast support
in Internet.
Linux is more stable than Windows. Linux is truly multi-user and multi-
tasking.
Low cost:
There is no need to spend time and huge amount money to obtain licenses
since Linux and much of it’s software come with the GNU General Public
License. There is no need to worry about any software that you use in Linux.
Stability:
Linux has high stability compared with other operating systems. There is no
need to reboot the Linux system to maintain performance levels.
Performance:
Compatibility:
It runs all common Unix software packages and can process all common file
formats.
Wider Choice:
The large number of Linux distributions gives you a choice. Each distribution
is developed and supported by a different organization. You can pick the one
you like best; the core functionalities are the same; most software runs on
most distributions.
Fast and Easy Installation:
Linux distributions come with user-friendly installation and setup programs.
Security:
Linux is one of the most secure operating systems. File ownership and
permissions make Linux more secure.
Open source:
Linux is an open source operating systems. You can easily get the source
code for Linux and edit it to develop your personal operating system.
Crash proof:
Linux has memory protection between processes, so that one program can't
bring the whole system down.
Today, Linux is widely used for both basic home and office uses. It is the
main operating system used for high performance business and in web
servers.
Linux has made a high impact in this world. Today, Linux systems are used in
every domain, from embedded systems to supercomputers.
No threat of viruses.
Linux is Free.
Linux Distributions
3 2006-07-20 2010-10-31
4 2009-03-31 2012-02-29
5 Q1 2014 2017-03-31
6 Q2 2017 2020-11-30
System Requirements
• 1 GHz processor
Installation of CentOS
1. First Screen
2. For CD check (Skip this)
3. Starting CENTOS
4. Chose Language
5. Use Basic Storage Devices
FSSTND
• The FSSTND (Filesystem Standard), a filesystem hierarchy standard
specific to the Linux operating system, was released on 14 February
1994.
What is File?
• Files are collection of data items stored on disk. Or, it's device which
can store the information, data, music (mp3 files), picture, movie,
sound, book etc.
• In fact what ever you store in computer it must be in the form of a file.
• Files are always associated with devices like hard disk ,floppy disk etc.
What is a directory?
• It is root of your entire file system and can not be renamed or deleted.
Sub directory - Directory under root (/) directory is sub directory.
Directories are used to organize your data files, programs more efficiently.
Primary hierarchy root and root directory of the entire file system
/
hierarchy.
Essential command binaries that need to be available in single user
/bin
mode; for all users, e.g., cat, ls, cp.
/boot Boot loader files, e.g., kernels, initrd.
/dev Essential devices, e.g., /dev/null.
Host-specific system-wide configuration files
There has been controversy over the meaning of the name itself. In
early versions of the UNIX Implementation Document from Bell
labs, /etc is referred to as the etcetera directory,[25] as this directory
historically held everything that did not belong elsewhere (however,
/etc
the FHS restricts /etc to static configuration files and may not contain
binaries).[26] Since the publication of early documentation, the
directory name has been re-designated in various ways. Recent
interpretations include backronyms such as "Editable Text
Configuration" or "Extended Tool Chest".[27]
/etc/opt Configuration files for /opt/.
/etc/sgml Configuration files for SGML.
/etc/X11 Configuration files for the X Window System, version 11.
/etc/xml Configuration files for XML.
/home Users' home directories, containing saved files, personal settings, etc.
/lib Libraries essential for the binaries in /bin/ and /sbin/.
Mount points for removable media such as CD-ROMs (appeared in
/media
FHS-2.3).
/mnt Temporarily mounted filesystems.
/opt Optional application software packages.[28]
Virtual filesystem providing information about processes and kernel
/proc
information as files. In Linux, corresponds to a procfs mount.
/root Home directory for the root user.
/sbin Essential system binaries, e.g., init, ip, mount.
/srv Site-specific data which are served by the system.
Temporary files (see also /var/tmp). Often not preserved between
/tmp
system reboots.
Secondary hierarchy for read-only user data; contains the majority of
/usr
(multi-)user utilities and applications.[29]
Non-essential command binaries (not needed in single user mode);
/usr/bin
for all users.
/usr/include Standard include files.
/usr/lib Libraries for the binaries in /usr/bin/ and /usr/sbin/.
Tertiary hierarchy for local data, specific to this host. Typically has
/usr/local
further subdirectories, e.g., bin/, lib/, share/.[30]
Non-essential system binaries, e.g., daemons for various network-
/usr/sbin
services.
/usr/share Architecture-independent (shared) data.
/usr/src Source code, e.g., the kernel source code with its header files.
/usr/X11R6 X Window System, Version 11, Release 6.
Variable files—files whose content is expected to continually change
/var during normal operation of the system—such as logs, spool files, and
temporary e-mail files.
Application cache data. Such data are locally generated as a result of
time-consuming I/O or calculation. The application must be able to
/var/cache
regenerate or restore the data. The cached files can be deleted without
loss of data.
State information. Persistent data modified by programs as they run,
/var/lib
e.g., databases, packaging system metadata, etc.
/var/lock Lock files. Files keeping track of resources currently in use.
/var/log Log files. Various logs.
/var/mail Users' mailboxes.
Information about the running system since last boot, e.g., currently
/var/run
logged-in users and running daemons.
Spool for tasks waiting to be processed, e.g., print queues and unread
/var/spool
mail.
/
Deprecated location for users' mailboxes.[citation needed]
var/spool/mail
/var/tmp Temporary files to be preserved between reboots
Lecture # 4 Shell Commands
Commands
• The first word is the command itself, which tells the shell “what” to
do. The remaining words are commands options. An option controls
“how” the command is to be performed.
Shell
• Shell is a UNIX term for the interactive user interface with an operating
system.
1. ls
Syntax
ls
Options
v. ls –t (sort by time)
ls –ld /home
2. cd (change Directory)
mkdir –p A/B/C/D/E/F/G
6. touch (to create a file a blank file and we can update any info of
existing file/directory)
7. file (this command is used for command to check the files status like
for what this file is created )
mv –rf file new-location (to move a created file from one location to
another it can mv files and folders)
mv –rf file new-name (to rename a created file it can rename files and
folders)
Note: - for creating hidden files we use “.” in front of name (.file / .folder),
for rename we use mv command.
“.” Single dot mean same location “..” double mean one step
back in directories
10. cat (To view contents of file, Also used to create new text file.)
Syntax
Options
Syntax
cp file1 file2
cp -f file1 file2 (to copy file forcely)
12. echo (To print the string on the screen, Also used to create file.)
Syntax
Syntax
Syntax
wc file-name
Options
16. clear (to clear the window or use Shortcut keys ctrl+l or we can
set any alias easy like cls then whenever we type cls it will clear it)
17. who (Print information about users who are currently
logged in)
19. more (To display the contents of the file from top to
bottom.)
Syntax
more file-name
Navigation keys
i. Enter key
20. less (To display the contents of the file, We can navigate
the page up and down line by line and page by page.)
Syntax
less file-name
Syntax
head file-name
Options
Syntax
tail file-name
Options
Syntax
commad1 | command2
ls -l | wc
ls -l /etc | less
Syntax
history
Options
25. tac (To view the contents of file in reverse, lines are reversed
not letters)
Syntax
Syntax
Options
Syntax
29. ps (To view the current running process. ps is the shortage for
Process Status. The command should be used to display the currently
running processes on Unix/Linux systems)
Syntax
pgrep service-name
Syntax
pidof firefox
Syntax
Syntax
locate file-name
Options
Syntax
du directory-name
Options
Syntax
du directory-name
Options
Syntax:
su user-name
38. date (To display and change the date and time.)
Syntax
date
Option
Syntax
i. ifconfig
Note: - 127.0.0.1 is a local-loop means every computer has same local loop.
Syntax:
Syntax:
Syntax
Syntax
ping <ip>
48. info (A command use to see info pages for a particular term. )
Syntax
49. man (This command is used to see the manual of any command)
50. & (To set as a background job.) = (command & ) (ping &)
52. bg (To view the all background running jobs. show the total
jobs. )
53. jobs (To view the all background running jobs. jobs show the jobs
in sequence)
• A text editor is any word processing program that you can use to type
and edit text.
Vi
Gedit
Nano
Vi Editor
• Developed in C
• Command mode.
• Insertion mode.
NOTE: Pressing <ESC> will place you in Normal mode or will cancel an
unwanted and partially completed command.
o (Editing Command)
To delete from the cursor up to the next word type :dw <ENTER>
To delete from the cursor to the end of a line type: :d$ <ENTER>
To delete a whole lines type: d<number of Lines>d <ENTER>
To repeat a motion prepend it with a number: 2w <ENTER>
To move to the start of the line use a zero: 0
To undo previous actions, type: u (lowercase u)
To undo all the changes on a line, type: U (capital U)
To undo the undo's, type: CTRL-R
To put back text that has just been deleted, type p . This puts the
deleted text AFTER the cursor (if a line was deleted it will go on the line
below the cursor).
To replace the character under the cursor, type r and then the
character you want to have there.
CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
Typing / followed by a phrase searches FORWARD for the phrase.
Typing ? followed by a phrase searches BACKWARD for the phrase.
o After a search type n to find the next occurrence in the same
direction or N to search in the opposite direction.
CTRL-O takes you back to older positions, CTRL-I to newer positions.
• This is a GNU replacement for pico. Works and looks like pico, but it is
smaller, better, and licensed under the General Public License.
What is package?
When Linux developers create their software they typically bundle all the
executable and data files into a single file called a "package" file.
Types of Packages?
source code packages : suite of files related to one program: source
code, documentation, and configuration files.
Binary packages: source code packages that have been configured for
a particular Unix variant or package manager program. Usually contains
compiled code targeted to a specific architecture.
• With root privilege, you can use the rpm command with appropriate
options to manage the RPM software packages.
3.23.57 – Version
1 – Release
i386 – Architecture
indicates this is a special architecture such that the files in the package
work on any architecture
When you install a RPM, it checks whether your system is suitable for
the software the RPM package contains, figures out where to install the
files located inside the rpm package, installs them on your system, and
adds that piece of software into its database of installed RPM
packages.
o -i : install a package
o -v : verbose
You can use rpm command to query all the packages installed
in your system.
rpm –qa
o -q query operation
rpm -q MySQL-client
Note: To query a package, you should specify the exact package name. If
the package name is incorrect, then rpm command will report that the
package is not installed.
Let us say, you have list of files and you would want to know
which package owns all these files. rpm command has options
to achieve this.
-f : file name
If you have an RPM file that you would like to install, but want
to know more information about it before installing, you can do
the following:
User friendly
It is useful to store a group of files in one file for easy backup, for
transfer to another directory, or for transfer to another computer. It is
also useful to compress large files; compressed files take up less disk
space and download faster via the Internet.
Linux provides the bzip2, gzip, and zip tools for compression from a
shell prompt.
You can use gzip to compress multiple files and directories at the
same time by listing them with a space between each one:
tar -cvf filename.tar file1 file2 file3 (To archiving multiple files.)
tar -cvf filename.tar dir1 dir2 dir3 (You can archiving multiple
files and directories at the same time.)
By default the tar command does not compress the files or directory. To
create a tar and bzip2 compressed file, use the -j option with tar.
You can also expand and decompressed a bzip2 tar file by using following
command:
Types of Links
1. Soft Link
2.Hard Link
1. Soft Link
• Refer to a symbolic path indicating the abstract location of another file
2. Soft link
• A soft link, like a Windows shortcut, becomes useless when you remove
the original file.
ln -s /path/to/file1.txt /path/to/file2.txt
Hard Link
Hard links cannot links directories.
What is inode
An inode (index node) is a data structure found in many Unix file systems.
Each inode stores all the information about a file system object.
ls -i /home/hiday/Desktop/file_name
Hard Link
ln source_file destination_file
ln {file.txt} {hard-link}
ln /tmp/file link-here
lecture # 09 Manage Users Accounts and Groups Working
with users and groups in Linux
Manage users and group
Linux groups
Username
Password
directory.
Other distributions may use a different numbering scheme for the UID.
It’s this UID that the operating system actually uses to control access
to files and directories in the file system.
Files in Which accounts and Groups info and Passwords
Store
/etc/passwd This file contains the user account information for your
system.
Using useradd
Using passwd
Using usermod
Using userdel
Options
From time to time, you will need to modify an existing user account.
The syntax for usermod is very similar to that used by useradd.
ID –nG any-user ( To view the Users groups in which he is add if we use –ng
then it shows only primary group but here it will show the primary and
secondary group)
Using groupmod (To Modify a group) (–g to change the group ID) (-A to
add the users) (-R to remove the Users) (groupmod –A group user-
name)
Pass_Min_Days 0
Pass_MIN_LEN 5
Pass_WARN_AGE 7
Note: - #Finger command show the user and its home directory but first we
have to install finger command
# Minimum User ID is 500 and maximum is 6000 and the system users
has 0 to 499 user IDS root has 0 user ID. Usergroups has the same name and
GID of groups and default those groups are there primary groups
#UMASK = Permission =Delegation. UMASK is set for all the user for
system users UMASK is 022 (it will be minus from 777 for directories and 666
for files), and for simple user this mask is 002. vi /etc/login.defs
#For making any user equal to root user then we have to change this
thing in thing sudores file “vi /etc/sudores” OR “visudo”. Here we are
doing Delegation mean we can give permission to users what task they can
perform like they can create users and they can change IP etc but they have
to use “sudo” word before command.
#if we don’t want to use sudo word then we have to write alias in
.bashrc file which is hidden and present in home directory of every user.
• Others (all the other users who are not the owner or member of
Note: Dot (.) in front of the name of any file indicates that this is
hidden file.
•Owner has the permission to read and write but can’t execute.
•Group can read and execute but don’t have the permission to
write.
•Others can also read and execute but don’t have the permission
Note: Hyphen (-) is placed in place of the permission that you want
First number ‘7’ will set the read, write and execute
permissions for the owner of the file/directory.
Third number ‘5’ will set the read and execute permissions for others.
syntax.
This command will only revoke the read and write permissions from the
owner (u),
execute permission from the group (g), and write permission from the
others (o).
This command will only add the write permission to the owner (u),
read permission to the group (g), and write and execute permissions
This command will only revoke the read and write permissions from
the owner (u), execute permission from the group (g), and write
But while using “+‟ and “-‟ symbols we are just adding or revoking
rwx rwxrwx
Note: While using “=“ symbol to set permissions, all the previous
r---w—wx
-wxr-x r--
Command
three entities i.e. Owner, Group, and Others. For example we have
r–-r–-r—
rw-rw-rw-
follows.
Sticky Bit is mainly used on folders in order to avoid deletion of a folder and its content by other
users though they having write permissions on the folder contents. If Sticky bit is enabled on a
folder, the folder contents are deleted by only owner who created them and the root user. No one
else can delete other users data in this folder(Where sticky bit is set). This is a security measure
to avoid deletion of critical folders and their content(sub-folders and files), though other users
have full permissions.
Example: Create a project(A folder) where people will try to dump files for sharing, but they
should not delete the files created by other users.
4. Symbolic way:
6. Let me explain above command, We are setting Sticky Bit(+t) to folder /opt/dump by
using chmod command.
7. Numerical way:
12. For example: /opt/dump/ listing before and after Sticky Bit set
14. ls -l
15. total 8
18. ls -l
19. total 8
25. $ ls -l /opt
26. total 8
28. if you observe other user is unable to delete the folder /opt/dump. And now content in this
folder such as files and folders can be deleted by their respective owners who created
them. No one can delete other users data in this folder though they have full permissions.
32.
33. so if you want executable permissions, Apply executable permissions to the file.
chmod o+x /opt/dump/
ls -l command output:
-rwxr-xrwt 1 xyz xyzgroup 0 Dec 5 11:24 /opt/dump/
Sticky bit with Executable permissions:
34.
35.
36.
37. you should see a smaller ‘t’ in the executable permission position.
38. How can I find all the Sticky Bit set files in Linux/Unix.
40. The above find command will check all the files which is set with Sticky Bit bit(1000).
41. Can I set Sticky Bit for files?
Sticky Bit
Chmod 1777 Dir_name (Sticky bit will give th access to everyone
“Other user who are not creator of that file/Dir and they are not
number of that group then those or will be called others) they can see
but they can’t delete any contents)
These are used for others can’t delete any file, in that
directory
Super Group ID
Super User ID
Chmod 4777 Dir_name (In this we can control user create files,
file creator and root user will control them.
Chattr
Note: - In Other T is shown when we put Sticky bit if others have permission
than it is “t” not capital but when others don’t have permission it is “T”
capital on “X”.
For UID,GID bit there is “s” when Group and owner have permission but
when they don’t have permission then there is “S” on “X”.
Lecture # 12 What is WINE (WINE(WINdows Emulator)
Is Not Emulator )
What is Wine?
Wine Stands for (Wine is Not Emulator)
HISTORY
The name WINE initially was an acronym for Windows Emulator.
As we know Linux Don’t support .exe format it only install .rpm format
(IN REDHAT)
Install wine
Wine uninstaller
Rune Levels
A run level is a state of init and the whole system that defines what
system services are operating after booting a system.
Runlevel 5 to 3
• id:5:initdefault: OR id:3:initdefault:
1. Restart PC
ITS DONE
2. Now you are again selection mode (select kernel word line and press
“e”)
3. Now what ever typed you just have to type “S” remember just “S” and
Enter
4. Now you are in signing in mode and you can change password
Lecture #13 Virtual Network Computing
VNC
• Virtual Network Computing is a remote display system which allows
you to view a computing `desktop' environment not only on the
machine where it is running, but from anywhere on the local area
network or Internet.
• VNC is platform-independent
• There are clients and servers for many GUI-based operating systems.
History
• VNC was originally developed at the Olivetti & Oracle Research Lab
in Cambridge, United Kingdom.
• The original VNC source code and many modern derivatives are open
source under the GNU General Public License.
What is VNC?
• The VNC server is the program on the machine that shares its screen.
The server passively allows the client to take control of it.
• The VNC client (or viewer) is the program that watches, controls, and
interacts with the server. The client controls the server.
• The VNC protocol (RFB) is very simple, based on one graphic
primitive from server to client ("Put a rectangle of pixel data at the
specified X,Y position") and event messages from client to server.
Install VNC
• id
VNC Client
OR
• Go to
• Applications>Internet>TigerVNC Viewer
• To access the server desktop give the server’s IP with id of
that user and give the password.
Password of any user will be set for first id only other ids of same user will be
use same password.
• But if any other user will create new id he should set the password for
his id.
• All the VNC user’s id, password and log files stored in their home
directory
• /root/.vnc OR /home/hidaya/.vnc
• .vnc is hidden directory which stores the information of vnc user’s id,
password and log file.
4. now vnc client can access your computer with the id and password you
gave him, client will type this in VNC Tigerviewer
192.168.2.120:3
Lecture # 14 SSH (Secure Shell )
Secure SHell (SSH)
SSH is a protocol for secure remote access/login and other secure network
services to a machine over untrusted networks.
Commercial version
Freeware (www.openssh.com)
To run a secure shell on or securely copy a file to/from a remote system, the
following criteria must be met:
When you connect to an OpenSSH server for the first time, the
OpenSSH client prompts you to confirm that you are connected
to the right system. This checking can help prevent a man-in-the-
middle attack.
OpenSSH clients and servers rely on many files. Global files are kept in
/etc/ssh and user files in ~/.ssh
The ssh and scp clients do not require setup beyond installing the
requisite packages,
although you can create and edit files that facilitate their use. To run a
secure shell on or securely copy a file to/from a remote system, the following
criteria must be met: The remote system must be running an RFC-compliant
sshd daemon such as OpenSSH, you must have an account on the remote
system, and the server must positively identify itself to the client.
then giving an exit command to return to the shell on the local system
[email protected] password:
The first time you connect to a remote OpenSSH server, ssh or scp
asks you to confirm that you are connected to the right system
The following example copies file.txt from the working directory on the local
system to
[email protected] password:
The following example runs ls in the hist directory on the remote system
192.168.2.63
The example assumes that the user running the command ( has a login on
Or
The scp utility asks you for a password when one is required. The
format of an scp command is
• Vi /etc/hosts.deny
• Sshd: 192.168.2.12
RSA vs DSA
Lecture #15 PuTTy
What is PuTTy?
Install Putty
Putty is used in linux it is cross plateform just from windows to linux but we
can’t communicate linux to windonw.
Configuration files
/etc/ssh/ssh_config/.ssh/config
/etc/ssh/sshrc
/etc/rsh
/etc/passwd (it contains info about all the created users including
their ID’s and group ID complete name and home directories and login bash)
• Vi /etc/hosts.deny
• Sshd: 192.168.2.12
Lecture # 16 SCP and SFTP
SCP = Securely CoPy
passwd:
Sftp>
Now use commands here like checking which files are present here and
we can download and even we can upload from here
To Download
IPV4
IPV
Loop Back IP
127.0.0.1
Subnet Mask
A mask used to determine what subnet an IP address belongs to. An IP
address has two components, the network address and the host address.
All nodes (hosts) in a subnetwork see all packets transmitted by any node in
a network. Performance of a network is adversely affected under heavy
traffic load due to collisions and re transmissions
Subnet
The default Class C mask is: 255.255.255.0. To make smaller networks, called
subnetworks, we will borrow bits from the host portion of the mask. Since the Class
C mask only uses the last octet for host addressing, we only have 8 bits at our
disposal. Therefore, only the following masks can be used with Class C networks .
Class C Sub-netting
You can see that the bits that are turned on (1s) are used for
subnetting, while the bits that are turned off (0s) are used for addressing of
hosts. You can use some easy math to determine the number of subnets and
hosts per subnet for each different mask.
To determine the number of subnets, use the 2x, where the x exponent
is the number of subnet bits in the mask.
To determine the number of hosts, use the 2x-2, where the x exponent is the
number of host bits in the mask.
For example, if you have eight networks and each requires 10 hosts,
you would use the Class C mask of 255.255.255.240. Why? Because 240 in
binary is 11110000, which means you have four subnet bits and four host
bits. Using our math, we’d get the following:
24=16 subnets
24-2=14 hosts
128+64+32+16+8+4+2+1
1 1 0 0 0 0 0 0
You can see that the bits that are turned on (1s) are used for subnetting,
while the bits that are turned off (0s) are used for addressing of hosts.
NFS is an excellent way of sharing files between Linux and other UNIX
systems.
Installation of NFS
Make a directory in root “/” directory and put data or files which you want to
share.
mkdir /dir
• vi /etc/exports
• /system *(rw,no_root_squash)
• exportfs
• showmount -e 192.168.2.115
• mkdir /mnt/system
Permanent mounting
• vi /etc/fstab
Chkconfig --list nfs (To show the list of nfs booting time in all
the run levels)
File: vi /etc/sysconfig/network-scripts/ifconfig-eth0
Lecture # 19 LAMP (Linux Apache Mysql
PHP/Python/Perl/PgSQL)
LAMP is mostly used around the world whether you use Google, Facebook,
Yahoo etc. Most of the world’s top websites are running on this because here
user have authorities to do anything on his wish, but other platform’s are not
free and independent like this, so whenever you want to change something
deeply than you need to review your license or order for another license
mean more money. But in Linux platform no need of special licenses they all
are free for use and their code is also present and they want you to change
on your requirement by your own self.
http://toolbar.netcraft.com/site_report?url=http://www.google.com
Use above site to check about your desired site which platform they are
using.
Highly Scalable
Open Source
Low costs
Great Performance
But Then
Why are still few companies
afraid
of switching to it?
Linux
Very reliable OS
Extremely powerful
Scalable
No piracy issues
Apache
Largest Market share holder for web servers since 1996 and still growing.
Since April 1996 Apache has been the most popular HTTP server software
in use. As of June 2013, Apache was estimated to serve 54.2% of all active
websites and 53.3% of the top servers across all domains.
Although the main design goal of Apache is not to be the "fastest" web
server, Apache does have performance similar to other "high-
performance" web servers.
Written in C
Available in English
MYSQL
World’s Fastest growing open source database servers.
PHP
Open Source server-side scripting language designed specifically for the
web.
Outputs not only HTML but can output XML, images (JPG & PNG), PDF files
and even Flash movies (using libswf and Ming) all generated on the fly.
Can write these files to the filesystem.
Supports a wide-range of databases (20 + ODBC).
Installation of Apache
Documentation
• /etc/httpd/conf/httpd.conf
• /var/www/html
The term Virtual Host refers to the practice of running more than one
web site (such as www.company1.com and www.company2.com) on a
single machine
Using Apache Virtual Host, you can run several websites on the same
server.
For example, I can run both abc.com and xyz.com on a single physical
server that has one Apache webserver running on it.
This means that the server should have two ethernet cards, each one
of them configured to the ip-address of the corresponding website that
Apache virtual host will be serving. So, this is not practical for most
aspects, and you should not be using this.
In the following example, the server contains two NIC cards. one is
configured with 192.168.1.1 ip-address for abc.com, another is
configured with 192.168.1.2 for xyz.com. Both these ip-address are
served by a single Apache webserver running on that server using IP-
Based virtual host.
This is very easy, as you need only one ip-address on that physical
server; but, you update the DNS with multiple website names pointing
to the same ip-address. For all practical purpose, you’ll be using only
Name-based virtual host configuration.
In the following example, the server contains only one NIC card, which
is configured with 192.168.1.1 ip-address.
The DNS entry for both abc.com and xyz.com website points to
192.168.1.1 ip-address. When Apache recives a request, it looks for the
hostname entry in the HTTP header, and serves the corresponding
website.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/vhost/abc/
ServerName abc.com
ErrorLog /var/www/abc/logs/access_log
#These Files on Location should be create by own self. These access log and
error logs files are used to view who has been visiting our sites and what he
has been downloading.
</VirtualHost>
NameVirtualHost *:80 – Indicates that all the name-based virtual hosts
will be listening on the default port 80
Note: if we want to access any site that is hosted on any single computer
than we have to change in /etc/hosts file and type something like following.
# Now give desired passwd that you want, and give him the authority
of that folder and subfolders with following command
# -R used for recursively mean if there is sub-files and folders than they will
be owned by ali user. Now add apache user in ali user than apache can open
that site of yours. Now restart service of httpd.
# If you want a user whose home directory is in /home/ali than use following
commands.
[root@sul]# getsebool
# Now apache can read files from users whom directory otherwise
apache can’t read them.
Lecture # 21 FTP (FILE TRANSFER PROTOCOL)
• File Transfer Protocol (FTP) is a standard network protocol used to
transfer files from one host to another host over a TCP-based network,
such as the Internet.
Install vsftpd
Turn on vsftpd
• Service vsftpd start/restart/reload/stop/status
• chkconfig vsftpd on
OR
ftp://192.168.2.119 #computers IP
ftp://localhost
FTP://hostname
• Yum install gftp = These Software’s are used to download the files that
you want to change and then change the file and re upload it.
What is Data?
What is a Database?
Provides an interface through which we can issue SQL statements and have
the results displayed.
What is DDL?
Data Definition Language (DDL) describes the portion of SQL that allows you to create,
alter, and destroy database objects.
What is DML?
Data Manipulation Language (DML) describes the portion of SQL that allows
you to manipulate or control your data.
What is DQL?
The SELECT statement retrieves data from the database. Following are the clauses of the
statement, which are demonstrated in the following sections:
MySQL
MySQL "My S-Q-L" officially, but also called "My Sequel“
OS: Cross-platform
Port no 3306
Features Of Mysql
Install
# mysql -u <username>
# mysql -h <hostname>
# mysql -D <database>
# mysql -p <password>
TRUNCATE student;
DML Statement
DML - Data Manipulation Language. It is used to retrieve, store, modify,
delete, insert and update data in the table.
DQL Statements
DQL – Data Query Language is used to query the information from a
database or table.
USE database hidaya; #By the help of this we can set any
database
History
Tobias Ratschiller, an IT consultant and later founder of the
software company Maguma, started to work on a PHP-based web front-end
to MySQL in 1998, inspired by MySQL-Webadmin.
PHPMyADMIN
Developer(s) The phpMyAdmin Project
Operating systemCross-platform
Features
Web interface
create, copy, drop, rename and alter databases, tables, fields and indexes
Install phpmyadmin
Configuration
• vi /etc/httpd/conf.d/phpMyAdmin.conf
<Directory "/usr/share/phpMyAdmin">
Order allow,deny
</Directory>
Lecture # 23 SAMBA
• Samba is software that can be run on a platform other than Microsoft
Windows, for example, UNIX, Linux, IBM System 390, OpenVMS, and
other operating systems.
• Samba uses the TCP/IP protocol that is installed on the host server.
When correctly configured, it allows that host to interact with a
Microsoft Windows client or server as if it is a Windows file and print
server.
• Samba provides file and print services for Microsoft Windows clients.
Samba
Initial release 1992
Samba Configuration
[My-share]
path = /share
browseable = yes
writable = no
Configuring the samba server at Linux side to share data “/share” for
Microsoft windows systems over the network.
Sharing files
Linux side.
• 1. SMB mode.
• 2. Mounting
1. SMB mode
Mounting
Permenant mounting
vi /etc/fstab
• To permanent mount.
Lecture # 23 DHCP
DYNAMIC HOST CONFIGURATION PROTOCOL
DHCP uses the concept of a "lease" or amount of time that a given IP address
will be valid for a computer. The lease time can vary depending on how long a user
is likely to require the Internet connection at a particular location. It's especially
useful in education and other environments where users change frequently.
Using very short leases, DHCP can dynamically reconfigure networks in which
there are more computers than there are available IP addresses. The protocol also
supports static addresses for computers that need a permanent IP address, such as
Web servers
Normally the DHCP server provides the client with at least this basic
information:
IP Address
Subnet Mask
Default Gateway
Dns
Discover = When the computer start it search for DHCP then he Discover
and send a request.
Request: In response to the offer, the Client will requests for an ip address.
DHCP PORTS
DHCP client, is executed on the client machine, it begins broadcasting
requests for configuration information. By default, these requests are on UDP port
68. The server replies on UDP 67, giving the client.
Assign a static ip (eg: “192.168.2.119″) in the same DHCP range for the
listening interface ( eg : “eth0″ ).
Now open /etc/sysconfig/dhcpd file and add the preferred interface name to
DHCPDARGS variable as below
# Command line options here DHCPDARGS=eth0
DHCP Configuration
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
#Default gateway ip
Fixed IP Address
host Printer01 {
fixed-address 192.168.1.55;
}
Service of DHCP
[root@localhost ~]# service dhcpd start/stop/status/reload
Note: Clients can get IP from DHCP server and Please ensure you don’t have any
other dhcp servers in the same network.
Practice
1. # yum install *dhcp*
2. After installation go and make an Ethernet active for dhcp so which can take
request from all the users and that ip will be responsible as DHCP, we use
these things when a computer have multiple Ethernet cards.
3. # vi /etc/sysconfig/dhcpd
DHCPDARGS= eth0
4. Now as DHCP work as an server the server should have an static IP that why
go in this file and do some changing.
5. Vi /etc/sysconfig/network-scripts/ifcfg-eth0
a. Device =eth0
b. BOOTPROTO=static
c. NM_CONTROLLED=”yes”
d. TYPE =”Ethernet”
e. UUID=”68e53b-2a58-4644-9904-31359f9bffe8
f. DEFROUT =”Yes”
g. IPV4_FAILURE_FATAL=”YES”
h. IPV6INT=”no”
i. NAME=”System eth0”
j. IPADDR=192.168.2.119
k. Prefix =24
l. GATEWAY =192.168.2.1
m. DN1=00:21:9b:2b:b9:2e
n. LAST_CONNECT=1374081461
a. Vi /etc/resolve.conf
c. nameserver 192.168.2.1
a. Remove comments simple from 8,9 line and 32 line where following
lines are present.
rtr-239-0-1example.org;
host any-hostname
• IP Tables is used to set up, maintain, and inspect the tables of IPv4 packet
filter rules in the Linux kernel.
• Each chain is a list of rules which can match a set of packets. Each rule
specifies what to do with a packet that matches. This is called a `target',
which may be a jump to a user-defined chain in the same table.
• Understanding how to setup and configure IP Tables will help you manage
your Linux firewall effectively.
• So, the structure is: IPTABLES -> TABLES -> CHAINS -> RULES
Types Of IPTABLES
Filter Table:
• This is the default table which contains three chains.
• INPUT Chain: To apply a rule on packets which are coming into the
system
NAT Tables
• OUTPUT Chain: For packets locally generated which are going out
from the system.
Mangle Table
• PREROUTING
• OUTPUT
• INPUT
• FORWARD
• POSTROUTING
IPTABLES
• Chains have some rules
• iptables
Iptables Option
• -p (protocol)
• -d (destination)
• -j (jump to target)
• -s (source)
• -i (in-interface)
• -o (out-interface)
• iptables -L
• iptables -L -vn .
To flush/delete all IPTables rules.
• iptables -F
PRACTICE
--line-number All rules are numbers shown then we can add new rules
below or above them, or we can remove them from the list of IPTABLE, the rules are
applied/read by computer from top to bottom.
-A Append the rule in last but if we want to add some rules in the top then we
must use –I (capital i).
OR
This rule will work same as above but if it is on the first line or before such lines
those allow the users.
OR
#iptables -F INPUT (It will Flush all the rules of INPUT chain)
#Host –ta histpk.org or #host histpk.org (this will give all the info
about histpk server)
(It will Block all the requests from our computer to anyother ftp 20 is a vsftpd
outgoing port)
(It will Block all the requests from others computers to our ftp 21 is a vsftpd
incoming port)
(-s= source)
Following command will not response the PING request (icmp is the protocol of ping)
(Above rule will allow the range of IPz to communicate, other IPz will not be
connected).
To change the Table, because Filter is the Default table of chains, we can change
this.
#iptables -t mangle -L
Configuration File of IPTABLES
# vi /etc/sysconfig/iptables
Above rules will work for temporary time, but if we want to do it for permanent then
we use.
#/etc/init.d/iptables save
Save iptables rules in backup/simple file for later use on another system or on the
same system.
To drop the entire incoming request, this command will make the drop policy default
for INPUT/incoming traffic.
Iptables is used from kernel 2.4 now we use kernel 4.6 in centos 6.3 version.
Some firewall are used in industry level (IP Cops, Smooth Wall)
Lecture # 26 Shell Scripting
Kernel
Kernel is the core component of Linux OS. It manages resource of Linux OS. It
provides facilities for example, facility to store data, print data on printer,
memory, file management etc.
Kernel decides who will use this resource, for how long and when.
Shell
• Shell is the interpreter between User and Linux Kernel.
• Shell is not a part of system kernel, but uses the system kernel to execute
programs.
Shell Scripting
• Normally shells are interactive. It means shell accept command from you (via
keyboard) and execute them. But if you use command one by one (sequence
of number of commands) , you can store this sequence of command to a text
file and tell the shell to execute this text file, This is know as shell script.
• Practically all modern operating system shells can be used in both interactive
and batch mode, the latter usually by specifying the name of a text file with
commands listed therein.
• Shell script can take input from user/file and output them on screen.
Shebang
#!/bin/bash Poem (Hash “#” Not “!” Slash “/” Bin “bin” Slash “/” Bash
“bash”)
• Use any editor like vi, nano or gedit to write shell script.
• After writing shell script set execute permission for your script as follows,
because simple file doesn’t have permission.
• ./script-file
• sh script-file
• bash script-file