Linux Interview1
Linux Interview1
Linux Interview1
What is fragmentation?
Fragmentation occurs when a piece of data in memory is broken up into many pieces that are not close
together
OR
Fragmentation occurs when the operating system cannot or will not allocate enough contiguous space to
store a complete file as a unit, but instead puts parts of it in gaps between other files
Scattered Data
What is Semaphore?
Locking Mechanism used inside resource mangers and resourse dispensers.
LINUX BASICS
What are the main flavors of UNIX?
System V (five) from AT&T
HP-UNIX
IBM-AIX
SCO-UNIX
SOLARIS
BSD
/etc/rc.d
It has a single script for each runlevel.
Name
Valhalla
Psyche
Shrike
Date
Kernel Version
2.4.18-3
2.4.8-14
2.4.20-8
Name
Yarrow
Tettnang
Heidelberg
Stentz
Bordeaux
Date
November 5, 2003
May 18, 2004
November 8, 2004
June 13, 2005
March 20, 2006
Kernel Version
What is Fedora?
Fedora is a set of projects, sponsored by Red Hat and guided by the Fedora Foundation. These projects are
developed by a large community of people who strive to provide and maintain the very best in free, open
source software and standards
Fedora
Fedora Core is intended for personal, hobbyist, and
developer use
Fedora Core 3 is much advance having latest kernel
2.6 and newer developer tools.
Fedora Core 4 is having latest gcc and tools.
No Support
Free
What is a kernel?
The kernel is the core piece of most operating systems. It is a piece of software responsible for the
communication between hardware and software components.
/proc:
procfs is short for process filesystem: a pseudo-filesystem which is used to access kernel information
about processes. Because /proc is not a real file system, It was designed in order to replace the ptrace
system call used for process tracing
What is SWAP?
Its an extension of RAM.
How many number of swap files you will create? What is the maximum total size for
SWAP?
Red Hat Enterprise Linux 2.1 supports upto 32 swap partitions, each can be a maximum size of 2GB.
Maximum total swap size is 64GB.
RHEL 3 supports swap size till 1TB
How much disk space should you allocate for the /proc filesystem?
We dont have to. It does not consume any storage space, and it consumes only a limited amount of
memory.
halt
single user mode
multi user mode (No network)
multi user mode (with network)
X windows
Reboot
init 6
|
inittab
|
/etc/rc.d/rc
|
/etc/rc.d/rc6.d/
username:passwd:last:may:must:warn:expire:disable:reserved
username
last
The minimum period in days that must expire before the password can be changed
must
Expire
7
disable
reserved
A reserved field
The previous example might then be:
username:Npge08pfz4wuk:9479:0:10000::::
How does enabling shadow passwd's change the functionality of user authentication?
Why is there an /etc/shadow (or similar, differently-named)file? What is in it, and how
is it different from /etc/passwd?
When a system has shadow passwords enabled, the password field in /etc/passwd is replaced by an "x"
and the user's real encrypted password is stored in /etc/shadow.
How you gonna check on which redhat linux version you are working on?
# cat /etc/redhat-release
How do you findout whether a command is an aliases, bash function, built-in like cd and
type, or executable program?
# type -all yourcmd
CRON/ANACRON
Whats the difference between CRON and AnaCRON
CRON:
8
cron assumes your system is running. continuously. (and that crond is running).
AnaCRON:
Anacron uses a config file and time stamps to determine the last time a task was done. If the tasks is
overdue to be done, anacron makes sure it gets done.anacron does not run continuously. It is a one shot
command. It is usually invoked on bootup
Anacron looks at boot-time if something was missed while the computer was off.
Used to control the execution of daily, weekly, and monthly jobs
When I add a new task to my crontab, I get an e-mail evertime it has been executed. Can
this be avoided in some way?
Yes, append '> /dev/null' to your crontab entry.
Example:
30 04 * * * mydailyscript.sh > /dev/null
How do you find all the programs, and there location, using sockets or pipes on your
computer?
lsof
How do you create directory and subdirectories when the parent directory may exist, in one
command? In other words, create the following directory structure.
/home/user/one/two The command should work whether /home/user exists or not.
mkdir -p /home/user/one/two The -p or "parents" makes the parent directory as needed.
If someone talks about ext2 and ext3 filesystems, what are they most likely running
Debian or Redhat?
RedHat
How do you create a directory that's sharable to a group, that by default, will have each file
created as sharable to a group.
Mkdir <dir>
Chmod 770 <dir>
What options to (GNU) tar(1) would you use to decompress and extract everything from
an archive named files.tar.gz into the current directory?
# tar zxvf file.tar.gz
If you mistype a password, how do you clear it out to retype the password again.
Ctrl-C .
- CDROM
What command would you use to check available disk space on all currently-mounted disk
partitions?
# df h
how would you add a user to your system? What files get modified?"
# useradd <username>
It modifies two files:
/etc/passwd
/etc/shadow
10
there is no need to defragment an ext partition (2 or 3) because of the way it arranges the data,
How do I remove those enoying ^M chars from textfiles that has been generated on a
Microsoft platform?
Use the 'tr' command to remove them like this:
# cat <thefile.txt> | tr -d '\r'
This will output the new file without the ^M charters to your standard output. Just redirect them using the
'>' char to get the result in to a file like this:
# cat <thefile.txt> | tr -d '\r' > newfile.txt
tr translate
-d delete
\r return
How do you give a user access to an application or program that needs to run as root
without giving them the root password?
I would use sudo or setuid
What are the steps involving the recompilation of the linux kernel
1. untar the tar file into /usr/src/kernel
2. vi Makefile (change the ver. )
3. make menuconfig or ./config or
4. make deps
5. make bzImage
6. cp /kernel/arc/i386/boot/bsImage to /boot/bzImage
7. cp /kernel/system.map to /boot/system.map
8. make
9. make check
10. make install
11
Both are same
If I'm logged in as root, what command lets me "become" another user id?
su
What is /etc/inittab?
Startup sequence file
What is the first process to start on a UNIX system, after the kernel?
init
12
What is an X Server?
graphical display device,7optional
What is the main advantage of creating links to a file instead of copies of the file?
A: The main advantage is not really that it saves disk space (though it does that too) but, rather, that a
change of permissions on the file is applied to all the link access points. The link will show permissions of
lrwxrwxrwx but that is for the link itself and not the access to the file to which the link points. Thus if you
want to change the permissions for a command, such as su, you only have to do it on the original. With
copies you have to find all of the copies and change permission on each of the copies.
What is the most graceful way to get to run level single user mode?
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do init 0 first and from the ok
prompt do a boot -s.
What does the following command line produce? Explain each aspect of this line.
$ (date ; ps -ef | awk {print $1} | sort | uniq | wc -l ) >> Activity.log
A: First lets dissect the line: The date gives the date and time as the first command of the line, this is
followed by the a list of all running processes in long form with UIDs listed first, this is the ps -ef. These
are fed into the awk which filters out all but the UIDs; these UIDs are piped into sort for no discernible
reason and then onto uniq (now we see the reason for the sort - uniq only works on sorted data - if the list
is A, B, A, then A, B, A will be the output of uniq, but if its A, A, B then A, B is the output) which
produces only one copy of each UID.
These UIDs are fed into wc -l which counts the lines - in this case the number of distinct UIDs running
processes on the system. Finally the results of these two commands, the date and the wc -l, are appended
to the file "Activity.log". Now to answer the question as to what this command line produces. This writes
the date and time into the file Activity.log together with the number of distinct users who have processes
running on the system at that time. If the file already exists, then these items are appended to the file,
otherwise the file is created.
Question 5: What is CVS? List some useful CVS commands.(Asked by Silicon Magic
Corp.people)
CVS is Concurrent Version System. It is the front end to the RCS revision control system which extends
the notion of revision control from a collection of files in a single directory to a hierarchical collection of
directories consisting of revision controlled files. These directories and files can be combined together to
form a software release.
There are some useful commands that are being used very often. They are
cvs checkout
cvs update
cvs add
13
cvs remove
cvs commit
What is PAM
What is Jouranaling
The act of moving pages of memory from RAM to virtual memory on a hard drive. Excessive paging is
caused by a lack of actual system memory. In this case the system has to use the hard drive as memory
frequently, and performance is degraded.
What are the main differences between Apache 1.x and 2.x?
What does the route command do?
What are the read/write/execute bits on a directory mean?
What is SED?
SED (which stands for Stream EDitor) is a simple but powerful computer program used to apply various
pre-specified textual transformations to a sequential stream of text data.
It reads input files line by line, edits each line according to rules specified in its simple language (the sed
script), and then outputs the line.
What is AWK
AWK is a complete pattern scanning and processing language, it is most commonly used as a Unix
command-line filter to reformat the output of other commands.
For example, to print only the second and sixth fields of the date command (the month and year) with a
space separating them, at the Unix prompt, you would enter:
date | awk {print $2 $6}
What's your biggest fuck up, and how did you fix it?
now tell me how you would a) mirror the rootdisk, b) grow an existing filesystem, or c)
modify the partition table for a disk on that OS.
Do you consider the open source movement to be a threat to the commercial software
industry?
Do I need to reboot the machine after increasing the maximum number of open files at
/etc/security/limits.conf
No
/etc/security/limits.conf
* - nofile 2048
14
Verify this with the following command:
ulimit -n
ulimit -a
Look for line:
open files
(-n) 2048
System Monitoring
How do I change the priority of a process?
nice, renice, priocntl (SysV.4)
Like when you use 'uptime' (or 'w'), what do the three numbers after 'load average'
represent?
What is a zombie process and how do you find them?
When a process creates a child process "fork() command" and that child process terminates, information
about the child process (CPU time, memory, etc.) exists for the parent to fetch. The parent can use the
"wait" or "waitpid" to fetch this signal. The child process becomes a zombie as soon as it finishes; but,
the SIGCHLD hasn't been caught.
ps -aux, will show all processes. Look for "Z" in that stat and defunct under the command.
Note: wait may still produce zombies. This can happen of child A terminates, and it's signal has been
caught. While this signal is being process child B terminates. Since these signals won't queue, child B
could stay in the zombie state. It's safer to use the waitpid call.
Describe the various metrics and procedures you would use to evaluate the performance
and system utilization of a linux machine
What are some shells you'd find on a Unix box?
Answer should include at least: Bourne shell (sh), C-Shell (csh) and Korn shell (ksh). Might also mention
Tom's C shell (tcsh), Bourne-again shell (bash), or z-shell (zsh).
How would you find the most recently changed file in a directory?
ls ltr
15
How would you find all the processes being run by user "joe?"
System 5: ps -fe | grep joe
Berkeley: ps -auxww | grep joe
There are two unix machines named A and B that are on the same subnet. Describe to me, in as much
detail as possible, what happens when I type "telnet B" from a terminal on machine A.
incremental backup only backs up files that have been created or modified (their archive bit
is set to 1) since the last normal or incremental backup. An incremental backup also clears
the archive bit (sets the archive bit back to 0) of all files that it backs up.
Q3. reinstall the os.
start -> run -> type ntbackup -> ok -> next -> select restore -> next -> select backup files -> next ->
finish
Basic Networking
What's a socket? What's a port? How do you reserve them? how are they related? How do
you find out what's going on with them on a system?
Normally, a server runs on a specific computer and has a socket that is bound to a specific port number.
The server just waits, listening to the socket for a client to make a connection request.
Socket: IP + Port
Port: is a virtual data connection. Programs binds on the port to exchange the data.
What would you use to view the contents of TCP packets on the network
# tcpdump
How would you check TCP packets coming from Remote IP?
# tcpdump i <interface> src <IP>
16
ethernet.
What should be found in the /etc/hosts file?
How would you check the route table on a workstation/server
Trouble Shooting
4. Where would you look for startup and error messages on a Unix server?
/var/adm/messages (/usr/adm/syslog on HP-UX boxes). They can also run the command dmesg.
TROUBLESHOOTING
How would you restore GRUB boot loader (MBR)
1.boot from RHEL CD 1.
Boot: linux rescue
2. chroot /mnt/sysimage
3. grub-install /dev/hda3
Type "grub" which makes a GRUB prompt appear.
1. Type "find /boot/grub/stage1". You'll get a response like "(hd0)" or in my case "(hd0,2)". Use whatever
your computer spits out for the following lines.
1.boot from RHEL CD 1.
Boot: linux rescue
2. grub> root (hd0,2)
3. grub> setup (hd0,2)
4. grub> quit
KERNEL COMPILATION
When would you want to reconfigure the kernel and how would you do it?
If incase your hardware doesnt supports, Enabling SMP
RAID
RAID
===
17
What is striping?
A technique for spreading data over multiple disk drives. Disk striping can speed up operations that
retrieve data from disk storage. The computer system breaks a body of data into units and spreads these
units across the available disks. Systems that implement disk striping generally allow the user to select the
data unit size or stripe width.
Disk striping is available in two types. Single user striping uses relatively large data units, and improves
performance on a single-user workstation by allowing parallel transfers from different disks. Multi-user
striping uses smaller data units and improves performance in a multi-user environment by allowing
simultaneous (or overlapping) read operations on multiple disk drives.
Mail Server
6.
If you send an e-mail to someone and it comes back "Message Undeliverable", what could be
wrong.
7.
You can receive e-mail, but can't send any. What is wrong?
- Name at least two types of server process that can be an open mail relay but are not SMTP server
processes.
- Explain in what ways each of the IMAP, POP3, and SMTP protocols are used.
- Give at least two differences between IMAP and POP3.
- Explain at least one way that SMTP is used that does not involve a mail user agent.
(Bonus points for creative answers.)
- What is an open mail relay?
- How would you test an SMTP server to see if it is an open mail relay?
- Name at least two types of server process that can be an open mail relay but are not
SMTP server processes.
- What are the basic commands to send a message to an SMTP server?
(Hint: Begin with HELO.)
What is /etc/aliases? mail aliases for systems
Is there an easy way to find out which mailservers that handles incoming e-mail for a domain?
18
Answer
Yes, this can be done with the 'host' command. Have a look at the manpage for more information on how
to use it.
Example:
# host mreriksson.net
mreriksson.net has address 62.20.106.119
mreriksson.net mail is handled (pri=10) by mail.mreriksson.net
#
Is there some interactive way to view active processes in the system based on their size or cpu-usage?
Answer
Many unix/linux systems comes with a command called 'top' that does this. See the manpage for top for
detailed information on how to display processes based on cpu- or memory-usage.
Web Server
how to install and configure an Apache Web server.
How do I know what modules I have availible in my installation of apache?
Answer
Execute: 'httpd -l', this will show you a list of all availible modules.
-------------------------------------------------------------------------------Question 2
What user should the stand-alone server be ran as?
Answer
It should be ran as root to be able to attach to port 80. Apache will then spawn it's children with the owner
you specify in the httpd.conf file. (Which should be a user without any additional access)
-------------------------------------------------------------------------------Question 3
When would I use the inetd daemon to execute Apache?
Answer
Since running Apache from inetd will slow down new client connections quite alot, it's best suited for
servers which doesn't handle alot of requests, and would are low on memory.
Note: To run Apache from inetd can also make life a bit easier when working with apaches configuration
files, since they will be re-read as soon as a new client connects.
--------------------------------------------------------------------------------
19
Question 4
Can I prevent a user to override my global settings with the .htaccess file?
Answer
Yes, you can do this with the 'AllowOverride' option in the config file.
Example:
<Directory />
AllowOverride None
</Directory>
This will prevent users from using the .htaccess file in all directories.
-------------------------------------------------------------------------------Question 5
Is the UserDir module safe to use?
Answer
The UserDir module is said to be safe if the html pages arn't stored in the users homedirectory. Instead
you should set up an additional directory for each user outside it's homedirectory, and use the following
configuration:
<IfModule mod_userdir.c>
UserDir /home/httpd/*/
</IfModule>
And for each user have a directory, which they own, under /home/httpd/, with the same name as the user.
This will enable users to have an URL like http://host.fo/~user
-------------------------------------------------------------------------------Question 6
How should I configure Apache to make it serve WAP pages?
Answer
You should add these lines to your Apache configuration:
AddType text/vnd.wap.wml .wml .wml
AddType Application/vnd.wap.wmlc .wmlc
AddType text/vnd.wap.vmlscript .wmls
AddType Application/vnd.wap.wmlscriptc .vmlsc
AddType image/vnd.wap.wbmp .wbmp
The you should locate the 'DirectoryIndex' directive in the file, and add the 'index.wml' tag to it, should
look something like this afterwards:
<IfModule mod_dir.c>
DirectoryIndex index.html index.wml
20
</IfModule>
This tells Apache to look for a file named index.wml if no file is specified in the requested URL.
(Example: http://host.fo/wap/ )
Note: There might be more arguments here if you, for example, have installed support for PHP or Perl.
-------------------------------------------------------------------------------Question 7
How do I use Apaches user authentication (htaccess) ?
Answer
First of all, you need to configure your Apache server to allow usage of the .htaccess file for
authentication control. This is done by adding the keyword 'AuthConfig' to the 'AllowOverride' option in
the current <Directory> block. Based on the default configuration, you might end up with something like
this:
<Directory />
Options FollowSymLinks
AllowOverride AuthConfig
</Directory>
This enables the usage of .htaccess in all directories in your filesystem. (For security reasons, you might
want to limit this to a certin directory instead of the filesystem root)
To limit the access to a directory and all it's sub-directories, you should create a file called '.htaccess'
within it. This file should contain the following options:
AuthName ZoneName
AuthType Basic
AuthUserFile /usr/local/etc/apache/htusers
Require valid-user
AuthName configures the name of this authenticated zone. By defining the same name in several zones,
they can be included in the same authentication session, and thereby only require the user to login once to
access all zones on the site.
AuthType defines the type of authentication that should be used, the 'Basic' type is the most widespread
one and will provide the best compatibility.
AuthUserFile referes to the htpassword file to fetch login information from. This file can be generated by
using the htpasswd(1) command provided with the Apache package, or via the online tool availible at
http://mreriksson.net/online/htgenerator/ .
The Require option tells Apache which usernames to accept for this zone. Using the 'valid-user' keyword
will allow all users defined in the AuthUserFile to login. The 'user' keyword allows a whitespace
separated list of usernames that are allowed from the given userfile. Example: Require user user1 user2
user3
21
-------------------------------------------------------------------------------Question 8
Is there a way to allow virtual hosts to have their own cgi-bin directory?
Answer
Yes, this can be specified using the ScriptAlias-option in the <VirtualHost> block that you want to enable
this for.
Example:
<VirtualHost *>
ServerAdmin webmaster@foo.bar
DocumentRoot /home/httpd/www.foo.bar/public_html/
ServerName foo.bar
ServerAlias www.foo.bar
ScriptAlias /cgi-bin/ /home/httpd/www.foo.bar/cgi-bin/
ErrorLog /home/httpd/www.foo.bar/logs/error_log
CustomLog /home/httpd/www.foo.bar/logs/access_log common
</VirtualHost>
Note:
It's important that you end the path to the cgi-bin directory with a slash (/), or Apache will fail to find your
cgi's.
-------------------------------------------------------------------------------Question 9
When using ScriptAlias to allow site-specific cgi-bin-directories, is there a way to require the user to log
in before the cgi's can be accessed?
Answer
Yes, this can be done in the normal way with the htaccess-system. Just place a .htaccess-file that
configures the authentication-requirements in the cgi-bin directory.
DNS Server
- What is found in a DNS zone file? (Assume BIND running on a POSIX operating system.)
- What is the purpose of an MX record?
- What data is transferred in a DNS zone transfer?
- In what circumstances would you permit systems outside of your local/corporate network
to perform DNS zone transfers? In what circumstances would you not?
2. What files are used to configure DNS on a Unix box
/etc/resolv.conf and /etc/nsswitch.conf
-
22
Know the options available in /etc/named.conf.
DNS
------------# What is DNS
DNS stores the database of domain name and its corresponding IPs.
It is used for translating domain name to IP and vice versa
# What port no does DNS uses?
53
# What are the types of DNS?
Caching Name Server named.ca (root servers)
Authoritive Name Server
# How many Root Name Servers worldwide
13
# what is the configuration file?
/etc/named.conf
defining Zones
/etc/resolv.conf
defining Name Server
/etc/nsswitch.conf
# Where would you define the Zone Records?
/etc/named.conf
# What are the types of Resource Records?
NS
A
PTR
CNAME
MX Mail Exchanger
Q. What is use of CNAME
CNAME is used for giving an alias for Domain name
Q. How to check any RR record for domainname ?
# dig domainname
# nslookup domainname
# dig MX domainname
# nslookup -query=NS linobox.com
Q. What is found in a DNS zone file
Resource Records
Q. What is the purpose of an MX record?
23
To define the Mail Server
Q How one can configure round robin in DNS server in linux
www.dgshiping.com IN A 1.2.3.1
www.dgshiping.com IN A 1.2.3.2
www.dgshiping.com IN A 1.2.3.3
Q How to set MX Priority in DNS Server
Eg Priority can be given for any three Server
MX 10 mailhost
MX 100 mailhost.matrix.co.in.
MX 200 www.matrix.com.
NFS Server
What is NFS?
NFS is Network File System
It is basically used for sharing files & directories on a network.
What is its job?
allow machines to mount a disk partition on a remote machine
Why is it necessary to start portmap service before nfs service
Portmap serves RPC calls which is necessary for NFS
What is RPC
Library routines for remote procedure calls
These routines allow C programs to make procedure calls on other machines across the network.
On which port NFS runs?
2049
Which service is required for NFS?
# service portmap start
# service nfs start
Which daemons are required for NFS?
Rquotad
Mountd
Nfsd
Nlockmgr
Name the configuration file for NFS?
/etc/exports
24
How would you share /home/exports to a specific machine (192.168.20.10) with read/write permission?
# vi /etc/exports
/home/exports 192.168.20.10(rw)
# What is the default permission for NFS mount point?
Read only with root_squash option
what do you mean by no_root_squash
no_root_squash - Allows root users on client computers to have root access on the server. Mount requests
for root are not be mounted to the anonomous user. This option is needed for diskless clients
no_root_squash will make sure root users on the clients have actual root permissions on the nfsd as well
what is root_squash?
Root users mounted as nobody user and privileges given for others (other users) on mounted directory
will be assigned for root user.
How to mount NFS filesystem remotely?
# mount t nfs 192.168.20.100:/home/exports /nfsmount
Remote NFS filesystem should be automounted on startup?
# vi /etc/fstab
192.168.20.100:/gome/exports /nfsmount
nfs defaults
25
9. These helper damons, like all daemons, needs ports to bind to [monitor] and
run on. Are these ports given in /etc/services?
A: No
10. Then how do these daemons get ports?
A: portmapper daemon is used to dynamically assign port nos to these RPC
services which can be seen by "rpcinfo -p". In /etc/rpc
11. What port does NFS use?
A: 2049
12. And how do you know that?
A: /etc/services
13. What port does portmapper use?
A: 111
14. RPC services have their own config file. What is it?
A: /etc/rpc
15. Display a list of NFS shares from a client if the server is shiva
A: showmount -e shiva
16. How does one check the status of a NFS server?
A: showmount -e localhost
17. Which file is configured on a NFS server to facilitate sharing across a NW?
A: /etc/exports
18. How does one refresh NFS shares?
A: exportfs -ra
19. What does this refresh mean?
A: Telling the NFS daemon to re-process /etc/exports and rebuild the NFS
mount table config file, which is...., cannot say, since it a question.
See later.
20. Which NFS file shows the export permissions of all exported directories ?
26
A: /var/lib/nfs/rmtab
21. Which NFS file shows the info about currently exported dirs, which 'mountd'
reads when processing client mount requests and is rebuilt every time
'exportfs' is run?
A: /var/lib/nfs/xtab
22. How would you check who [remote hosts ] were using your NFS server and
which files were in use?
A: nfsstat -a
23. I wish to temporarily export a dir /jokes on shiva to brahma with r/w
perms. How?
A: exportfs brahma:/jokes -o rw
24. Temporarily? What's that?
A: It isn't configured in /etc/exports and on a 'service nfs restart'
would no longer exist!
25. How would you do the same permanently ?
A: Configure /etc/exports : /jokes brahma(rw)
26. Then how would you unexport this temporary dir, if I did not wish to do a
'service nfs restart'?
A: exportfs -u brahma:/jokes
27. Can I unexport all exported dirs w/o shutting down/restarting the NFS
daemons? How?
A: Yes.
28. How?
A: exportfs -ua
29. How would you know there are no shares now which are exported?
A: showmount -e
30. Explain the following /etc/exports file on NFS server ganesh:
/
shiva brahma
27
brahma in r/o mode
31. How would a user foo on a remote client brahma mount this on her local
empty dir /win ?
A: Cannot. Only root can do remote NFS mounts. This is how :
mount ganesh:/ /win
32. Can a user foo delete any files in the NFS share win?
A: No
33. What about the local root?
A: No
34. Why not ?
A: Local root is squashed by the NFS server by default
35. squashed ?
A: Local root is converted to another user.
36. So what user is this local root squashed to?
A: nfsnobody.
37. And is this a VLU ?
A: Yes!
38. And what is this nfsnobody's user/group id?
A: 65534/65534
39. Did you create this user?
A: No way! It's what's called a system a/c. Created on install by RH
40. Now examine this /etc/exports file on ganesh:
/
shiva(rw) brahma(rw,no_root_squash)
28
share's rw perms on it. So ?
A: ls -ld
on ganesh
show this :
drwx-r-xr-x
Although NFS does allow it, dir perms of the OS do not for
[no "w" for 'others'].
'root', meanwhile, has also been squashed!
42. Explain the following /etc/exports file :
/
shiva(rw)
shiva (rw)
A: Exports the entire filesystem to machine shiva with r/o access and to the
entire world with write access. Precisely what you did not want, in reverse!
44. Explain the following /etc/exports file :
/
192.168.0.
A: Exports the entire FS to all m/cs on segment 192.168.0 with r/o access.
45. Explain the following /etc/exports file :
/projects
proj*.local.domain(rw)
@trusted(rw)
pc001(rw,all_squash,anonuid=100,anongid=100)
A: These options explicitly set the uid and gid of the anonymous account
which would normally have been nfsnobody [65534/65534]. So why bother ?
Primarily useful for PC [M$] / NFS clients, where you might want all
requests to appear to be from one user.
29
Here, all requests are mapped to uid 100 (which is supposedly that of
user foo).
48. Explain the following /etc/exports file :
/pub
(ro,insecure,all_squash)
The insecure option in this entry also allows clients with NFS
implementations that do not use a reserved port for NFS.
49. Remote NFS client brahma mounts /jokes on local dir /funny using the
following :
[root@brahma root] # mount ganesh:/jokes
/funny
Now, for some reason, the NFS server on ganesh goes down.
What will happen on brahma?
A: Client will hang indefinitely.
50. Would you be able to interrupt with the keyboard?
A: No
51. What would you do?
A: Use intr
52. How would you use a timeout?
A: Use soft
53. You suddenly get smart overnite. How would you do all this before mounting
a NFS share?
A: mount ganesh:/jokes
/funny -o soft,intr
/funny -o
soft,intr,rsize=8192,wsize=8192
55. How would you automate a NFS Client with all the above considerations in
mind?
A: In /etc/fstab append the following line :
ganesh:/jokes
/funny nfs
soft,intr,rsize=8192,wsize=8192
0 0
30
and make sure the netfs daemon starts at boottime. And of course
portmap
56. What is the default for the read and write buffer ?
A: 4096
57. How many columns does /etc/fstab have?
A: 6
58. What are they?
A:
* Block sp. device [devdrv], or remote FS to be mounted.
One can use LABEL too which points to a hardware partition.
* Mt point for the FS
* Type of FS
* Mount options associated with the FS
* Dump details
* fsck
59. The fifth field of /etc/fstab contains mount options associated with the
FS viz. ext3.
What does defaults mean?
A: rw,suid,dev,exec,auto,nouser,async
60. Explain them
61. How would you remount all the FS's in /etc/fstab w/o rebooting?
A: mount -a
62. By default, can a user mount a cdrom?
A: Yes
63. How would you disallow this?
A: The fifth field of /etc/fstab for cdrom contains noauto,owner.
Change to owner to noowner!
64. What is a synonym for owner?
A: user [nouser]
65. foo mounts a cdrom and logs out? Can bar log in and use his own cdrom?
31
A: No. He will have to unmount foo's cdrom first, for which he has no
permission.
66. So how would you help bar!
A: No problem. Change owner to users!
67. You just said that owner and user and synonymous! Can I use 'owners' above ?
A: No ! Will not work!
68. The fifth field of /etc/fstab for cdrom contains noauto,owner.
Is it a good idea to change the noauto to auto?
A: No. If you forget to have a CD in the drive on boottime, system could
hang!
69. Are there any GUI tools to configure a NFS server?
A: Yes. redhat-config-nfs.
70. I tried it but it is not working? Help me.
A: The file /etc/exports must be missing. It must, at the very least,
be touched!
Q
Q.
A
Q.
A.
Q.
Q.
A.
Q.
A.
knfsd
32
Q.
A.
Q.
Samba Server
Proxy using Squid
33
Firewall (IPTABLES)
What is DMZ
What is Bastion Host
What do you know about Firewalls?
Printing
What is the lp command?
How can you find out the status of your print job?
What command would you enter to cancel a print job
How do I install a new printer?
lpadmin, /etc/printcap
How do I setup a printer? lpadmin, printcap, YMWV
Shell Programming
Write a script to convert all DOS style backslashes to UNIX style slashes in a list of files.
How do I test for the presence of a file in Bourne Shell? test -f
___ In a shell script, how do I print the scripts arguments? $@ $* or $1..$2..
___ How do you make a shell-script executable?chmod ___ script
___ What is the difference between ' ` and "? Protect, Process and Group
___ How do I connect processes, so stdout of one becomes stdin of another? pipes
___ How do I redirect stderr under a Bourne Shell? 2>
___ How do I determine the home directory of a user in a shell script? $HOME, ~, /etc/passwd
___ What is a regular expression? pattern matching language
___ Explain shell job control. fg,bg,&,^Z
___ Whats the differences between a Bourne and C-Shell? startup file, script syntax, etc..
___ How are new processes created? fork/exec
You have 20 servers that need to be updated named server01,server02...server20. Write a bash script to
update all the computers, assuming they all use ssh, with the account bozo.
Ans:
#!/bin/bash
user="bozo";
updatecmd="ls -l"; # put in rpm command here
errorfile="updatelog";
for i in `seq -w 20`
do
ssh "${user}@server$i" $updatecmd || echo "Error on server $i >> $errorfile";
done
The command seq -w 20 pads with the necessary zeros (01,02,03...09).
34
The || executes only the left side on success. However, if the ssh fails, the right side is executed and an
error message to piped to the file.
How do you pass and use a command variable to an awk script?
How can you easily print quotes in an awk script? U sing a sed script print only the
data between "<start>.....</start>" in a file.
How do you create a C like for loop in Bash?
How do you find the length of an array in bash?
You have 20 servers that need to be updated named
Ans:
Yours is woefully unportable. For starters, you can't rely on bash.
Second, you can't rely on GNU-specific tools like seq.
> for i in `seq -w 20`
If you're using bash, why add an extra shell invocation here?
for i in {01..20} should get the same effect in recent versions of bash2.
Write a regular expression (or sed script) to replace all occurrences of the letter f, followed by any
number of characters, followed by the letter a, followed by one or more numeric characters, followed by
the letter n, and replace whats found with the string UNIX.
Write a script to list all the differences between two directories.
Write a program in any language you choose, to reverse a file.
PERL
What does the @ in a variable indicate? its an array
___ What's the current version of Perl? 4 or 5, prefer 5. 5.005 is MRV
___ What is a Hash? a key-data pair type of array variable
What is an inode?
Pointer to block of disk, referenced in a directory
The inode contains information about the file size, file location, ownership, etc. Plus, it contains a pointer
to the first few blocks of data in the file.
35
Any file system broken enough to need the alternate superblock is too broken to use... after all, that is why
you have backups.
Any Unix today that requires one to play with the file system at the superblock level is also too broken to
use in any kind of production environment. It is simply not "production quality," let alone "state of the
art."
All that kind of stuff went away with the development of fsck some 20+ years ago.
While playing with superblocks and file system structure may be fine on a hobby system, a commercial
system cannot afford the downtime, the introduced lack of reliability associated with playing with the file
system on the bit level or the time while someone plays -- that time is better spent on recovery which you
are willing to "bet the company on."
FIND
Using the find command how do you find directory names that "do not contain" a
particular file?
Using the find command, how do you find all files with the immunitable attribute set?
Write a command to find all of the files which have been accessed within the last 30 days.
find / -type f -atime -30 > December.files
This command will find all the files under root, which is /, with file type is file. -atime -30 will give all
the files accessed less than 30 days ago. And the output will put into a file call December.files.
NET
What is the difference between IP Masq and Proxy?
SSH
How would I configure sshd to not ask for a password when connecting with a given user from a
certain host?
The best solution for this is to create a DSA key which can be used to authorize you when you log into the
computer. This is done in two steps, 1) Create the key, 2) Transfer the public part of the key to the server.
Step one:
On the machine which you want to connect from, execute the following command:
ssh-keygen -b 768 -d -f ~/.ssh/id_dsa -P ""
This will create two files under .ssh/ in your homedirectory. They will be called 'id_dsa' and 'id_dsa.pub'
which contains the public (id_dsa.pub) and the private (id_dsa) parts of your key.
Step two:
The public part of your key will now need to be transfered to the server which you want to connect to
without entering a password. This can be done using the 'scp' command provided with most ssh clients:
scp ~/.ssh/id_dsa.pub yourusername@myserver.fo.bar:~/.ssh/authorized_keys2
36
In reality, you should just find a way to transfer your '.ssh/id_dsa.pub' file to the remote machine, rename
it to 'authorized_keys2' and place it under '.ssh/' in your homedirectory. Also, if you want to add more
keys to the same account on a server, you'll just append the data in your new id_dsa.pub file to the
.ssh/authorized_keys2 file on the server.
Note: This solution is based on the ssh v2.0 protocol since it's more secure than v1.x in general. Therefor,
if your ssh client supports v1.x and the server is configured to try that version first, you'll probably have to
tell the client to use v2.0, or you will get a password question anyway. (With OpenSSH, this is done using
the '-2' flag)
1)
2)
3)
4)
37
Difference between LILO and Grub
* LILO has no interactive command interface, whereas GRUB does.
* LILO does not support booting from a network, whereas GRUB does.
* LILO stores information regarding the location of the operating systems it can to load
physically on the MBR. If you change your LILO config file, you have to rewrite the LILO
stage one boot loader to the MBR. Compared with GRUB, this is a much more risky option
since a misconfigured MBR could leave the system unbootable. With GRUB, if the
configuration file is configured incorrectly, it will simply default to the GRUB command-line
interface.
Differences between Ext2,Ext3 and Ext4 file systems in linux.
EXT2 : Ext2 was the standard file system for linux until the introduction of ext3.It was
introduced with the 1.0 kernel in 1993.Ext2 is flexible,can handle file system up to 4 TB,and
supports long filenames up to 1012 characters,it has sparse super blocks feature which
increase file system performance.In case any user processes fill up a file system,ext2
normally reserves about 5% of disk blocks for exclusive use by root so that root can easily
recover from that situation.Now our rescue diskettes use ext2 instead of minix.
EXT3 : Ext3 (Extended 3 file system) provides all the features of ext2,and also features
journaling and backward compatibility with ext2.The backward compatibility enables you to
still run kernals that are only ext2-aware with ext3 partitions.we can also use all of the ext2
file system tuning,repair and recovery tools with ext3 also you can upgrade an ext2 file
system to an ext3 file system without losing any of your data.
Ext3s journaling feature speeds up the amount of time it takes to bring the file system back
to a sane state if its not been cleanly unmounted (that is,in the event of a power outage or
a system crash). Under ext2,when a file system is uncleanly mounted ,the whole file system
must be checked.This takes a long time on large file systems.On an ext3 system ,the
system keeps a record of uncommitted file transactions and applies only those transactions
when the system is brought back up.So a complete system check is not required and the
system will come back up much faster.
A cleanly unmounted ext3 file system can be mounted and used as an ext2 file system,this
capability can come in handy if you need to revert back to an older kernel that is not aware
of ext3.The kernel sees the ext3 filesystem as an ext2 file system.
EXT4 : Ext4 is part of the Linux 2.6.28 kernel,Ext4 is the evolution of the most used Linux
file system, Ext3. In many ways, Ext4 is a deeper improvement over Ext3 than Ext3 was
over Ext2. Ext3 was mostly about adding journaling to Ext2, but Ext4 modifies important
data structures of the file system such as the ones destined to store the file data. The result
is a filesystem with an improved design, better performance, reliability and features.
Features of Ext4 file system :
1. Compatibility
2. Bigger filesystem/file sizes
3. Subdirectory scalability
4. Extents
5. Multiblock allocation
6. Delayed allocation
7. Fast fsck
8. Journal checksumming
9. Online defragmentation
10. Inode-related features
11. Persistent preallocation
12. Barriers on by default
38
Maximum Number of Partitions
Please note that under Linux maximum 63 IDE partitions can be created and 15 SCSI
partitions can be created per disk
39
CLEANING UP THE LINUX BUFFER CACHE
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
Mounting NFS using autofs
Autofs uses the automount daemon to manage your mount points by only mounting them dynamically
when they are accessed.
Autofs consults the master map configuration file /etc/auto.master to determine which mount points are
defined. It then starts an automount process with the appropriate parameters for each mount point. Each
line in the master map defines a mount point and a separate map file that defines the file systems to be
mounted under this mount point. For example, the /etc/auto.misc file might define mount points in the
/misc directory; this relationship would be defined in the /etc/auto.master file.
Each entry in auto.master has three fields. The first field is the mount point. The second field is the
location of the map file, and the third field is optional. The third field can contain information such as a
timeout value.
For example, to mount the directory /jomlu on the remote machine rock.home.net at the
mount point /misc/nfs_jomlu on your machine, add the following line to auto.master:
/misc /etc/auto.misc --timeout 60
Next, add the following line to /etc/auto.misc:
nfs_jomlu -rw,soft,intr,rsize=8192,wsize=8192 rock.home.net:/jomlu
To start the autofs service, at a shell prompt, type the following command:
/sbin/service autofs restart