684 BNCSC502
684 BNCSC502
Study Material
(Linux Administration-II and BNCSC502)
_____________________________________________________________________________________________
Table of Contents
1
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Disk space is a finite and shared resource (even considering the enormous increases in hard-disk technology in
recent years).
Disk quotas are needed in home directory partitions for various reasons:
There is a limited amount of disk space that must be shared between many people.
Some people tend to use much more disk space than they need, and far beyond what is reasonable and fair
for a shared resource.
Sometimes processes can go out of control and produce huge amounts of data. If a disk fills up, no more
data will be able to be saved, and people will lose work; for instance, someone who has been working with
an editor may not be able to save their changes.
For these reasons and others, it is necessary for the CSL staff to manage home directory space. Disk quotas are an
equitable way of doing this.
There are two types of quotas that are set on home directories via the UNIX disk quota system: block quotas and
file quotas.
A block quota is the limit on the actual amount of disk space that can be used by an account. This space is
measured in 1 KB blocks (1 KB = 1024 bytes or characters). All files, directories, etc., use up some number
of blocks.
A file quota is the limit on the number of files, directories, etc., that there can be for an account. This is because
each file system (eg, /home/home1/) has a finite sized inode table, and
each file system object (such as a file or directory) uses up one inode. When this table gets filled up, no
more files can be created.
While it is not uncommon for someone to exhaust their blocks quota, it is quite unusual for anyone to use up their
file’s quota.
user@login> quota -v
minerva:/vol/vol0/insitu4
2
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
quota The quota for blocks; you will start getting warnings when you exceed this amount.
limit The hard quota for blocks; you cannot exceed this limit under any circumstances.
grace The amount of time you have left to get back below your blocks soft quota before UNIX starts getting
angry.
quota The soft quota for files; you will start getting warnings when you exceed this amount.
limit The hard quota for files; you cannot exceed this limit under any circumstances.
grace The amount of time you have left to get back below your files soft quota before UNIX starts getting
angry.
Remember to use the -v option with the quota command. See the quota man page for more information.
Disk quotas can be configured for individual users as well as user groups. This makes it possible to manage the space
allocated for user-specific files (such as email) separately from the space allocated to
the projects a user works on (assuming the projects are given their own groups).
In addition, quotas can be set not just to control the number of disk blocks consumed but to control the number of
inodes (data structures that contain information about files in UNIX file systems). Because inodes are used to contain
file-related information, this allows control over the number of files that can be created.
Enabling Quotas
1. Log in as root.
2. Edit the /etc/fstab file.
3. Add either the usrquota or grpquota or both options to the file systems that require quotas.
Edit /etc/fstab
3
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
For example, to use the text editor vim type the following:
# vim /etc/fstab
Add Quotas
Note
The following examples assume that a separate /home partition was created during the installation of Red Hat
Enterprise Linux. The root (/) partition can be used for setting quota policies in the /etc/fstab file.
Run the umount command followed by the mount command to remount the file system. See the man page
for both umount and mount for the specific syntax for mounting and unmounting various file system types.
If the file system is currently in use, the easiest method for remounting the file system is to reboot the system.
The quotacheck command examines quota-enabled file systems and builds a table of the current disk usage per file
system. The table is then used to update the operating system's copy of disk usage. In addition, the file system's disk
quota files are updated.
1. Create the quota files on the file system using the following command:
# quotacheck -cug /file system
2. Generate the table of current disk usage per file system using the following command:
# quotacheck -avug
4
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
c:- Specifies that the quota files should be created for each file system with quotas enable.
g: Checks for group quotas. If only -g is specified, only the group quota file is created.
If neither the -u or -g options are specified, only the user quota file is created.
The following options are used to generate the table of current disk usage:
After quotacheck has finished running, the quota files corresponding to the enabled quotas (either user or group or
both) are populated with data for each quota-enabled locally-mounted file system such as /home.
Prerequisite
For example, if a quota is enabled in /etc/fstab for the /home partition (/dev/VolGroup00/LogVol02 in the following
example) and the command edquota testuser is executed, the following is shown in the editor configured as the
default for the system:
5
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
The first column is the name of the file system that has a quota enabled for it. The second column shows how many
blocks the user is currently using. The next two columns are used to set soft and hard block limits for the user on
the file system. The inodes column shows how many inodes the user is currently using. The last two columns are
used to set the soft and hard inode limits for the user on the file system.
The hard block limit is the absolute maximum amount of disk space that a user or group can use. Once this limit is
reached, no further disk space can be used.
The soft block limit defines the maximum amount of disk space that can be used. However, unlike the hard limit,
the soft limit can be exceeded for a certain amount of time. That time is known as the grace period. The grace period
can be expressed in seconds, minutes, hours, days, weeks, or months.
If any of the values are set to 0, that limit is not set. In the text editor, change the desired limits.
For example:
# quota testuser
Disk quotas for user username (uid 501):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb 1000* 1000 1000 0 0 0
Prerequisite
For example, to set a group quota for the user1 group, use the command:
# edquota -g user1
This command displays the existing quota for the group in the text editor:
To verify that the group quota has been set, use the command:
# quota -g user1
If a given quota has soft limits, you can edit the grace period (i.e. the amount of time a soft limit can be exceeded)
with the following command:
# edquota -t
This command works on quotas for inodes or blocks, for either users or groups.
7
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
8
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
c. The amount of disk space a user is denied d. The amount of disk space a user is allowed
from using. to use.
15. The process of dividing a disk into sectors that the disk controller can read and write, before a disk can
store data is known as ____________
a. Partitioning b. Swap space creation
c. Low-level formatting d. None of the mentioned
16. The two steps the operating system takes to use a disk to hold its files are _______ and ________
a. Partitioning & logical formatting b. Swap space creation & caching
c. Caching & logical formatting d. Logical formatting & swap space creation
4. How do I view the current disk quota usage for a user or group?
5. How can I enforce soft and hard limits in disk quotas?
6. What happens when a user exceeds their disk quota in Linux?
7. How can I increase or decrease disk quotas for users or groups?
8. Is it possible to exclude certain files or directories from disk quotas?
9. What are the differences between user-based and group-based disk quotas?
10. How do I generate reports on disk quota usage for users?
11. Can I set up automatic notifications when users approach their disk quota limits?
12. How can I disable or remove disk quotas from a Linux system?
13. What is aquota.user and aquota.group? How will they create?
14. What does edquota and quotacheck do in Linux? Give proper example
15. Define hard and soft space limits with example.
16. Define grace period and what is the way to change it?
10
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Computer Network: -
Definition: - A network is a group of two or more connected computing devices that can share resources such as
files, printers, and applications. Networks can be classified into different types based on their size, purpose, and the
technology used to connect the devices.
Types: -
Local area networks (LANs): LANs are small networks that are confined to a single location, such as a home, office,
or school.
Metropolitan area networks (MANs): MANs are larger networks that cover a city or metropolitan area.
Wide area networks (WANs): WANs are the largest type of networks and can cover an entire country or even the
world.
Personal area networks (PANs): PANs are very small networks that connect devices that are close to each other,
such as smartphones, laptops, and printers.
Wireless networks: Wireless networks use radio waves to connect devices without the need for cables.
Understand IP Addresses
An IP address is an address used in order to uniquely identify a device on an IP network. The address is made up of
32 binary bits, which can be divisible into a network portion and host portion with the help of a subnet mask. The
32 binary bits are broken into four octets (1 octet = 8 bits). Each octet is converted to decimal and separated by a
period (dot). For this reason, an IP address is said to be expressed in dotted decimal format (for example,
172.16.81.100). The value in each octet ranges from 0 to 255 decimal, or 00000000 - 11111111 binary.
Here is how binary octets convert to decimal: The right most bit, or least significant bit, of an octet holds a value of
20. The bit just to the left of that holds a value of 21. This continues until the left-most bit, or most significant bit,
which holds a value of 27. So if all binary bits are a one, the decimal equivalent would be 255 as shown here:
11111111
128 64 32 16 8 4 2 1 (128+64+32+16+8+4+2+1=255)
Here is a sample octet conversion when not all of the bits are set to 1.
01000001
0 64 0 0 0 0 0 1 (0+64+0+0+0+0+0+1=65)
And this sample shows an IP address represented in both binary and decimal.
10. 1. 23. 19 (decimal)
11
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
00001010.00000001.00010111.00010011 (binary)
Given an IP address, its class can be determined from the three high-order bits (the three left-most bits in the first
octet). Figure 1 shows the significance in the three high order bits and the range of addresses that fall into each
class. For informational purposes, Class D and Class E addresses are also shown.
Figure 1
In a Class A address, the first octet is the network portion, so the Class A example in Figure 1 has a major network
address of 1.0.0.x - 127.255.255.x (where x can go from 0 to 255). Octets 2, 3, and 4 (the next 24 bits) are for the
network manager to divide into subnets and hosts as he/she sees fit. Class A addresses are used for networks that
have more than 65,536 hosts (actually, up to 16777214 hosts!).
In a Class B address, the first two octets are the network portion, so the Class B example in Figure 1 has a major
network address of 128.0.0.x - 191.255.255.x. Octets 3 and 4 (16 bits) are for local subnets and hosts. Class B
addresses are used for networks that have between 256 and 65534 hosts.
12
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
In a Class C address, the first three octets are the network portion. The Class C example in Figure 1 has a major
network address of 192.0.0.x - 223.255.255.x. Octet 4 (8 bits) is for local subnets and hosts - perfect for networks
with less than 254 hosts.
Network Masks
A network mask helps you know which portion of the address identifies the network and which portion of the
address identifies the node. Class A, B, and C networks have default masks, also known as natural masks, as shown
here:
Class A: 255.0.0.0
Class B: 255.255.0.0
Class C: 255.255.255.0
An IP address on a Class A network that has not been subnetted would have an address/mask pair similar to:
10.20.15.1 255.0.0.0. In order to see how the mask helps you identify the network and node parts of the address,
convert the address and mask to binary numbers.
10.20.15.1 = 00001010.00010100.00001111.00000001
255.0.0.0 = 11111111.00000000.00000000.00000000
Once you have the address and the mask represented in binary, then identification of the network and host ID is
easier. Any address bits which have corresponding mask bits set to 1 represent the network ID. Any address bits
that have corresponding mask bits set to 0 represent the node ID.
10.20.15.1 = 00001000.00010100.00001111.00000001
255.0.0.0 = 11111111.00000000.00000000.00000000
-----------------------------------
net id | host id
netid = 00001010 = 10
hostid = 00010100.00001111.00000001 = 20.15.1
Understand Subnetting
Subnetting allows you to create multiple logical networks that exist within a single Class A, B, or C network. If you
do not subnet, you are only able to use one network from your Class A, B, or C network, which is unrealistic.
Each data link on a network must have a unique network ID, and every node on that link is a member of the same
network. If you break a major network (Class A, B, or C) into smaller subnetworks, it allows you to create a network
of interconnecting subnetworks. Each data link on this network would then have a unique network/subnetwork ID.
13
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Any device, or gateway, that connects n networks/subnetworks has n distinct IP addresses, one for each network /
subnetwork that it interconnects.
In order to subnet a network, extend the natural mask with some of the bits from the host ID portion of the address
in order to create a subnetwork ID. For example, given a Class C network of 192.168.5.0 which has a natural mask
of 255.255.255.0, you can create subnets in this manner:
192.168.5.0 - 11001100.00010001.00000101.00000000
255.255.255.224 - 11111111.11111111.11111111.11100000
--------------------------|sub|----
By extending the mask to be 255.255.255.224, you have taken three bits (indicated by "sub") from the original host
portion of the address and used them to make subnets. With these three bits, it is possible to create eight subnets.
With the other five host ID bits, each subnet can have up to 32 host addresses, 30 of which can actually be assigned
to a device since host ids of all zeros or all ones are not allowed (it is very important to remember this). So, with
this in mind, these subnets have been created.
192.168.5.0 255.255.255.224 host address range 1 to 30
192.168.5.32 255.255.255.224 host address range 33 to 62
192.168.5.64 255.255.255.224 host address range 65 to 94
192.168.5.96 255.255.255.224 host address range 97 to 126
192.168.5.128 255.255.255.224 host address range 129 to 158
192.168.5.160 255.255.255.224 host address range 161 to 190
192.168.5.192 255.255.255.224 host address range 193 to 222
192.168.5.224 255.255.255.224 host address range 225 to 254
Networking in Linux
1. Linux has a very strong set of networking tools and features.
2. These tools allow you to configure and manage your network, as well as troubleshoot network problems.
3. Some of the most important networking tools in Linux include:
ifconfig
:- This command is used to configure network interfaces.
route
:- This command is used to manage routing tables.
ip :- This command is a newer version of ifconfig that provides more features.
ping
:- This command is used to test network connectivity.
traceroute
:- This command is used to trace the path of a packet through a network.
4. Linux also includes a number of networking services, such as DHCP, DNS, and SSH.
14
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
5. These services provide essential functionality for networking, such as assigning IP addresses to devices,
resolving hostnames to IP addresses, and providing secure remote access.
In RHEL 8 (Red Hat Enterprise Linux 8), network-related configurations are primarily managed through various files
in the /etc/sysconfig/network-scripts/ directory. Below are some of the important network-related files in RHEL 8:
-
15
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
1. Identify the network interface. :- The first step is to identify the network interface that you want to
configure. You can do this by running the ifconfig command.
2. Edit the network configuration :- The next step is to edit the network configuration file for the interface.
file. The default location of the network configuration file is
/etc/sysconfig/network-scripts/ifcfg-eth0.
3. Configure the network :- The following parameters need to be configured in the network
parameters. configuration file:
DEVICE: The name of the network interface.
BOOTPROTO: The method used to obtain the IP address for the
interface. The possible values are dhcp, static, and none.
IPADDR: The IP address of the interface.
NETMASK: The netmask of the interface.
GATEWAY: The gateway for the interface.
DNS1: The primary DNS server for the interface.
DNS2: The secondary DNS server for the interface.
ONBOOT: Whether the interface should be brought up at boot time.
4. Save the network configuration Once you have configured the network parameters, you need to save
file the network configuration file.
5. Restart the network service Once you have saved the network configuration file, you need to
restart the network service. You can do this by running the following
command:
sudo service network restart
6. Test the network connection Once you have restarted the network service, you need to test the
network connection. You can do this by running the following
command:
ping 8.8.8.8
If you are able to ping the Google DNS server, then the network
connection has been successfully configured.
16
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DNS2=8.8.8.8
ONBOOT=yes
NetworkManager: The default tool for managing network interfaces and connections in RHEL-8.
Components:
Using nmcli:
Using nmtui:
nmtui provides a text-based user interface for configuring and managing network connections.
NETWORK TROUBLESHOOTING
When troubleshooting network problems, it is important to have a good understanding of the Linux networking
tools and features.
You should also be familiar with the different types of network problems that can occur.
Some of the most common network problems include:
17
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
o Connectivity problems: These problems prevent you from connecting to other devices on the network.
o Routing problems: These problems prevent packets from reaching their destination.
o Name resolution problems: These problems prevent you from resolving hostnames to IP addresses.
There are a number of tools and techniques that you can use to troubleshoot network problems.
Some of the most common tools include:
ping: This command is used to test network connectivity.
traceroute: This command is used to trace the path of a packet through a network.
18
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
19
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
20
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
21
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Question
Correct Answer
Number
1. b. Kernel
2. a. 5
3. b. 7
4. d. Session and Presentation layer
5. a. End system
6. a. End system
7. d. All of the above
8. b. Session layer
9. d. Session layer
10. a. Application layer
11. b. Removed
12. a. 10.0.0.0-10.255.255.255
13. c. 192.168.24.58/30
14. d. /etc/sysconfig/network
15. a. Netmask
16. b. /etc/hosts
17. c. /etc/resolv.conf
18. b. Medium
19. a. Protocols
20. b. Multipoint
21. b. distributed system
22. a. broadcast network
23. a. personal area network
24. c. router
25. a. bit-by-bit delivery
26. d. all of the mentioned
27. c. packets
28. d. error control
29. a. Classless Addressing
30. a. setup
31. c. /etc/sysconfig/network-scripts/ifcfg-eth0
32. a. Static
22
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
23
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
History of DNS
ARPANET utilized a central file hosts.txt. It contains names to addresses mapping & Maintained by SRI’s NIC
(Stanford-Research-Institute: Network-Information-Center)
Administrators email changes to NIC. NIC updates hosts.txt periodically. Administrators FTP (download) hosts.txt
In 1984, Paul Mockapetris released the first version (RFCs 882 and 883, superseded by 1034 and 1035 …)
Introduction to DNS
A server to translate IP aliases to addresses. As you know, IP (internet protocol) works by providing every Internet
machine with a unique address as humans, we tend not to be able to remember lengthy strings of numbers so it’s
easier for us to name our machines. DNS allows us to reference machines by name and still use IP.
DNS servers exist across the Internet (globally), however, within a given domain, you might have a DNS that breaks
that domain into subdomains. For instance, NKU is a domain known by the global DNS’s but within NKU, we might
have cs.nku.edu and it.nku.edu and library.nku.edu, etc. These subdomains are known by our DNS, which then can
pass this information onto other DNS’s around the world.
DNS requests use UDP (user datagram protocol) and typically communicate over port 53 to DNS servers both request
and response are usually single UDPs.
The structure of DNS’s is tree-like. when you want to translate an IP alias to address, you ask your local DNS to
perform the lookup of the given domain. If that information is not available locally, the DNS asks its nearest neighbor
DNS, which will be one level higher. If that DNS does not have the information, it asks its next nearest neighbor
(again, one level higher). Ultimately, if no DNS has the information on the path up the tree, you get an error.
The precise location of a domain name in this hierarchy is known as a fully qualified domain name (FQDN). If the
alias has subdomains that are not known by the responding DNS, then it forwards the request to the domain’s DNS.
A DNS can act as a server to translate IP aliases and/or a cache which can merely cache previous lookups and respond
if available.
24
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DNS Hierarchy
25
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DNS Query:
Query means the particular request which receive by DNS server for name resolution and provide the
particular response against the request.
Recursive Query
When one DNS client send the request to the DNS server is called recursive query.
Recursion
This is a server-directed process to resolve an FQDN. If the server cannot resolve the FQDN with its own
information, it will send the query to other name servers. The recursion processcomprises root servers and
domain name servers.
1) The DNS client requests a name, like www.Sybex.com, from its DNS server.
2) Through the recursive process, the DNS server queries the root servers for the .comdomain name
servers.
26
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DNS Zone: -
DNS zone is an entity that stores the object information in to the various records. These are the following zone
types: -
Primary zone
Secondary zone
Forward lookup zone
Reverse lookup zone
Stub zone
Primary Zone: -- Primary (Master) zones, contain a read/write copy of the zone data. There could be only one
Master zone on one DNS server at a time. All the DNS records added manually or automatically, are written in this
Primary zone of the DNS server.
Secondary Zone: - The Secondary DNS zone is a read-only copy of the zone data. Most of the times Secondary
(Slave) zones are copies of Master zones.
Forward Lookup Zone and Reverse Lookup Zone: - You can use a Forward Lookup Zone to map a domain with its
IP address. On the other hand, a Reverse Lookup Zone will map an IP address to its domain records.
Stub Zone: - DNS stub zones are used to enable your DNS servers to resolve records in another domain. The
information in the stub zone allows your DNS to contact the authoritative DNS server directly.
Zone Transfer: -
AAAA Record Stands for address record this record responsible for IPV6 resolution
(Name - IP)
27
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Alias Record Alias (CNAME) records are created to list a secondary name for a
computer. It also referred to as canonical name.
MX Record Stands for Mail Exchange record , Which redirect mail to any user to a
designated mail host.
SRV Record Location of Service on the network which contains the following data:-
-Service (E.g. LDap)
- Target (Host that offers that service)
- Port
- Priority (Lower is preferred)
Usually crated automatically by applications.
SOA Record Stands for start of authority record. This record indicate that which
particular DNS server is authoritative for particular DNS zone.
One per Zone
Primary Name Server
E-Mail of administrator
Serial Number
Refresh time for the zone.
PTR Record The 'pointer' record is exactly the opposite of the 'A' record;
the PTR address will give you the domain associated with a given IP
address. The PTR record is used in reverse-lookup zones for reverse DNS
searches.
NS Record NS stands for 'name server' and this record indicates which DNS server is
authoritative for that domain (which server contains the actual DNS
records). A domain will often have multiple NS records which can indicate
primary and backup name servers for that domain.
Server Types: -
Root DNS Server: - Root hints are a list of the DNS servers on the Internet that your DNS servers can use to resolve
queries for names that it does not know. When a DNS server cannot resolve a name query by using its local data, it
uses its root hints to send the query to a DNS.
Primary DNS Server: - A primary DNS server is the first point of contact for a browser, application or device that
needs to translate a human-readable hostname into an IP address. The primary DNS server contains a DNS record
that has the correct IP address for the hostname.
Secondary DNS Server: - The secondary DNS server is an authoritative server that obtains information about a zone
from the primary server via zone transfer. (RFC 2182) The secondary DNS server is therefore tied to the primary
server.
Caching Only Name Server: - Caching-only Name Server is a name server in the Domain Name System (DNS) that
can resolve name lookup requests but does not maintain its own local DNS database or zone file of resource records.
28
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
A caching-only DNS server receives queries from clients, performs the queries against other name servers, caches
the results, and returns those results to the client. It then returns subsequent queries for the specified host from
the cache instead of submitting them to an external server.
All DNS Servers cache the results of their queries. However, some DNS Servers are put
into place to provide only this caching function. The Caching-only DNS server does not contain zone
information or a zone database file. The Caching-only server only contains information based on the results of
queries that it has already performed.
In this case, the cache takes the place of the zone database file. These Caching-only DNS Servers can be set up
quickly, and are an important ally in your network and Internet securitydesign.
The caching only server uses this list to begin building its cache. It adds to the cache as it issuesiterative queries
when responding to client requests to resolve Fully Qualified Domain Namesto IP addresses. After the FQDNs
are resolved to IP addresses, this information is stored in the DNS Server cache.
• They do not participate in zone transfer, and therefore there is no zone transfer traffic
• They can be placed on the far side of a slow WAN link and provide host name resolution for remote
offices that do not require a high level of host name resolutionsupport
• They can be implemented to provide secure host name resolution when configured asForwarders
29
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Forwarding:
This is an alternative to the recursion process. Forwarding is a lateral request to another nameserver within the
network. The forwarding server obtains a response and relays it to the originating name server.
PARAMETER DESCRIPTION
Protocol DNS
Required RPM 1. bind-9.*
2. Caching-nameserver-*
Port No 53
Main Configuration File 1. /etc/named.conf
2. /var/named/directory (Contains DNS zone files)
Daemon named
30
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
31
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
domain is contacted.
13. Which resource record is used to look up the hostname for a specific IPv4 address?
a. A (iii) PTR
c. AA (iv) AAAA
14. ‘PTR’record is used in
a. Forward lookup zone b. Both (a) and (c)
c. Reverse lookup zone d. None of the above
15. Zone is defined in a ____ file of primary DNS Server
a. /etc/dns.conf b. /etc/named.conf
c. /etc/bind.conf d. /etc/named/named.conf
16. All zone related information stored in a DNS zone file that is stored in
a. /var b. /etc
c. /var/log d. /var/named
1. Describe the terms ‘SOA’, ‘PTR’, ‘MX’, ‘CNAME’ and ‘A’
2. Write down the short notes on DNS Zone.
3. What does BIND stands for?
4. What is the default port of BIND?
5. Which are the important configuration files for DNS server?
6. On which version of BIND you have worked?
7. What is the utility of dig command?
8. Describe the function of /etc/resolv.conf file.
9. What is the difference between A record and CNAME record in DNS?
10. How does a dns lookup query works when you type a url on browser?
32
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
1. What is zone file? What will be the entry into zone file for mapping masterdns.example.com to
192.168.10.254?
2. What is the utility of dig command? Describe the function of /etc/resolv.conf file.
3. Describe the terms ‘NS’ and ‘A’. How serial number relates both master and slave DNS server?
4. What is the utility of MAC binding? What is the utility of ‘hostname’ command?
5. Describe the features of different types of DNS Server.
33
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DHCP definition
DHCP stands for dynamic host configuration protocol and is a network protocol used on IP networks where a
DHCP server automatically assigns an IP address andother information to each host on the network so they
can communicate efficiently with other endpoints.
A DHCP Server is a network server that automatically provides and assigns IP addresses, default gateways and
other network parameters to client devices. It relies on the standard protocol known as Dynamic Host
Configuration Protocol orDHCP to respond to broadcast queries by clients.
A DHCP server enables computers to request IP addresses and networking parameters automatically from
the Internet service provider (ISP), reducing the need for a network administrator or a user to manually assign
IP addresses to all network devices. In the absence of a DHCP server, a computer or other device on the
network needs to be manually assigned an IP address, or to assign itself an APIPA address, which will not
enable it to communicate outside its local subnet.
DHCP can be implemented on networks ranging in size from home networks to large campus networks and
regional Internet service provider networks. A routeror a residential gateway can be enabled to act as a DHCP
server. Most residentialnetwork routers receive a globally unique IP address within the ISP network.
Within a local network, a DHCP server assigns a local IP address to each deviceconnected to the network.
Internet Protocol (IP) defines how devices communicate within and across local networks on the Internet. A
DHCP server can manage IP settings for devices on itslocal network, e.g., by assigning IP addresses to those
devices automatically and dynamically.
DHCP operates based on the client–server model. When a computer or other device connects to a network,
the DHCP client software sends a DHCP broadcastquery requesting the necessary information. Any DHCP
server on the network may service the request. The DHCP server manages a pool of IP addresses and
information about client configuration parameters such as default gateway, domain name, the name servers,
and time servers. On receiving a DHCP request, the DHCP server may respond with specific information for
each client, as previously configured by an administrator, or with a specific address and any other information
valid for the entire network and for the time period for which the allocation (lease) is valid. A DHCP client
typically queries for this information immediately after booting, and periodically thereafter before the
expiration of the information. When a DHCP client refreshes an assignment, it initially requests the same
parameter values, but the DHCP server may assign a new address basedon the assignment policies set by
administrators.
On large networks that consist of multiple links, a single DHCP server may servicethe entire network when aided by
DHCP relay agents located on the interconnecting routers. Such agents relay messages between DHCP clients and
DHCP servers located on different subnets.
Depending on implementation, the DHCP server may have three methods ofallocating IP addresses:
34
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Dynamic allocation
A network administrator reserves a range of IP addresses for DHCP, and each DHCP client on the LAN is
configured to request an IP address from the DHCP server during network initialization. The request-and-
grant process uses a lease concept with a controllable time period, allowing theDHCP server to reclaim and
then reallocate IP addresses that are not renewed.
Automatic allocation
The DHCP server permanently assigns an IP address to a requesting client from the range defined by the
administrator. This is like dynamic allocation,but the DHCP server keeps a table of past IP address assignments,
so that itcan preferentially assign to a client the same IP address that the client previously had.
DHCP is used for Internet Protocol version 4 (IPv4) and IPv6. While both versionsserve the same purpose.
Operation
The DHCP employs a connectionless service model, using the User Datagram Protocol (UDP). It is implemented
with two UDP port numbers for its operations which are the same as for the bootstrap protocol (BOOTP). UDP
port number 67 isthe destination port of a server, and UDP port number 68 is used by the client.
DHCP operations fall into four phases: server discovery, IP lease offer, IP lease request, and IP lease
acknowledgement. These stages are often abbreviated as DORA for discovery, offer, request, and
acknowledgement.
The DHCP operation begins with clients broadcasting a request. If the client and server are on.
DORA PROCESS
1. DHCP DISCOVER
2. DHCP OFFER
3. DHCP REQUEST
4. DHCP ACK NOWLEDGEMENT
35
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
36
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
D – D in the term DORA stands for the DHCP Discover packet. The DHCP Discoverpacket
is broadcasted by the DHCP client computer in order to find the available DHCPserver(s) in the network.
Since the DHCP client computer sends the DHCP Discover packet as a broadcast, all the
DHCP servers that are present in the network receive the packet and respondaccordingly.
O – O in the term DORA stands for the DHCP Offer packet. The DHCP Offer is a unicast packet that is sent
by the DHCP server who receives the DHCP Discoverpacket from the DHCP client computer. The DHCP
Offer packet contains the available IP address that the DHCP server offers to the client computer.
R – R in the term DORA stands for the DHCP Request packet. The DHCP Request isagain a unicast packet sent
by the DHCP client computer to the DHCP server who had sent the DHCP Offer packet to the client computer.
With the help of the DHCP Request packet, the DHCP client computer requests the DHCP server to assign the
offered IP address to it.
A – A in the term DORA stands for the DHCP Acknowledge packet. The DHCP Acknowledge is a unicast
packet sent by the DHCP server to the DHCP client computer acknowledging the assignment of the offered
IP address for a specificlease time.
In computer science, a logical port is a number assigned to a “logical” connection. In simpler terms, it is the
endpoint to a logical connection that describes a service in TCP/IP and UDP. There are 65,536 TCP ports and
65,536 UDP ports. We count from 0 to 65,536. By including TCP/UDP port 0, the total number becomes 65,536
ports. Port numbers are assigned to a service, which is helpful to TCP/IP in identifying what ports it must send
traffic to. For example, TCP port 80 handles http, which is unencrypted Web traffic. Therefore, whenever TCP/IP
is handling communication between a client and a Web server, it will be using TCP port 80 (orTCP port 443 for
https). The Internet Assigned Number Authority (IANA) maintainsa list of official port assignments and divides
these ports into 3 ranges:
37
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
The port numbers in the “well-known” port range are assigned to commonly usedprotocols or services from
ports 0 to 1023. This port range also gets its own nickname, which is “non-ephemeral ports.” The word
ephemeral means temporary. By being non-ephemeral, the well-known ports are permanent.
A registered port is a network port (a sub-address defined within the Internet Protocol, in the range 1024–
49151) assigned by the Internet Assigned Numbers Authority (IANA) (or by Internet Corporation for Assigned
Names and Numbers (ICANN) before March 21, 2001, or by USC/ISI before 1998) for use with a certain
protocol or application.
The dynamic port numbers (also known as the private port numbers) are the portnumbers that are available
for use by any application to use in communicating with any other application, using the Internet's
Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP). When one application
communicateswith another application at another host computer on the Internet, it specifies that application
in each data transmission by using its port number.
38
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
First install DHCP packages using yum package manager on CentOS, Red Hat systems. DHCP rpms are available
under base repositories, so we don’t need to add an extra repository.
Firstly we need to set ethernet interface name as DHCPDARGS in /etc/sysconfig/dhcpd file. Edit this configuration
file and update the ethernet name.
DHCPDARGS=eth1
DHCP creates an empty configuration file /etc/dhcp/dhcpd.conf. Also it provides a sample configuration file at
/usr/share/doc/dhcp*/dhcpd.conf.sample, which is very useful for configuring the DHCP server.
So as a first part, copy the content of sample configuration file to the main configuration file. Sample configuration
file may be changed as perversion you have installed on your system.
Parameter Configuration
First configure the basic options which is common to all supported networks.
option domain-name "myserver.net";
option domain-name-servers ns1.myserver.net, ns2.myserver.net;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
IP Subnet Declaration
First, edit DHCP configuration file and update subnet details as per your network. For this example, we are
configuring DHCP for 192.168.1.0/24 LAN network.
In some cases, we need to assign a fixed IP to an interface each time it requested from dhcp. We can also assign a
fixed IP on basis of MAC address (hardware ethernet) of that interface. Setup host-name is optional to set up.
39
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
host station1 {
option host-name "station1.example.com";
hardware ethernet 00:11:1A:2B:3C:AB;
fixed-address 192.168.1.100;
}
After making all above changes, let’s start dhcp service using following commands as per your operating system
version.
At this stage we have a running dhcp server which is ready for accepting requests and assign them a proper ip. but
to verify I have another CentOS machine running on same LAN. Now login to that client machine and edit Ethernet
configuration file.
DEVICE=eth1
BOOTPROTO=dhcp
TYPE=Ethernet
ONBOOT=yes
Let’s restart network services on the client machine. You will get that dhcp server assigned an ip address from the
defined subnet. If you have connected to client pc from remote login, Your session can be disconnected.
40
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Question
Correct Answer
Number
1. a. IP address
2. b. Both IPv6 and IPv4
3. d. all of the above
4. a. for a limited period
5. c. 67
6. d. all of the above
7. a. UDP broadcast
8. a. dhcpd –t
c. Addresses are leased to host. A host will usually keep the same address by periodically
9.
contacting the DHCP sever to renew the lease.
10. a. chkconfig
11. c. /etc/sysconfig/network
12. c. It dynamically assigns IP addresses and network configuration to devices on the network.
13. d. All of the above.
14. d. Both A and B.
15. c. 24 hours
16. d. All of the above.
17. c. Both A and B.
42
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
1. What is DHCP? What information can a DHCP server provide to a host.
2. What is the configuration file of DHCP Server?
3. Describe the Scope in DHCP server.
4. How does DHCP work?
5. What are the benefits of using DHCP?
6. What are the disadvantages of using DHCP?
7. Which port does DHCP use?
8. What do you mean by an IP Lease?
9. What exactly is IP Reservation?
10. Can we assign static IP address to hosts ?
1. Write down the short notes of “DORA” process in DHCP with suitable diagram.
2. What is the utility of integrating DNS with DHCP? Describe with a suitable example.
3. What is DHCP relay?
4. What is APIPA? What is the range of APIPA address?
5. What exactly is a SUPER SCOPE?
43
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Web Server: A web server is software that serves web content (such as HTML pages, multimedia files, etc.) to clients
(web browsers) over the HTTP protocol. It processes incoming requests from clients and delivers the requested
resources.
Apache HTTP Server: Commonly referred to as Apache, it is the most widely used web server software.
Developed and maintained by the Apache Software Foundation, it is open-source and runs on various
platforms, including Linux, Windows, and macOS.
Features of Apache HTTP Server
Open Source: Apache is free to use and modify, encouraging community contributions and improvements.
Extensible: Supports a wide range of modules for additional functionality, such as SSL support, URL rewriting, and
authentication.
Security: Offers various security features to protect web applications and server infrastructure.
Core: The core of Apache handles basic functions such as managing network connections and handling requests.
Modules: Apache's functionality can be extended with modules. Some common modules include:
Configuration Files: Apache's behavior is controlled by configuration files, primarily httpd.conf and additional files
in the conf.d directory.
Installation Process:
On RHEL-based systems (Red Hat, CentOS, Fedora), Apache can be installed using the dnf package manager:
Configuring Apache
Key Directives:
ServerRoot: Specifies the directory where the server's configuration, error, and log files are stored.
44
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
DocumentRoot: The directory out of which Apache will serve files. Typically, /var/www/html.
Listen: Specifies the IP addresses and ports on which Apache will listen for incoming requests.
ServerName: The hostname and port that the server uses to identify itself.
Virtual Hosts
Virtual hosting allows Apache to serve different websites from the same server.
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/example.com
ErrorLog /var/log/httpd/example.com_error.log
</VirtualHost>
Managing Apache
Systemctl Commands:
Start Apache:
Securing Apache
Firewall Configuration:
45
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
SELinux Configuration:
Options –Indexes
<Files ".ht*">
</Files>
Performance Tuning
MaxClients: Controls the maximum number of simultaneous connections that Apache will handle.
KeepAlive: Enables persistent connections, reducing the overhead of establishing new connections for each
request.
Caching: Use caching mechanisms (like mod_cache) to improve response times and reduce load.
Log Files:
LogFormat: Customize the format of the logs to capture the required information.
Monitoring Tools: Use tools like Nagios, Zabbix, or Grafana for monitoring Apache performance and uptime.
Advanced Topics
SSL/TLS Configuration:
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /var/www/html/example.com
46
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/example.com.key
SSLCertificateChainFile /etc/pki/tls/certs/chain.crt
</VirtualHost>
Reverse Proxy:
<VirtualHost *:80>
ServerName proxy.example.com
ProxyPass / http://backend.example.com/
ProxyPassReverse / http://backend.example.com/
</VirtualHost>
a. httpd -p b. httpd -t
c. httpd -s d. httpd -n
a. /var/www/ b. /etc/httpd/
c. /usr/local/apache/ d. /var/www/html/
47
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
c. /etc/httpd/conf/httpd.conf d. /var/www/html/httpd.conf
6. Which directive in the Apache configuration file specifies the directory out of which the server will
serve documents?
a. ServerRoot b. DocumentRoot
c. ServerName d. Listen
a. mod_rewrite b. mod_ssl
c. mod_proxy d. mod_security
a. /etc/httpd/logs/error_log b. /var/log/apache2/error.log
c. /var/log/httpd/error_log d. /usr/local/apache2/logs/error_log
10. Which directive is used to set the hostname and port that the server uses to identify itself?
a. ServerRoot b. ServerAlias
c. ServerAdmin d. ServerName
11. What is the command to check the status of the Apache service?
a. mod_proxy b. mod_usertrack
c. mod_ssl d. mod_alias
a. .con b. .txt
c. .conf d. .configuration
a. /deck/log/httpd b. /drive/log/httpd
c. /var/log/httpd d. /location/log/httpd
48
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
15. What is the command to check the version of the Apache Server?
c. Yes, by default d. No
17. How do you change the default web root in Apache Server?
18. The most famous HTTP response error “Not Found” code is:-
a. 400 b. 405
c. 404 d. 408
a. Apache/logs/access.log b. Apache/logs/error.log
20. How can you allow HTTP and HTTPS traffic through the firewall on RHEL 8?
21. Which of the following directives is used to prevent the listing of files in a directory?
49
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
25. Which file should be edited to configure a new virtual host in Apache on RHEL 8?
a. /etc/httpd/conf/httpd.conf b. /etc/httpd/conf.d/vhost.conf
c. /var/www/html/vhost.conf d. /etc/httpd/virtual.conf
Question
Correct Answer
Number
1. a. 80 and 443
2. a. Static Web page file(Which is called “WebRoot”
3. b. httpd -t
4. d. /var/www/html/
5. c. /etc/httpd/conf/httpd.conf
6. b. DocumentRoot
7. b. sudo systemctl restart httpd
8. b. mod_ssl
9. c. /var/log/httpd/error_log
10. d. ServerName
11. c. sudo systemctl status httpd
12. a. mod_proxy
13. C. .conf
14. c. /var/log/httpd
15. c. rpm –qa|grep httpd
16. b. Yes, using mod_proxy module
17. d. Change the DoccumentRoot in httpd.conf file
18. c. 404
19. d. Borh (a) and (b)
20. b. Options -Indexes
21. b. To rewrite URLs
22. b. To rewrite URLs
23. C. sudo systemctl enable httpd
24. c. To forward requests to another server
25. b. /etc/httpd/conf.d/vhost.conf
50
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
51
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Definition: An email server is a server that handles and delivers email over a network, typically the internet.
IMAP (Internet Message Access Protocol): Used for receiving emails, allowing multiple clients to manage the same
mailbox.
POP3 (Post Office Protocol 3): Used for receiving emails, downloading emails from the server to the client.
Postfix: A free and open-source mail transfer agent (MTA) that routes and delivers electronic mail.
Dovecot: An open-source IMAP and POP3 server for Unix-like operating systems.
Courier: A mail transfer agent with integrated POP3 and IMAP servers.
Step-by-Step Guide:
2. Configure Postfix:
# sudo vi /etc/postfix/main.cf
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/
52
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
3. Configure Dovecot:
# sudo vi /etc/dovecot/dovecot.conf
mail_location = maildir:~/Maildir
# sudo vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
# sudo vi /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
4. Configure Firewall:
53
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Sending Email:
MUA (Mail User Agent): The client application (like Thunderbird or Outlook) used to compose and send an email.
MTA (Mail Transfer Agent): (e.g., Postfix) routes the email to the recipient's mail server.
MDA (Mail Delivery Agent): (e.g., Dovecot) delivers the email to the recipient's mailbox.
Receiving Email:
MTA receives email: The recipient's MTA receives the email from the sender's MTA.
MDA stores email: The MDA (like Dovecot) stores the email in the recipient's mailbox.
MUA retrieves email: The recipient's MUA retrieves the email from the mailbox using IMAP or POP3.
Security Considerations
Encryption:
TLS/SSL: Use TLS/SSL to encrypt communications between email clients and servers (SMTP, IMAP, and POP3).
Authentication:
Strong Passwords: Enforce the use of strong passwords for all email accounts.
Spam Filtering:
Install and configure spam filtering tools: Tools like SpamAssassin can help reduce spam emails.
Regular Updates:
Keep software up to date: Regularly update Postfix, Dovecot, and other related software to patch security
vulnerabilities.
Verify DNS settings: Ensure that your domain's DNS records (MX, SPF, DKIM) are correctly configured.
Firewall settings: Ensure that the firewall is not blocking necessary ports (25 for SMTP, 143 for IMAP, 110 for POP3).
54
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Authentication Failures:
Verify user credentials: Ensure that the username and password are correct.
Check Dovecot authentication configuration: Ensure that the authentication settings in /etc/dovecot/conf.d/10-
auth.conf are correct.
Best Practices
Backup:
Regularly backup mail data: Ensure you have regular backups of all mail data and configurations.
Monitoring:
Monitor server performance and logs: Use tools like logwatch or Logrotate to manage and monitor log files.
User Education:
Educate users: Make sure users are aware of phishing attacks and how to handle suspicious emails.
55
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
1. Simple mail transfer protocol (SMTP) utilizes _________ as the transport layer protocol for electronic
mail transfer.
a. TCP b. UDP
c. DCCP d. SCTP
a. SMTPS b. SSMTP
c. SNMP d. STARTTLS
a. 22 b. 23
c. 21 d. 25
4. Which one of the following protocol is not used to send and receive mail messages?
5. An email client needs to know the _________ of its initial SMTP server.
c. URL d. Name
9. When the mail server sends mail to other mail servers it becomes ____________
56
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
c. Peer d. Master
c. Google d. Tumblr
a. IMAP b. POP3
c. SMTP d. FTP
14. Where is the main configuration file for Postfix located on a RHEL 8 system?
a. /etc/postfix/main.cf b. /etc/mail/postfix.cf
c. /etc/postfix.conf d. /var/spool/postfix/main.cf
15. Which of the following is an open-source IMAP and POP3 server commonly used with Postfix?
a. Sendmail b. Exim
c. Dovecot d. Courier
a. /etc/dovecot/dovecot.conf b. /etc/dovecot/conf.d/10-auth.conf
c. /etc/dovecot/authentication.conf d. /etc/dovecot/user.conf
a. 25 b. 110
c. 143 d. 993
19. To allow SMTP traffic through the firewall on RHEL 8, which command should be used?
57
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
20. Which Postfix directive specifies the domain for outgoing emails?
a. myhostname b. mydomain
c. myorigin d. inet_interfaces
21. In which directory are the email logs typically stored on a RHEL 8 system?
a. /var/log/mail b. /var/log/email
c. /var/log/postfix d. /var/log/maillog
a. FTP b. HTTP
c. SSL/TLS d. SSH
23. What command is used to reload the Postfix configuration without restarting the service?
24. Which file in Dovecot configuration specifies the SSL certificate and key locations?
a. /etc/dovecot/dovecot.conf b. /etc/dovecot/conf.d/10-ssl.conf
c. /etc/dovecot/conf.d/ssl-cert.conf d. /etc/dovecot/ssl.conf
25. How can you check the status of the Postfix service on RHEL 8?
26. Which command is used to generate a self-signed SSL certificate for securing email communication?
a. The directory where mail logs are stored b. The location of the Dovecot configuration
files
c. The format and location of users' mailboxes d. The domain name for incoming emails
58
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Question
Correct Answer
Number
1. a. TCP
2. a. SMTPS
3. d. 25
4. d. FTP
5. a. IP address
6. d. One HTTP transaction
7. a. Message transport
8. c. User’s word processor
9. b. SMTP client
10. a. Simple Message Transfer Protocol
11. a. Microsoft Outlook
12. a. Microsoft Outlook
13. c. SMTP
14. a. /etc/postfix/main.cf
15. c. Dovecot
16. b. sudo systemctl start postfix
17. b. /etc/dovecot/conf.d/10-auth.conf
18. c. 143
19. b. sudo firewall-cmd --permanent --add-service=smtp
20. c. myorigin
21. d. /var/log/maillog
22. c. SSL/TLS
23. a. sudo systemctl reload postfix
24. b. /etc/dovecot/conf.d/10-ssl.conf
25. c. sudo systemctl status postfix
26. b. sudo openssl req -new -x509
27. c. The format and location of users' mailboxes
1. What Is Smtp?
2. Explain How Does Smtp Work?
3. Explain The Smtp Basic Functions?
4. What Is The Difference Between Ports 465 And 587?
5. What is postfix?
6. What is the default port used for postfix?
7. What is the difference between Postfix & Sendmail ?
8. What is MUA?
9. What is MTA and it’s role in mailing system?
10. What are the important daemons in postfix?
11. What are the configuration files of postfix server?
12. How to restart the postfix service & make it enable across reboot?
13. What is the primary function of an SMTP server?
59
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
60
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file
systems as though they are mounted locally. This enables system administrators to consolidate resources onto
centralized servers on the network.
Purpose of NFS
How It Works
Currently, there are three versions of NFS. NFS version 2 (NFSv2) is older and is widely supported. NFS version 3
(NFSv3) has more features, including 64bit file handles, Safe Async writes and more robust error handling. NFS
version 4 (NFSv4) works through firewalls and on the Internet, no longer requires portmapper, supports ACLs, and
utilizes stateful operations. Red Hat Enterprise Linux supports NFSv2, NFSv3, and NFSv4 clients, and when mounting
a file system via NFS, Red Hat Enterprise Linux uses NFSv3 by default, if the server supports it.
All versions of NFS can use Transmission Control Protocol (TCP) running over an IP network, with NFSv4 requiring it.
NFSv2 and NFSv3 can use the User Datagram Protocol (UDP) running over an IP network to provide a stateless
network connection between the client and server.
When using NFSv2 or NFSv3 with UDP, the stateless UDP connection under normal conditions has less Protocol
overhead than TCP which can translate into better performance on very clean, non-congested networks. The NFS
server sends the client a file handle after the client is authorized to access the shared volume. This file handle is an
opaque object stored on the server's side and is passed along with RPC requests from the client. The NFS server can
be restarted without affecting the clients and the cookie remains intact. However, because UDP is stateless, if the
server goes down unexpectedly, UDP clients continue to saturate the network with requests for the server. For this
reason, TCP is the preferred protocol when connecting to an NFS server.
NFSv4 has no interaction with portmapper, rpc.mountd, rpc.lockd, and rpc.statd, since protocol support has been
incorporated into the v4 protocol. NFSv4 listens on the well known TCP port (2049) which eliminates the need for
the portmapper interaction. The mounting and locking protocols have been incorpated into the V4 protocol which
eliminates the need for interaction with rpc.mountd and rpc.lockd.
Required Services
Red Hat Enterprise Linux uses a combination of kernel-level support and daemon processes to provide NFS file
sharing. All NFS versions rely on Remote Procedure Calls (RPC) between clients and servers. RPC services under
Linux are controlled by the portmap service. To share or mount NFS file systems, the following services work
together, depending on which version of NFS is implemented:
o nfs — (/sbin/service nfs start) starts the NFS server and the appropriate RPC processes to service requests
for shared NFS file systems.
o nfslock — (/sbin/service nfslock start) is a mandatory service that starts the appropriate RPC processes to
allow NFS clients to lock files on the server.
61
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
o portmap — accepts port reservations from local RPC services. These ports are then made available (or
advertised) so the corresponding remote RPC services access them. portmap responds to requests for RPC
services and sets up connections to the requested RPC service. This is not used with NFSv4.
o rpc.mountd — This process receives mount requests from NFS clients and verifies the requested file system
is currently exported. This process is started automatically by the nfs service and does not require user
configuration. This is not used with NFSv4.
o rpc.nfsd — Allows explicit NFS versions and protocols the server advertises to be defined. It works with the
Linux kernel to meet the dynamic demands of NFS clients, such as providing server threads each time an
NFS client connects. This process corresponds to the nfs service.
o rpc.lockd — allows NFS clients to lock files on the server. If rpc.lockd is not started, file locking will
fail. rpc.lockd implements the Network Lock Manager (NLM) protocol. This process corresponds to
the nfslock service. This is not used with NFSv4.
o rpc.statd — This process implements the Network Status Monitor (NSM) RPC protocol which notifies NFS
clients when an NFS server is restarted without being gracefully brought down. This process is started
automatically by the nfslock service and does not require user configuration. This is not used with NFSv4.
o rpc.rquotad — This process provides user quota information for remote users. This process is started
automatically by the nfs service and does not require user configuration.
o rpc.idmapd — This process provides NFSv4 client and server upcalls which map between on-the-wire NFSv4
names (which are strings in the form of user@domain) and local UIDs and GIDs. For idmapd to function
with NFSv4, the /etc/idmapd.conf must be configured. This service is required for use with NFSv4.
Currently, there are three versions of NFS. NFS version 2 (NFSv2) is older and widely supported. NFS version 3
(NFSv3) supports safe asynchronous writes and is more robust at error handling than NFSv2; it also supports 64-bit
file sizes and offsets, allowing clients to access more than 2Gb of file data.
NFS version 4 (NFSv4) works through firewalls and on the Internet, no longer requires an rpcbind service, supports
ACLs, and utilizes stateful operations. Red Hat Enterprise Linux 6.X & Centos 6.X supports NFSv2,NFSv3, and NFSv4
clients. When mounting a file system via NFS, Red Hat Enterprise Linux uses NFSv4 by default, if the server supports
it.
Configuration files of NFS server
‘/etc/exports’ is the main configuration file that controls which file systems are exported to remote hosts and
specifies options.
‘/etc/sysconfig/nfs‘ is the file through which we can fix ports for RQUOTAD_PORT, MOUNTD_PORT,
LOCKD_TCPPORT, LOCKD_UDPPORT and STATD_PORT
62
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
ro: The directory is shared read only; the client machine will not be able to write to it. This is the default.
rw: The client machine will have read and write access to the directory.
root_squash: By default, any file request made by user root on the client machine is treated as if it is made
by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user
“nobody” on the server, not the client.)
no_root_squash : if this option is used , then root on the client machine will have the same level of access
to the files on the system as root on the server. This can have serious security implications, although it may
be necessary if you want to perform any administrative work on the client machine that involves the
exported directories. You should not specify this option without a good reason.
no_subtree_check : If only part of a volume is exported, a routine called subtree checking verifies that a file
that is requested from the client is in the appropriate part of the volume. If the entire volume is exported,
disabling this check will speed up transfers.
sync : Replies to the NFS request only after all data has been written to disk. This is much safer than async,
and is the default in all nfs-utils versions after 1.0.0.
async : Replies to requests before the data is written to disk. This improves performance, but results in
lost data if the server goes down.
no_wdelay : NFS has an optimization algorithm that delays disk writes if NFS deduces a likelihood of a
related write request soon arriving. This saves disk writes and can speed performance
wdelay : Negation of no_wdelay , this is default
nohide : Normally, if a server exports two filesystems one of which is mounted on the other, then the client
will have to mount both filesystems explicitly to get access to them. If it just mounts the parent, it will see
an empty directory at the place where the other filesystem is mounted. That filesystem is “hidden”. Setting
the nohide option on a filesystem causes it not to be hidden, and an appropriately authorised client will be
able to move from the parent to that filesystem without noticing the change.
hide : Negation of nohide This is the default
List available nfs share on local machine & remote machine
Soft Mount : Consider we have mounted a NFS share using ‘soft mount’ . When a program or application
requests a file from the NFS filesystem, NFS client daemons will try to retrieve the data from the NFS server.
But, if it doesn’t get any response from the NFS server (due to any crash or failure of NFS server), the NFS
client will report an error to the process on the client machine requesting the file access. The advantage of
this mechanism is “fast responsiveness” as it doesn’t wait for the NFS server to respond. But, the main
disadvantage of this method is data corruption or loss of data. So, this is not a recommended option to use.
Hard Mount : Suppose we have mounted the NFS share using hard mount, it will repeatedly retry to contact
the server. Once the server is back online the program will continue to execute undisturbed from the state
where it was during server crash. We can use the mount option “intr” which allows NFS requests to be
interrupted if the server goes down or cannot be reached. Hence the recommended settings are hard and
intr options.
63
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Shares are accessed automatically and transparently when a user tries to access any files or directories
under the designated mount point of the remote filesystem to be mounted.
Booting time is significantly reduced because no mounting is done at boot time.
Network access and efficiency are improved by reducing the number of permanently active mount points.
Failed mount requests can be reduced by designating alternate servers as the source of a filesystem.
The Role of “sync” Option for Nfs Server
If sync is specified, the server waits until the request is written to disk before responding to the client. The sync
option is recommended because it follows the NFS protocol.
Autofs
Autofs , is auto mounting filesystem on demand like when ever you need it.
NFS is like mounting a complete partition remotely and you will have availability of whole content of the
partition.
But there are few advantages with autofs over nfs.
Advantages of Autofs
Shares are accessed automatically and transparently when a user tries to access any files or directories
under the designated mount point of the remote filesystem to be mounted.
Booting time is significantly reduced because no mounting is done at boot time.
Network access and efficiency are improved by reducing the number of permanently active mount points.
Failed mount requests can be reduced by designating alternate servers as the source of a filesystem.
64
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
65
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
9. a. Are stateless
10. c. Be invisible
66
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Samba is the standard open source Windows interoperability suite of programs for Linux. It implements
the server message block (SMB) protocol. Modern versions of this protocol are also known as the
common Internet file system (CIFS) protocol. It allows the networking of Microsoft Windows®, Linux,
UNIX, and other operating systems together, enabling access to Windows-based file and printer shares.
Samba's use of SMB allows it to appear as a Windows server to Windows clients.
Introduction to Samba
Samba is an important component to seamlessly integrate Linux Servers and Desktops into Active
Directory (AD) environments. It can function both as a domain controller (NT4-style) or as a regular
domain member (AD or NT4-style).
The SMB protocol enables applications and their users to access files on remote servers, as well as connect to other
resources, including printers, mailslots and named pipes. SMB provides client applications with a secure and
controlled method for opening, reading, moving, creating and updating files on remote servers. The protocol can
also communicate with server programs configured to receive SMB client requests.
Known as a response-request protocol, the SMB protocol is one of the most common methods used for network
communications. In this model, the client sends an SMB request to the server to initiate the connection. When the
server receives the request, it replies by sending an SMB response back to the client, establishing the
communication channel necessary for a two-way conversation.
The SMB protocol operates at the application layer but relies on lower network levels for transport. At one time,
SMB ran on top of Network Basic Input/Output System over Transmission Control Protocol/Internet Protocol
(NetBIOS over TCP/IP, or NBT) or, to a lesser degree, legacy protocols such as Internetwork Packet Exchange or
67
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
NetBIOS Extended User Interface. When SMB was using NBT, it relied on ports 137, 138 and 139 for transport. Now,
SMB runs directly over TCP/IP and uses port 445.
Today, communications with devices that do not support SMB directly over TCP/IP require the use of NetBIOS over
a transport protocol such as TCP/IP.
Today, communications with devices that do not support SMB directly over TCP/IP require the use of NetBIOS over
a transport protocol such as TCP/IP.
Microsoft Windows operating systems (OSes) since Windows 95 have included client and server SMB protocol
support. The Linux OS and macOS also provide built-in support for SMB. In addition, Unix-based systems can use
Samba to facilitate SMB access to file and print services.
A client and server can implement different SMB dialects. If they do, the systems must first negotiate the differences
between editions before starting a session.
smbd
The smbd server daemon provides file sharing and printing services to Windows clients. In addition, it is responsible
for user authentication, resource locking, and data sharing through the SMB protocol. The
68
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
default ports on which the server listens for SMB traffic are TCP ports 139 and 445. The smbd daemon is controlled
by the smb service.
nmbd
The nmbd server daemon understands and replies to NetBIOS name service requests such as those produced by
SMB/CIFS in Windows-based systems. These systems include Windows 95/98/ME, Windows NT, Windows 2000,
Windows XP, and LanManager clients. It also participates in the browsing protocols that make up the Windows
Network Neighborhood view. The default port that the server listens to for NMB traffic is UDP port 137. The nmbd
daemon is controlled by the nmb service.
winbindd
The winbind service resolves user and group information received from a server running Windows NT, 2000, 2003,
Windows Server 2008, or Windows Server 2012. This makes Windows user and group information understandable
by UNIX platforms. This is achieved by using Microsoft RPC calls, Pluggable Authentication Modules (PAM), and the
Name Service Switch (NSS). This allows Windows NT domain and Active Directory users to appear and operate as
UNIX users on a UNIX machine. Though bundled with the Samba distribution, the winbind service is controlled
separately from the smb service. The winbind daemon is controlled by the winbind service and does not require the
smb service to be started in order to operate. winbind is also used when Samba is an Active Directory member, and
may also be used on a Samba domain controller (to implement nested groups and interdomain trust). Because
winbind is a client-side service used to connect to Windows NT-based servers, further discussion of winbind is
beyond the scope of this chapter.
Smbpasswd
This allows the user to change the password used for their smb sessions.
Smb mount
This mounting programs enables mounting of server directories on a linux or unix box.
Smb status
This programs lists the current samba connections.
CIFS
Common internet file system is a protocol that basically an updated smb.
Configuration File: -
/etc/samba/smb.conf
69
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
To connect to a Samba share from a shell prompt, type the following command:
# smbclient //hostname/sharename -U username
The following sections describe the different ways a Samba server can be configured. Keep in mind your
needs and the changes required to the /etc/samba/smb.conf file for a successful configuration.
Stand-alone Server
A stand-alone server can be a workgroup server or a member of a workgroup environment. A standalone server is
not a domain controller and does not participate in a domain in any way.
SMB RPM
RPM DESCRIPTION
samba Base rpm for samba server.
Samba-common Include commands those required by samba server and client.
Samba-doc Provide samba documentation.
Samba-client This is am smb client program that implement a simple ftp like client on a linux or
unix box.
Samba-swat Gui interface for samba configuration.
Samba-winbind Allow interoperability between linux and windows.
Samba-domainjoin-gui Allow linux user to connect with windows workgroups and domains.
SMB PORTS
PORT NO DESCRIPTION
137 Connection port, used by nmbd daemon.
138 Data port, used by smbd daemon.
139 Used for authentication.
445(TCP) Used by mordern samba server.
70
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
SAMBA COMMANDS
COMMANDS DESCRIPTION
Smbclient Comand used to connect with samba server from samba client.
mget To download file from samba server.
mput To upload file to samba server.
bye To logout from samba server.
71
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Question
Correct Answer
Number
1. a. TCP/IP
72
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
2. d. Stateless
3. d. All the above
4. b. SMB
5. d. Both Kerberos and NTLM
6. a. IBM
7. c. Executing program on different computer
8. c. –
9. d. testparm /etc/smb.conf
10. B,d File sharing, Printer sharing
To provide WINS resolution to SMB clients, To provide file and printer sharing to SMB
11. B,d
clients
73
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Security Enhanced Linux or SELinux is a set of modifications developed by the United States National Security Agency
(NSA) to provide a variety of security policies for Linux. SELinux was released as open source at the end of 2000.
Since kernel version 2.6 it is an integrated part of Linux.
SELinux offers security! SELinux can control what kind of access users have to files and processes. Even when a file
received chmod 777, SELinux can still prevent applications from accessing it (Unix file permissions are checked first!).
SELinux does this by placing users in roles that represent a security context. Administrators have very strict control
on access permissions granted to roles.
SELinux is present in the latest versions of Red Hat Enterprise Linux, Debian, CentOS, Fedora, and many other
distributions.
selinux modes
selinux knows three modes: enforcing, permissive and disabled. The enforcing mode will enforce policies, and may
deny access based on selinux rules. The permissive mode will not enforce policies, but can still log actions that would
have been denied in enforcing mode. The disabled mode disables selinux.
getenforce
Use getenforce to verify whether selinux is enforced, disabled or permissive.
The /selinux/enforce file contains 1 when enforcing, and 0 when permissive mode is active.
setenforce
You can use setenforce to switch between the Permissive or the Enforcing state once
selinux is activated.
74
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Permissive
[root@centos65 ~]#
Sestatus
You can see the current selinux status and policy with the sestatus command.
Policy
Most Red Hat server will have the targeted policy. Only NSA/FBI/CIA/DOD/HLS use the
mls policy.
The targted policy will protect hundreds of processes, but lets other processes run
'unconfined' (= they can do anything).
/etc/selinux/config
The main configuration file for selinux is /etc/selinux/config. When in permissive mode, the file looks like this.
The targeted policy is selected in /etc/selinux/config.
DAC or MAC
Standard Unix permissions use Discretionary Access Control to set permissions on files. This means that a user that
owns a file, can make it world readable by typing chmod 777 $file.
With selinux the kernel will enforce Mandatory Access Control which strictly controls what processes or threads can
do with files (superseding DAC). Processes are confined by the kernel to the minimum access they require.
75
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
SELinux MAC is about labeling and type enforcing! Files, processes, etc are all labeled with an SELinux context. For
files, these are extended attributes, for processes this is managed by the kernel.
user:role:type:(level)
ls –Z
To see the DAC permissions on a file, use ls -l to display user and group owner and permissions.
For MAC permissions there is new -Z option added to ls. The output shows that file in /root have a XXXtype of
admin_home_t.
[root@centos65 ~]# ls -Z
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log.syslog
-Z
/selinux
When selinux is active, there is a new virtual file system named /selinux. (You can compare it to /proc and /dev.).
Although some files in /selinux appear wih size 0, they often contain a boolean value. Check /selinux/enforce to see
if selinux is running in enforced mode.
Identity
The SELinux Identity of a user is distinct from the user ID. An identity is part of a security
context, and (via domains) determines what you can do. The screenshot shows user root
having identity user_u.
[root@rhel55 ~]# id -Z
user_u:system_r:unconfined_t
Role
The selinux role defines the domains that can be used. A role is denied to enter a domain, unless the role is explicitely
authorized to do so.
The selinux context is the security context of a process. An selinux type determines what a process can do. The
screenshot shows init running in type init_t and the mingetty's running in type getty_t.
The selinux type is similar to an selinux domain, but refers to directories and files instead of processes.
[root@centos65 sbin]# netstat -nptlZ | tr -s ' ' | cut -d' ' -f6-
Foreign Address State PID/Program name Security Context
LISTEN 1096/rpcbind system_u:system_r:rpcbind_t:s0
LISTEN 1208/sshd system_u:system_r:sshd_t:s0-s0:c0.c1023
LISTEN 1284/master system_u:system_r:postfix_master_t:s0
LISTEN 1114/rpc.statd system_u:system_r:rpcd_t:s0
LISTEN 1096/rpcbind system_u:system_r:rpcbind_t:s0
LISTEN 1666/httpd unconfined_u:system_r:httpd_t:s0
LISTEN 1208/sshd system_u:system_r:sshd_t:s0-s0:c0.c1023
LISTEN 1114/rpc.statd system_u:system_r:rpcd_t:s0
LISTEN 1284/master system_u:system_r:postfix_master_t:s0
You can also get a list of ports that are managed by SELinux:
security context
The combination of identity, role and domain or type make up the selinux security context.
The id will show you your security context in the form identity:role:domain.
The ls -Z command shows the security context for a file in the form identity:role:type.
The security context for processes visible in /proc defines both the type (of the file in /proc)
and the domain (of the running process). Let's take a look at the init process and /proc/1/ .
The /proc/1/ directory, which identifies the init process, has type init_t.
It is not a coincidence that the domain of the init process and the type of /proc/1/ are both
init_t.
Don't try to use chcon on /proc! It will not work.
Transition
An selinux transition (aka an selinux labelling) determines the security context that will be assigned. A transition of
process domains is used when you execute a process. A transition of file type happens when you create a file.
Extended attributes
Extended attributes are used by selinux to store security contexts. These attributes can be
viewed with ls when selinux is running.
Chcon
This example shows how to use chcon to change the type of a file.
Booleans
80
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
httpd_enable_homedirs=1
httpd_read_user_content=1
IPTABLES
Introduction
All modern operating systems come equipped with a firewall – a software application that regulates network traffic
to a computer. Firewalls create a barrier between a trusted network (like an office network) and an untrusted one
(like the internet). Firewalls work by defining rules that govern which traffic is allowed, and which is blocked. The
utility firewall developed for Linux systems is iptables.
Prerequisites
Network traffic is made up of packets. Data is broken up into smaller pieces (called packets), sent over a network,
then put back together. Iptables identifies the packets received and then uses a set of rules to decide what to do
with them.
81
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Targets: A target is a decision of what to do with a packet. Typically, this is to accept it, drop it, or reject it
(which sends an error back to the sender).
Linux firewall iptables has four default tables. We will list all four along with the chains each table contains.
1. Filter
The Filter table is the most frequently used one. It acts as a bouncer, deciding who gets in and out of your network.
It has the following default chains:
Input – the rules in this chain control the packets received by the server.
Output – this chain controls the packets for outbound traffic.
Forward – this set of rules controls the packets that are routed through the server.
3. Mangle
The Mangle table adjusts the IP header properties of packets. The table has all the following chains we described
above:
Prerouting
Postrouting
Output
Input
Forward
4. Raw
The Raw table is used to exempt packets from connection tracking. The raw table has two of the chains we previously
mentioned:
Prerouting
Output
82
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
5. Security (Optional)
Some versions of Linux also use a Security table to manage special access rules. This table includes input, output,
and forward chains, much like the filter table.
Targets
A target is what happens after a packet matches a rule criteria. Non-terminating targets keep matching the packets
against rules in a chain even when the packet matches a rule.
With terminating targets, a packet is evaluated immediately and is not matched against another chain. The
terminating targets in Linux iptables are:
Accept – this rule accepts the packets to come through the iptables firewall.
Drop – the dropped package is not matched against any further chain. When Linux iptables drop an incoming
connection to your server, the person trying to connect does not receive an error. It appears as if they are
trying to connect to a non-existing machine.
Return – this rule sends the packet back to the originating chain so you can match it against other rules.
Reject – the iptables firewall rejects a packet and sends an error to the connecting device.
By default, these commands affect the filters table. If you need to specify a different table, use the –t option,
followed by the name of the table.
To view the current set of rules on your server, enter the following in the terminal window:
sudo iptables –L
The system displays the status of your chains. The output will list three chains:
It’s safe to allow traffic from your own system (the localhost). Append the Input chain by entering the
following:
sudo iptables -A INPUT -i lo -j ACCEPT
This command configures the firewall to accept traffic for the localhost (lo) interface (-i). Now anything
originating from your system will pass through your firewall. You need to set this rule to allow applications
to talk to the localhost interface
.
84
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
These rules allow traffic on different ports you specify using the commands listed below. A port is a
communication endpoint specified for a specific type of data.
To allow only incoming SSH (Secure Shell) traffic, enter the following:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Replace the IP address in the command with the IP address you want to allow.
You can REJECT traffic from a range of IP addresses, but the command is more complex:
If you define dport iptables firewall rules, you need to prevent unauthorized access by dropping any traffic
that comes via other ports:
The -A option appends a new rule to the chain. If any connection comes through ports other than those you
defined, it will be dropped.
Delete a Rule
85
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
You can use the -F option to clear all iptables firewall rules. A more precise method is to delete the line
number of a rule.
Locate the line of the firewall rule you want to delete and run this command:
Replace <Number> with the actual rule line number you want to remove.
Iptables does not keep the rules you created when the system reboots. Whenever you configure iptables in
Linux, all the changes you make apply only until the first restart.
Firewalld
Introduction to firewalld
firewalld is a dynamic firewall management tool with support for network/firewall zones that define the
trust level of network connections or interfaces. It provides a dynamically managed firewall with support
for network zones to define the trust level of network connections or interfaces. It also supports IPv4, IPv6,
ethernet bridges, and IP sets.
86
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Key Concepts
1. Zones:
Zones are predefined sets of rules that determine the level of trust for network connections. Each
zone can have different firewall rules.
Services are predefined rules that allow specific types of network traffic. Examples include HTTP, HTTPS,
FTP, and SSH.
Rich Rules:
Rich rules provide a way to create complex rules that are not possible with simple commands. They can
match specific IP addresses, ports, and protocols and apply specific actions like logging or rejecting.
Direct Rules:
Direct rules provide a way to interact with the low-level iptables rules directly. They are useful for advanced
configurations that are not supported by firewalld’s high-level commands.
1. Installation:
firewalld is installed by default on RHEL 8. If it’s not installed, you can install it using
Start firewalld:
87
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
3. Checking Status:
88
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
89
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
90
B.Sc. (H) ANCS-2022 and SEM-V
Linux Administration-II (BNCSC502)
Class: - Theory
2024-25
Question
Correct Answer
Number
1. c. Mangle
2. a. DROP
3. b. REJECT
4. c. –A
5. b. –p
6. d. -o
7. b. Nat
8. b. POSTROUTING
9. d. Both (a) and (b)
10. c. service iptables restart
11. b. getsebool
12. a. setsebool
13. a. setsebool
14. a. getsebool -l | grep httpd
15. a. getsebool -a
16. d. enabled
17. a. SELINUX=disabled
18. a. /etc/sysconfig/selinux
19. b. echo 0 > /selinux/enforce
20. c. sestatus
21. c. sudo dnf install firewalld
22. c. To define the trust level of network connections or interfaces
23. b. sudo systemctl start firewalld
24. d. Both b and c
25. a. sudo firewall-cmd --reload
26. c. sudo firewall-cmd --get-active-zones
27. b. sudo firewall-cmd --zone=public --add-port=8080/tcp
28. b. sudo firewall-cmd --zone=public --remove-service=ssh --permanent
29. d. sudo firewall-cmd --zone=public --list-all
15. What command would you use to check the status of the firewalld service?
16. How do you list all available zones in firewalld?
17. Which command lists all active zones and their associated interfaces?
18. How do you add the HTTP service to the public zone temporarily?
19. How can you reload the firewalld configuration to apply new settings?
20. What command would you use to permanently open port 8080/tcp in the public zone?
21. What does SELinux stand for?
22. How can you check the current status of SELinux on a RHEL 8 system?
23. What command is used to temporarily set SELinux to permissive mode?
24. Which configuration file is used to permanently set SELinux modes?
25. What are the three modes of operation for SELinux?
26. How do you install the SELinux troubleshooting tools on RHEL 8?
27. What is the command to list all SELinux Booleans?
28. How do you restore the default SELinux context for a specific file?
29. What is the purpose of the audit2allow tool?
30. How can you list all SELinux policies currently loaded on the system?
31. What does the -P flag do when setting an SELinux Boolean?
32. How do you add a custom SELinux policy module?
33. Which command provides detailed information about the SELinux context of a file?
34. What does the SELinux type httpd_sys_content_t typically represent?
35. How do you permanently disable SELinux on a RHEL 8 system?
1. How To List All The Rules Applied On Your System And How To Flush All Iptables Rules ?
2. What Are The Target Values In Iptables?
3. Explain the different modes of Selinux.
4. Explain about Selinux.
5. Explain the concept of DAC and MAC.
6. Explain the concept of firewalld zones and their importance. How would you change the default zone,
and what impact does this have on network security?
7. Explain the core concepts of SELinux (Security-Enhanced Linux) in RHEL 8, including the different modes
of operation and how they impact system security.
8. How does SELinux enforce security policies in RHEL 8? Explain the role of Type Enforcement (TE) and
Role-Based Access Control (RBAC) in SELinux.
92