Linux Interview Questions and Answers

Posted: June 12, 2013 in Interview, Model III

Real Time Based Questions in Redhat Linux

  1. Linux Boot Process
  2. Linux Partition
  3. Linux File System Hierarchy
  4. Important Configuration files Linux
  5. /Proc
  6. Server configuration file s and Packages
  7. Monitoring Commands
  8. Port Numbers In Linux

9.Linux Logs

Linux Boot Process (Startup Sequence)

linux-boot-process

Linux Partition for OS installation

/

/boot

Swap

/home

/var

/etc

Linux Directory Structure/ File System

filesystem-structure

 

Linux Server and Port number

20 – FTP Data (For transferring FTP data)

21 – FTP Control (For starting FTP connection)

22 – SSH(For secure remote administration which uses SSL to encrypt the transmission)

23 – Telnet (For insecure remote administration

25 – SMTP(Mail Transfer Agent for e-mail server such as SEND mail)

53 – DNS(Special service which uses both TCP and UDP)

68 – DHCP

69 – TFTP(Trivial file transfer protocol uses udp protocol for connection less transmission of data)

80 – HTTP/WWW (apache)

88 – Kerberos

110 – POP3(Mail delivery Agent)

123 – NTP(Network time protocol used for time syncing uses UDP protocol)

137 – NetBIOS(nmbd)

139 – SMB-Samba(smbd)

143 – IMAP

995 – POP3s

161 – SNMP(For network monitoring)

389 – LDAP(For centralized administration)

443 – HTTPS(HTTP+SSL for secure web access)

636 – ldaps(both tcp and udp)

873 – rsync

989 – FTPS-data

990 – FTPS

993 – IMAPS

2049 – NFS(nfsd, rpc.nfsd, rpc, portmap) 2401 – CVS server

3306 – MySql

 

1. /proc Directories with names as numbers

Do a ls -l /proc, and you’ll see lot of directories with just numbers. These numbers represents the process ids, the files inside this numbered directory corresponds to the process with that particular PID.

Following are the important files located under each numbered directory (for each process):

  • cmdline – command line of the command.
  • environ – environment variables.
  • fd – Contains the file descriptors which is linked to the appropriate files.
  • limits – Contains the information about the specific limits to the process.
  • mounts – mount related information

Following are the important links under each numbered directory (for each process):

  • cwd – Link to current working directory of the process.
  • exe – Link to executable of the process.
  • root – Link to the root directory of the process.

2. /proc Files about the system information

Following are some files which are available under /proc, that contains system information such as cpuinfo, meminfo, loadavg.

/proc/cpuinfo – information about CPU,

  • /proc/meminfo – information about memory,
  • /proc/loadvg – load average,
  • /proc/partitions – partition related information,
  • /proc/version – linux version

Some Linux commands read the information from this /proc files and displays it. For example, free command, reads the memory information from /proc/meminfo file, formats it, and displays it.

To learn more about the individual /proc files, do “man 5 FILENAME”.

  • /proc/cmdline – Kernel command line
  • /proc/cpuinfo – Information about the processors.
  • /proc/devices – List of device drivers configured into the currently running kernel.
  • /proc/dma – Shows which DMA channels are being used at the moment.
  • /proc/fb – Frame Buffer devices.
  • /proc/filesystems – File systems supported by the kernel.
  • /proc/interrupts – Number of interrupts per IRQ on architecture.
  • /proc/iomem – This file shows the current map of the system’s memory for its various devices
  • /proc/ioports – provides a list of currently registered port regions used for input or output communication with a device
  • /proc/loadavg – Contains load average of the system
    The first three columns measure CPU utilization of the last 1, 5, and 10 minute periods.
    The fourth column shows the number of currently running processes and the total number of processes.
    The last column displays the last process ID used.
  • /proc/locks – Displays the files currently locked by the kernel
    Sample line:
    1: POSIX ADVISORY WRITE 14375 08:03:114727 0 EOF
  • /proc/meminfo – Current utilization of primary memory on the system
  • /proc/misc – This file lists miscellaneous drivers registered on the miscellaneous major device, which is number 10
  • /proc/modules – Displays a list of all modules that have been loaded by the system
  • /proc/mounts – This file provides a quick list of all mounts in use by the system
  • /proc/partitions – Very detailed information on the various partitions currently available to the system
  • /proc/pci – Full listing of every PCI device on your system
  • /proc/stat – Keeps track of a variety of different statistics about the system since it was last restarted
  • /proc/swap – Measures swap space and its utilization
  • /proc/uptime – Contains information about uptime of the system
  • /proc/version – Version of the Linux kernel, gcc, name of the Linux flavor installed.

Linux Log Files

 

  1. /var/log/messages – Contains global system messages, including the messages that are logged during system startup. There are several things that are logged in /var/log/messages including mail, cron, daemon, kern, auth, etc.
  1. /var/log/dmesg – Contains kernel ring buffer information. When the system boots up, it prints number of messages on the screen that displays information about the hardware devices that the kernel detects during boot process. These messages are available in kernel ring buffer and whenever the new message comes the old message gets overwritten. You can also view the content of this file using the dmesg command.
  1. /var/log/auth.log – Contains system authorization information, including user logins and authentication machinsm that were used.
  1. /var/log/boot.log – Contains information that are logged when the system boots
  1. /var/log/daemon.log – Contains information logged by the various background daemons that runs on the system
  1. /var/log/dpkg.log – Contains information that are logged when a package is installed or removed using dpkg command
  2. /var/log/kern.log – Contains information logged by the kernel. Helpful for you to troubleshoot a custom-built kernel.
  1. /var/log/lastlog – Displays the recent login information for all the users. This is not an ascii file. You should use lastlog command to view the content of this file.
  1. /var/log/maillog /var/log/mail.log – Contains the log information from the mail server that is running on the system. For example, sendmail logs information about all the sent items to this file
  1. /var/log/user.log – Contains information about all user level logs
  1. /var/log/Xorg.x.log – Log messages from the X
  1. /var/log/alternatives.log – Information by the update-alternatives are logged into this log file. On Ubuntu, update-alternatives maintains symbolic links determining default commands.
  1. /var/log/btmp – This file contains information about failed login attemps. Use the last command to view the btmp file. For example, “last -f /var/log/btmp | more”
  1. /var/log/cups – All printer and printing related log messages

 

  1. /var/log/anaconda.log – When you install Linux, all installation related messages are stored in this log file

 

  1. /var/log/yum.log – Contains information that are logged when a package is installed using yum
  1. /var/log/cron – Whenever cron daemon (or anacron) starts a cron job, it logs the information about the cron job in this file
  1. /var/log/secure – Contains information related to authentication and authorization privileges. For example, sshd logs all the messages here, including unsuccessful login

/var/log/wtmp or /var/log/utmp – Contains login records. Using wtmp you can find out who is logged into the system. who command uses this file to display the information.

  1. /var/log/faillog – Contains user failed login attemps. Use faillog command to display the content of this file.

Apart from the above log files, /var/log directory may also contain the following sub-directories depending on the application that is running on your system.

  • /var/log/httpd/ (or) /var/log/apache2 – Contains the apache web server access_log and error_log
  • /var/log/lighttpd/ – Contains light HTTPD access_log and error_log
  • /var/log/conman/ – Log files for ConMan client. conman connects remote consoles that are managed by conmand daemon.
  • /var/log/mail/ – This subdirectory contains additional logs from your mail server. For example, sendmail stores the collected mail statistics in /var/log/mail/statistics file
  • /var/log/prelink/ – prelink program modifies shared libraries and linked binaries to speed up the startup process. /var/log/prelink/prelink.log contains the information about the .so file that was modified by the prelink.
  • /var/log/audit/ – Contains logs information stored by the Linux audit daemon (auditd).
  • /var/log/setroubleshoot/ – SELinux uses setroubleshootd (SE Trouble Shoot Daemon) to notify about issues in the security context of files, and logs those information in this log file.
  • /var/log/samba/ – Contains log information stored by samba, which is used to connect Windows to Linux.
  • /var/log/sa/ – Contains the daily sar files that are collected by the sysstat package.
  • /var/log/sssd/ – Use by system security services daemon that manage access to remote directories and authentication mechanisms.

Trouble shooting In Linux

Getting ram information

cat /proc/meminfo

cat /proc/meminfo | head -n 1

Another fun thing to do with ram is actually open it up and take a peek. This next command will show you all the string (plain text) values in ram.

sudo dd if=/dev/mem | cat | strings

Getting cpu info

Sometimes in troubleshooting we want to know what processor we are dealing with along with how much cpu is currently being used by our OS and programs. We can do this with these two commands.

cat /proc/cpuinfo

top

Check the temperature of your CPU

Keeping a computer within a safe temperature is the key to maintaining a stable system.e

List PCI and USB devices

To list all the PCI devices in your system issues the following command:

lspci

For USB use:

lsusb

Check out how much hard drive space is left

df -h

See what hard drives are currently detected

It is often times helpful to know what hard drives are connected to a system and what name was given them in the Linux directory. This info allows us to mount the hard drive and manipulate it.

sudo fdisk -l

Installed Programs

Packages

Ever want to find all the packages that are installed on your system? You can find all the packages and also find out why they are on your system. You can even determine what packages depend on them if any.

Find all installed packages

dpkg –get-selections | less

Find out why a packages is installed and what depends on it

aptitude why packagename

Find out where the package stores all of its files

dpkg -L packagename

Kill a process

ps -A | grep ProgramName

kill 7207

Miscellaneous

Go to a terminal

Ctrl + Alt + f3

return with, Ctrl + Alt + f7

Show all network connections

There are many great network scanners and assessment tools available for Linux but netstat is a very easy to use often a first step in troubleshooting network issues. We will leave the rest of the network tools for a later article as there is so much to cover.

netstat

List all files that are currently open on the system

This command will allow you to see all the files that are currently open on your system. Limiting the directory or coupling this command with grep is often useful for finding files that are still open restricting the ability to unmount a device. Lsof will also ouput the process id or PID. You can then kill the process using the kill command above.

lsof

Keep an eye on something for awhile

The watch command will repeat a command at a set interval (default 2 seconds) and output the response. This is useful for watching directories that change, watching hard drives fill up when a lot of data is being transfered, or using it with lsusb to watch for USB devices being plugged in.

watch ls

watch df -h

Find where a binary is stored and its libraries

Often times when running a cron command you want to include the absolute path to the command. Sometimes I run scheduled PHP tasks. This can be acomplished by using the ‘whereis‘ command.

whereis php5

Logs

See if you have kernel boot issues

dmesg | less

For more logs just cd into the /var/log directory and start using, catlesstailgrepfind or any other tool to view and search.

Linux Network troubleshooting step by step

Here we go into the topic.

1- First check that your interface (Network adapter ) is enabled or not using:         ifconfig

2- To make sure there is no internal problem.

     ping to the loop back address  ping 127.0.0.1

   if there is no response  service network restart if same repeats check network settings again.

3- check cable problem from ethtool eth0

if everything is fine then last line will show

 
                Link detected: yes
 
    
     if link is not detected plug it or change the cable according to need and problem
4-check the gateway settings in 
 
/etc/network    and
 /etc/sysconfig/network-scripts/ifcfg-eth0

And check DNS settings in

 /etc/resolv.conf 
 
system-config-network 

netstat

route 

service iptables stop

( only disable the firewall for testing and dont forget to turn it on)

check boot messages if eth card is detected at boot time or not

cat /var/log/dmesg | grep -i eth0

or

dmesg | grep -i eth0

to check table of network interfaces

netstat -i

for more advanced troubleshooting

lspci | less

or
lspci | grep ethernet

to check all PCI buses and devices connected to them

These are enough to troubleshoot if still problem persist try installing drivers , check kernel related problems , check is there any need to recompile the kernel etc

Comments
  1. I do accept as true with all of the ideas you have offered for your post. They are very convincing and can certainly work. Still, the posts are too brief for novices. Could you please prolong them a little from next time? Thank you for the post.

  2. As a Newbie, I am permanently searching online for articles that can be of assistance to me. Thank you

  3. Home Page says:

    I will immediately snatch your rss as I can not find your e-mail subscription hyperlink or newsletter service. Do you’ve any? Please permit me recognise in order that I may just subscribe. Thanks.

  4. website says:

    I get pleasure from, result in I found just what I used to be taking a look for. You have ended my four day lengthy hunt! God Bless you man. Have a great day. Bye

  5. Homepage says:

    Thank you for all your work on this site. Gloria enjoys carrying out investigation and it’s really easy to understand why. All of us hear all about the lively mode you convey vital things through this website and cause response from others about this point then our own child is without a doubt learning a lot. Enjoy the remaining portion of the new year. You’re the one carrying out a powerful job.

  6. Home Page says:

    Great beat ! I wish to apprentice while you amend your site, how can i subscribe for a blog website? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

  7. Web Site says:

    Undeniably believe that which you said. Your favorite justification appeared to be on the net the easiest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they just don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks

  8. Nice post. I was checking constantly this blog and I am impressed! Very useful info specifically the last part 🙂 I care for such info a lot. I was looking for this particular info for a long time. Thank you and good luck.

  9. Great write-up, I¡¦m regular visitor of one¡¦s blog, maintain up the excellent operate, and It is going to be a regular visitor for a long time.

  10. Website says:

    I’m so happy to read this. This is the kind of manual that needs to be given and not the accidental misinformation that is at the other blogs. Appreciate your sharing this greatest doc.

  11. certainly like your web site however you need to test the spelling on quite a few of your posts. Many of them are rife with spelling issues and I in finding it very troublesome to inform the truth then again I¡¦ll certainly come again again.

  12. I¡¦ve been exploring for a little for any high-quality articles or weblog posts on this kind of area . Exploring in Yahoo I eventually stumbled upon this site. Studying this information So i¡¦m happy to exhibit that I’ve a very excellent uncanny feeling I discovered just what I needed. I most indisputably will make certain to don¡¦t put out of your mind this web site and give it a glance regularly.

  13. Read More says:

    you are actually a good webmaster. The website loading velocity is amazing. It seems that you are doing any distinctive trick. In addition, The contents are masterpiece. you’ve done a excellent process on this subject!

  14. Website says:

    Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently quickly.

  15. learn more says:

    I think this is one of the most important info for me. And i’m glad reading your article. But should remark on few general things, The website style is great, the articles is really excellent : D. Good job, cheers

  16. website says:

    I¡¦ve recently started a blog, the info you provide on this site has helped me tremendously. Thanks for all of your time

  17. Going Here says:

    Good web site! I really love how it is simple on my eyes and the data are well written. I’m wondering how I could be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a nice day!

  18. I¡¦ve been exploring for a little for any high-quality articles or weblog posts on this kind of area . Exploring in Yahoo I eventually stumbled upon this site. Studying this information So i¡¦m happy to exhibit that I’ve a very excellent uncanny feeling I discovered just what I needed. I most indisputably will make certain to don¡¦t put out of your mind this web site and give it a glance regularly.

  19. Click Here says:

    I have been reading out many of your stories and i can state clever stuff. I will definitely bookmark your site.

  20. website says:

    Thank you for any other wonderful post. The place else may anybody get that type of information in such an ideal way of writing? I’ve a presentation next week, and I am at the look for such info.

  21. read more says:

    Thanks a bunch for sharing this with all folks you really understand what you’re speaking about! Bookmarked. Please also talk over with my web site =). We may have a link change arrangement between us!

  22. Read This says:

    What i do not understood is actually how you are not really a lot more well-favored than you may be right now. You are so intelligent. You recognize therefore considerably on the subject of this matter, produced me in my opinion believe it from so many various angles. Its like men and women are not involved until it is one thing to do with Girl gaga! Your own stuffs excellent. At all times maintain it up!

  23. Web Site says:

    Wonderful paintings! This is the kind of info that are meant to be shared around the web. Shame on the search engines for no longer positioning this submit upper! Come on over and discuss with my website . Thank you =)

  24. Read More says:

    I have been absent for a while, but now I remember why I used to love this web site. Thank you, I will try and check back more often. How frequently you update your web site?

  25. whoah this weblog is excellent i like reading your posts. Keep up the great paintings! You know, a lot of people are looking around for this information, you can aid them greatly.

  26. Wow, fantastic blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is magnificent, as well as the content!

  27. You made some good points there. I did a search on the issue and found most people will consent with your site.

  28. Homepage says:

    You can definitely see your expertise within the work you write. The sector hopes for more passionate writers like you who are not afraid to mention how they believe. Always go after your heart.

  29. I’m still learning from you, but I’m trying to reach my goals. I absolutely enjoy reading all that is posted on your blog.Keep the stories coming. I liked it!

  30. I¡¦m not positive where you are getting your information, however good topic. I needs to spend some time learning much more or working out more. Thanks for excellent info I used to be searching for this information for my mission.

  31. Web Site says:

    Very good written information. It will be valuable to anybody who employess it, as well as yours truly :). Keep up the good work – for sure i will check out more posts.

  32. view source says:

    Whats Going down i’m new to this, I stumbled upon this I’ve discovered It positively helpful and it has helped me out loads. I am hoping to give a contribution

  33. Hello my friend! I want to say that this article is amazing, nice written and include almost all important infos. I would like to look more posts like this .

  34. view source says:

    You really make it seem really easy with your presentation but I to find this topic to be actually one thing which I think I might by no means understand. It seems too complicated and extremely wide for me. I’m looking ahead for your next put up, I will try to get the hang of it!

  35. visit says:

    It is in point of fact a nice and useful piece of info. I am happy that you just shared this helpful information with us. Please keep us informed like this. Thank you for sharing.

  36. click here says:

    I have been reading out many of your stories and i can state clever stuff. I will definitely bookmark your site.

  37. visit here says:

    Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but instead of that, this is wonderful blog. A great read. I’ll definitely be back.

  38. Hi, Neat post. There is an issue with your website in web explorer, would test this¡K IE still is the market chief and a huge element of folks will pass over your great writing due to this problem.

  39. Wow, marvelous weblog layout! How lengthy have you been blogging for? you made blogging glance easy. The overall look of your website is fantastic, as well as the content!

  40. I am just writing to make you be aware of what a superb encounter my friend’s princess found reading your site. She picked up such a lot of details, most notably what it’s like to possess an incredible coaching nature to make other people just grasp chosen specialized matters. You really did more than my expected results. Thanks for delivering those good, safe, edifying and even easy guidance on the topic to Lizeth.

  41. Hey, you used to write fantastic, but the last several posts have been kinda boring¡K I miss your tremendous writings. Past several posts are just a little out of track! come on!

  42. more info says:

    I will immediately snatch your rss as I can not find your e-mail subscription hyperlink or newsletter service. Do you’ve any? Please permit me recognise in order that I may just subscribe. Thanks.

  43. I keep listening to the news update speak about getting free online grant applications so I have been looking around for the best site to get one. Could you advise me please, where could i acquire some?

  44. visit here says:

    Definitely, what a splendid blog and illuminating posts, I surely will bookmark your site.All the Best!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.