Linux Question Bank Solution
This post share solution on most difficult and confusing questions of Bachelor of Computer Application (BCA) affiliated to Pokhara University on Linux subject.
2018 Fall
5 a) What do you mean by web server? Why are the needed? Explain.
A web server is a computer that stores web server software and a website’s component files. (for example, HTML documents, images, CSS stylesheets, and JavaScript files) A web server connects to the Internet and supports physical data interchange with other devices connected to the web. A web server includes several parts that control how web users access hosted files. At a minimum, this is an HTTP server. An HTTP server is software that understands URLs (web addresses) and HTTP (the protocol your browser uses to view webpages). An HTTP server can be accessed through the domain names of the websites it stores, and it delivers the content of these hosted websites to the end user’s device.
Why Are Web Servers Needed?
Without web servers the internet as we know it would cease to exist. Web servers are an integral part of the way the internet works. The web hosting industry is simply used to lease out web servers, providing average business owners and individuals with the opportunity to use high-tech servers that make it possible to expand their outreach to the entire world. Without rental web servers the internet would be a fraction of the size it is today, as most web site owners can afford to buy their own web server in cash.
Web servers are the gateway between the average individual and the world wide web, yet surprisingly web hosting plans start at only a couple of dollars per month. Now that you’re familiar with web servers you can begin shopping for a quality web hosting plan without the usual confusion that most novices experience.
- b) What do you mean by DHCP, DHCP server and DHCP client? How DHCP works? Explain
Dynamic Host Configuration Protocol (DHCP) is a client/server protocol that automatically provides an Internet Protocol (IP) host with its IP address and other related configuration information such as the subnet mask, default gateway and DNS Configuration.
Why use DHCP ?
- Every device on a TCP/IP-based network must have a unique unicast IP address to access the network and its resources. Without DHCP, IP addresses for new computers or computers that are moved from one subnet to another must be configured manually; IP addresses for computers that are removed from the network must be manually reclaimed.
- With DHCP, this entire process is automated and managed centrally. The DHCP server maintains a pool of IP addresses and leases an address to any DHCP-enabled client when it starts up on the network. Because the IP addresses are dynamic (leased) rather than static (permanently assigned), addresses no longer in use are automatically returned to the pool for reallocation.
DHCP Server:
The DHCP server typically has a pool of IP addresses that it is allowed to distribute to clients, and these clients lease an IP address from the pool for a specific period of time, usually several days. Once the lease is ready to expire, the client contacts the server to arrange for renewal.
The network administrator establishes DHCP servers that maintain TCP/IP configuration information and provide address configuration to DHCP-enabled clients in the form of a lease offer. The DHCP server stores the configuration information in a database that includes:
- Valid TCP/IP configuration parameters for all clients on the network.
- Valid IP addresses, maintained in a pool for assignment to clients, as well as excluded addresses.
- Reserved IP addresses associated with particular DHCP clients. This allows consistent assignment of a single IP address to a single DHCP client.
- The lease duration, or the length of time for which the IP address can be used before a lease renewal is required.
DHCP Client:
DHCP clients are client machines that run special DHCP client software enabling them to communicate with DHCP servers. All versions of Linux and Windows include DHCP client software, which is installed when the TCP/IP protocol stack is installed on the machine.
HOW DHCP WORKS:
DHCP clients obtain a DHCP lease for an IP address, a subnet mask, and various DHCP options from DHCP servers in a four-step process:
- DHCPDISCOVER:
The client broadcasts a request for a DHCP server.
- DHCPOFFER:
DHCP servers on the network offer an address to the client.
- DHCPREQUEST:
The client broadcasts a request to lease an address from one of the offering DHCP servers.
- DHCPACK:
The DHCP server that the client responds to acknowledges the client, assigns it any configured DHCP options, and updates its DHCP database. The client then initializes and binds its TCP/IP protocol stack and can begin network communication.
6 a) Why is DNS important? Explain the process of DNS configuration in Linux?
IP address are tough for human to remember and impossible to guess. DNS are usually used to translate a hostname or Domain name (eg. ncit.edu.np) into an IP address (eg. 208.91.198.170).
Why DNS is important
- DNS is the cornerstone of how the Internet operates. Every time you type a domain name into your browser, computer refers to a DNS server to find the corresponding IP address.
- When we type a website domain into your browser, like Websitehosting.com, our computer will use a DNS server to resolve the IP address of that website’s server. Once the IP address has been identified, our computer can then contact the website’s server, which in turn will serve your computer the website that you want to access. This is called Domain Name Resolution.
Process of DNS Configuration in Linux
The basic steps in creating a DNS server are as follows:
- Identifying DNS servers
- Install BIND DNS Server using following command
- Sudo yum install bind bind-utils –y
- Once the BIND is installed, start the BIND service and enable it to start at system reboot. Using
- systemctl start named
- systemctl enable named
- Creating DNS Configuration files : named.conf
- Create Forward and Reverse DNS Zone
- A Forward Zone is used to resolve the hostname to IP address while a Reverse Zone is used to resolve the IP address to hostname. Generally, all normal DNS queries are forward lookup queries. You can define the forward and reverse lookup zones in the /etc/named.conf file.
//Forward Zone for bca department.
zone “bca.local” IN {
type master;
file “bca.local.db”;
allow-update { none; };
};
//Reverse Zone
zone “2.0.10.in-addr.arpa” IN {
type master;
file “10.0.2.db”;
allow-update { none; };
};
- Create Forward and Reverse Zone Files : Create a forward zone file with the following command: nano /var/named/bca.local.db
- Then create reverse zone using nano /var/named/10.0.2.db
- Verify DNS Configuration
- After configuring all zone files, you will need to verify the configuration files. First, validate the main configuration file with the following command:
- named-checkconf /etc/named.conf
- Configure Firewall : Allow port 53 to allow DNS queries from client machines.
- Verify DNS Server: verify the forward lookup using the dig command:
- dig www.rosehosting.local
- b) What do you mean by database server? Explain the configuration of database server in linux.
2018 Spring
3 b) Explain the procedure of adding, removing and modifying user accounts in Linux with necessary commands and examples?
To create new user we use useradd command and supply different parameters below is the command to add User account in Linux
# useradd -c “Sara Green” –d /mnt/home/sara/ -s /bin/csh sara
# passwd sara
Changing password for user sara.
New password: **********
Retype new password: **********
Here user Sara is created with
-d /mnt/home directory and
-s : csh shell
-c: comment of user account
Then password is assigned to user.
To modify user we use usermod command; in this example we are changing shell for user chris and also assign user chris to another group of sales and marketing.
# usermod -s /bin/csh chris
# usermod -Ga sales,marketing chris
userdel is used to remove users. The following command removes the user chris:
# userdel -r chris
Here, the user chris is removed from the /etc/password file. The –r option removes the user’s home directory as well. If you choose not to use –r, as follows, the home directory for chris is not removed:
# userdel chris
Simply removing the user account does not change anything about the files that user leaves around the system (except those that are deleted when we use -r).
5 a) What is DHCP server? How can you configure DHCP server and client?
DHCP SERVER: Refer earlier answer
Below is the procedure to configure DHCP server:
Step 1:Install DHCP Server using following command:
sudo yum -y install dhcp-server
step 2: Step 2: Configure DHCP Server
Edit the DHCP server configuration file on using following command
sudo vi /etc/dhcp/dhcpd.conf
Configuration file will be populated with these parameters:
- Domain name: example.com
- DNS Server: ns1.example.com
- DHCP network: 192.168.20.0
- DHCP Subnet mask: 255.255.255.0
- Range of IP addresses to allocate: 192.168.20.30 – 192.168.20.200
- Default gateway: 192.168.20.1
- DHCP Lease Time: 600
- DHCP Maximum Lease Time: 7200
- We can modify the dhcp.conf file as below (if you can remember and have time )
# Set DNS name and DNS server’s IP address or hostname
# Declare DHCP Server
authoritative;
# The default DHCP lease time in seconds
default-lease-time 600;
# Set the maximum lease time in seconds
max-lease-time 7200;
# Set Network address, subnet mask and gateway
subnet 192.168.20.0 netmask 255.255.255.0 {
# Range of IP addresses to allocate
range dynamic-bootp 192.168.20.30 192.168.20.200;
# Provide broadcast address
option broadcast-address 192.168.20.255;
# Set default gateway
option routers 192.168.20.1;
}
- Step 3: Start and enable the dhcpd service after making the changes in the configuration file.
- Step 4: allow DHCP service through firewall, if firewall is enabled.
- Setp 5: How to check if DHCP is working or not on server and Leased ip addresses
- Check the /var/lib/dhcp/dhchpd.leases file. If the client has successfully been assigned addresses from the DHCP server, a lease line should appear in that file.
Configure DHCP Client
Step 1: Install DHCP client in your Linux machine to get an IP address automatically.
$ sudo yum -y install dhcp-client
Step 2:
Edit /container/name/rootfs/etc/sysconfig/network-scripts/ifcfg-iface, where iface is the name of the network interface, and change the value of BOOTPROTO to read as:
BOOTPROTO=dhcp
- b) Explain the procedure of setting up of web server? How a website can be hosted in LAN using Linux?
Step 1: Installation of Apache webserver:
To install apache use following code
[raju@localhost ~]$ sudo yum install httpd
Step 2: Start the Http process
After installation of apache start the httpd service and to enable apache service even after system reboot use following command respectively:
[raju@localhost ~]$ systemctl start httpd
[raju@localhost ~]$ systemctl enable httpd
Step 3: Allow through firewall
Configure firewall to allow http and https services which will allow port 80 and 443 incoming connection use following command
[raju@localhost html]$ sudo firewall-cmd –add-service=http –permanent
Step 4: Create index.html file
Once all above processes are executed now create index.html using any text editor by going to
[raju@localhost html]$ cd /var/www/html
#index.html
Step 5: Configuring the Apache Server
The primary file for configuring your Apache Web server is httpd.conf (located in the /etc/httpd/conf directory). All Apache configuration files are plain-text files and can be edited with your favorite text editor.
Configuring the Web server (httpd.conf)
The httpd.conf file is the primary configuration file for the Apache Web server. It contains options that pertain to the general operation of the server. The default filename (/etc/httpd/conf/httpd.conf) can be overridden by the -f filename command-line argument to the httpd daemon or the ServerConfigFile directive. The following sections list the contents of the httpd.conf file and describe how to use the file.
To host a website in LAN after completing above steps for webserver and website configuration following below steps:
Step 1: Configure Static IP address on the web-server on linux server.
Step 2: Configure DNS server and add ‘A’ record in forward look zone. So client machine can browse webserver using domain name.
6 a) What is MYSQL Database? Write configuration file and setting for MYSQL Database?
- b) What is BIND Server? Define configuration settings for DNS server.
2017 Fall
2 b) Write the command syntax for the following purpose.
- To create a user “Linux” with password “redhat”.
- To change the password for that user to “fedora”.
- To create a group “Hackers”.
- After all assign the group “Hackers” for the user “Linux”.
- After all provide comment name “Blackcat” and login shell “bash” for that user.
- Then assign the expiry date for that user account.
- To delete that group.
- To remove that user.
5 a) What is the role of DNS? Explain DNS configuration process in linux with example.
- b) Why is Apache Web Server popular? Discuss Apache Web Server configuration.
6 a) What is the purpose of DHCP server in computer network? Write the process of configuring DHSP server and client.
- b) What is database server? Explain configuration setting for MYSQL as database server.
2015 Fall
4 b) Why is Apache Web Server popular? Discuss Apache web server’s main server configuration and directive’s in detail.
5 a) What is DHCP server? How can you configure DHCP server and client?
- b) What is the package name and daemon of MYSQL? How do you check and install MYSQL package? How do you start MYSQL service?
6 a) Define BIND server. Explain configuration setting for DNS server.
- b) How can we reconfigure hardware with kudzu? Write its step.
2016 Fall
2 b) What is kudzu? What are the module configurations commands write with example each.
5 a) Explain the procedure of setting up of web server? How a website can be hosted in LAN using Linux?
- b) Why is DHCP server is necessary? Explain about the configuration file used?
6 a) What do you means by database server? Write the configuration for mysql database server?
- b) How can you configure DNS server in Linux system? Write down the configuration files.
2015 Spring
3 b) Why is Apache web server popular? Discuss Apache Web Server configuration.
4 a) Define DHCP. How can you set up DHCP server and client.
- b) What is database server? Define configuration setting for MYSQL database server and client sites.
6 a) What are the roles of using DNS in network? Write the process to configure domain using BIND.
b) Explain the various processes
Question: What do u mean by backup and restore?
Backup and restore refers to technologies and practices for making periodic copies of data and applications to a separate, secondary device and then using those copies to recover the data and applications—and the business operations on which they depend—in the event that the original data and applications are lost or damaged due to a power outage, cyberattack, human error, disaster, or some other unplanned event.
Backup and restore is an essential component of any business’ disaster recovery strategy.
Different types of Backup are (if the question is only about backup and restore explain full and incremental backup)
Full backup
A full backup is one that stores every file on a particular disk or partition. If that disk should ever crash, you can rebuild your system by restoring the entire backup to a new disk. Whatever backup strategy you decide on, some sort of full backup should be part of it. You may perform full backups every night or perhaps only once every week; it depends on how often you add or modify files on your system, as well as the capacity of your backup equipment.
Incremental backup
An incremental backup is one that contains only those files that have been added or modified since the last time a full backup was made. You may choose to do incremental backups to conserve your backup media. Incremental backups also take less time to complete. This can be important when systems are in high use during the work week and running a full backup would degrade system performance. Full backups can be reserved for the weekend when the system is not in use.
Tools for backup
1. To backup on Writable DVD Drives
The dvdrecord command should allow you to burn DVDs on any DVD burner that is compliant with the Multimedia Command (MMC) standard.
The first step is to create an image of the DVD file system as a file on your computer. You do this with the mkisofs command. As an example, imagine that you want to back up the home directory for user raju. You would invoke the mkisofs command and pass it the name of the file system image file to create, followed by the directory to base it on:
$ mkisofs -R -o /var/tmp/raju.cd /home/raju
This creates an ISO9660 file system image in a file named raju.cd located in the /var/tmp directory.
Then we will burn this image on DVD
# dvdrecord -v speed=2 dev=0,0,0 -data raju.cd
2. Creating a backup with dump on external Hard disk.
When making a file system backup using the dump command, you must supply parameters specifying the dump level, the backup media, and the file system to back up. You can also supply optional parameters to specify the size of the backup media, the method for requesting the next tape, and the recording of file system dump times and status.
# dump options arguments filesystem
# dump 0uf /dev/qft0 /dev/hda6
This command results in dump performing a level zero (full) backup of the /dev/hda6 file system, storing the backup on the tape drive /dev/qft0 (option f), and recording the results in /etc/dumpdates (for option u). The dump command prints status messages to the screen, letting you know how far along the backup has progressed and estimating how much time it will take to complete.
If the question ask you about cron job explain below only with dump command mention above
Install dump using following command:
[raju@localhost ~]$ sudo yum install dump
[raju@localhost ~]$ sudo yum install mt-st
You can automate most of your backups with shell scripts and the cron daemon. Use the su command to become root, and then cd to the /usr/local/bin directory. Now create script called backup.sh to backup the data.
#!/bin/sh
if [ $1 ]; then
level=$1
else
#
# No dump level was provided, so set it
# to zero
#
level=”0″
fi
#dump 0uf /dev/qft0 /dev/hda6
/sbin/dump $level’uf’ /dev/nrft0 /
/sbin/dump $level’uf’ /dev/nrft0 /home
/sbin/dump $level’uf’ /dev/nrft0 /var
/sbin/dump $level’uf’ /dev/nrft0 /usr
if [ $level = “0” ]; then
/usr/bin/mt -f /dev/nrft0 rewind
/usr/bin/mt -f /dev/nrft0 offline
Fi
Exit the text editor and make this file backup.sh executable
# chmod 700 backups.sh
Now using cron job schedule it
# crontab –e
This opens the root crontab file in an editor. Add the following lines at the end of the file:
0 22 * * 0 /usr/local/bin/backup.sh 0
0 22 * * 1 /usr/local/bin/backup.sh 9
0 22 * * 2 /usr/local/bin/backup.sh 8
0 22 * * 3 /usr/local/bin/backup.sh 7
0 22 * * 4 /usr/local/bin/backup.sh 6
0 22 * * 4 /usr/local/bin/backup.sh 5
0 22 * * 5 /usr/local/bin/backup.sh 4
Save and exit the file. The cron daemon will now run the backup script at 10:00 p.m. every day of the week.
Question: Steps of disk quota.
I. Creating quotas directory: Here we are going to create quota on /home directory for user Ram.
II. Enable quotas per file system by modifying the /etc/fstab file.
As root, using a text editor, edit the /etc/fstab file. Add the usrquota and/or grpquota options to the file systems that require quotas:
# sudo Vim /etc/fstab
/dev/mapper/cl-mydrive /mydrive xfs defaults,usrquota,grpquota 0 0
Save and exit vim
III. Remount all mount point or we can remount our drive.
Mount –a OR Mount –o remount /dev/sda4 /mydrive
IV. Reboot the machine
V. Creating the Quota Database Files
To create the quota files (aquota.user and aquota.group) on the file system, use the -c option of the quotacheck command. For example, if user and group quotas are enabled for the /home file system, create the files in the /home directory:
# quotacheck -cug /home
After the files are created, run the following command to generate the table of current disk usage per file system with quotas enabled:
# quotacheck -avug
VI. Creating quota rules
root@localhost ~]# quotaon /home
This command will create quota rule on /home directory.
VII. Create quota rule for user RAM
[root@localhost ~]# edquota ram
Now assign quota to Ram user , we can use either block or inode quota.
Disk quotas for user ram (uid 1002):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/cl-home 0 0 0 0 10 12
Question: What are the modules on linux system, How do you use them. Explain.
Kernel modules are chunks of code that are loaded and unloaded into the kernel as needed, thus extending the functionality of the kernel without requiring a reboot. In fact, unless users inquire about modules using commands like lsmod, they won’t likely know that anything has changed.
One important thing to understand is that there are lots of modules that will be in use on your Linux system at all times and that a lot of details are available if you’re tempted to dive into the details.
One of the prime ways that lsmod is used is to examine modules when a system isn’t working properly. However, most of the time, modules load as needed and users don’t need to be aware of how they are working.
We can use Module by loading them
You can load any module (as root user) that has been compiled and installed (to a /lib/modules subdirectory) into your running kernel using the modprobe command.
A common reason for loading a module is to use a feature temporarily. Another reason to load a module is to identify that module as one that will be used by a particular piece of hardware that could not be autodetected.
Here is an example of the modprobe command being used to load the parport module, which provides the core functions to share parallel ports with multiple devices:
# modprobe parport
After parport is loaded, you can load the parport_pc module to define the PC-style ports available through the interface. The parport_pc module lets you optionally define the addresses and IRQ numbers associated with each device sharing the parallel port, as in the following example:
# modprobe parport_pc io=0x3bc irq=auto
In this example, a device is identified as having an address of 0x3bc, and the IRQ for the device is autodetected.
The modprobe command loads modules temporarily—they disappear at the next reboot.
To add the module to your system permanently, add the modprobe command line to one of the startup scripts run at boot time.