Wednesday, 9 December 2015

Increase Swap Size for Linux server

1. Create Swap file

 > touch /swapfile

2. To create 2GB of swap file,

 > dd if=/dev/zero of=/swapfile bs=1024 count=2048000

  For 4GB,

 > dd if=/dev/zero of=/swapfile bs=1M count=4096

3. mkswap /swapfile

Now the swap file is created.

4. To activate /swapfile file,

 > swapon /swapfile

5. Add entry on /etc/fstab file to activate after serevr reboot,

 > vi /etc/fstab
 
   /swapfile swap    swap    defaults        0 0

Now check the swap space,

 > free -m

Tuesday, 15 September 2015

L1 / L2 Quest & answer

1. What is ldd?
List dynamic dependencies – print shared library dependencies
Eg: – # vim new.c
# gcc new.c –o new
# ldd new
2. What is the command to uninstall processes in Linux?
rpm –e sendmail
-e – remove
3. What is the command for finding the highest memory occupied file in Linux?
du –ah / | sort –n –r | head –n 1
du – estimate file space usage
-a – write counts for all files, not just directories
-h – print sizes in human readable format (eg. 1K 234M 2G)
sort – sort lines of text files
-n – compare according to string numerical value
-r – reverse the result of comparisons
head – output the first part of files
-n – number of lines
4. What are the Linux boot files?
1./boot/grub/grub.conf: contains boot disk parameters
2./etc/fstab: contains File systems which need to mount at boot time
3./etc/initab: Contains default run level
4./etc/init.d/rc.d/rcN.d: This is a dir it contains
5. Difference between swap partition and swap file?
Swap partition is maintained as a separate partition. Same swap partition can be used for two OS within single machine.
Suppose if the system crashes, there is a chance to recover or it may not  corrupt the partition.
Less fragmented.
Where as swap file takes very less space. We can increase the space very easily, compared to swap partition. Swap file system fragmented.
If  the system crashes then there is a huge chance to lost the swap file system.
6. A file which is not deleted by normal user and also root (using rm), for that type of file how we delete it?
Using chattr command, we need to change the attributes and then we remove using rm command.
Eg: – chattr -iIu example
rm -rf example
7. Difference between nfs soft and hard mounting points?
Hard mount option: – If the client fails to access the server, then the connection hangs and once the system is up then it will again access the server.
Soft: – If the client failed to connect the server, it immediately gives the error report and closes the connection.
8. If we transfer 100 files by ftp to remote server, how to know the files are successfully transfer or some file are not transferred?
ftp>mput 1 2 3 …. 100
ftp> ls –l
9. I know ssh, telnet, dns,apache all are worked on TCP/UDP but i want to know any one service which are working on UDP only?
snmptrap 162/udp
snmptrap – simple network management protocol trap
snmptrapd is an SNMP application that receives and logs
10. I want to built a fire wall using iptables. My condition is ” inbound to 192.168.0.2 with a port of 80 from 172.168.0.1 should accept”
iptables –A INPUT –p tcp –dport 80 –s 172.168.0.1 –d 192.168.0.2 –j ACCEPT
11. I want to see how many interfaces (Ethernet cards) are working using single command?
ifconfig
12. What is the status code 403,404 represented in apache server?
403 represent forbidden error, means if a file misses some selinux security context.
404 represent that there is a cgi script missing or web pages missing.
13. How to monitor ports in a linux machine, with single command?
nmap localhost
14. In my linux machine, i lost /etc/passwd file and /etc/shadow file, then how can i recover it?
Normally in linux we must have backup by default for /etc/passwd and /etc/shadow files
/etc/passwd —> /etc/passwd-
/etc/shadow —> /etc/shadow-
from there we can copy or restore. If both are not available. Then follow below steps:
1. reboot
2. Single user mode [ single init=/bin/bash ]
3. pwconv
4. check /etc/passwd and /etc/shadow files are there
5. sync
6. init 3 or reboot with init 3
15. what r the different command to check ram,process and hdd of linux machine
To check ram in your system:
#free
To check process
#ps
#top
To check hdd
#fdisk
#sfdisk -l
16.If i run ls command it will show me the junk output what is problem and how to resolve it
Set your terminal setting by stty and before that, export ls command to PATH variable
17. WHAT IS THE MEANING OF AIX
AIX (Advanced Interactive eXecutive) is an open operating system from IBM which is based on a version of UNIX. AIX/ESA was designed for IBM’s System/390 or large server hardware platform. AIX/6000 is an operating system that runs on IBM’s workstation platform, the RISC System/6000.
18. Why ls -F dev/log file output indicate as = sign at end of the file name?
Standard output
19. What is nis server?
NIS is a service that provides any user on a network with the same working environment irrespective of the system on that network, which has been used for login purpose.
For example if NIS server is set up in a single system and configured to hold user accounts and their passwords and access information. Then any user on that network can login to his/her account from any system (with nis client running) on that configured network. This gives a look and feel that the user is logged into his/her own system. But actually it’s the account on the NIS server that is mounted on the local sytem user login.
20. What command can you use to review boot messages?
Dmesg
21. Who invented unix?
Unix was created in 1969 by Ken Thompson and Dennis Ritchie at Bell Laboratories.
22. Write a cron entry for the following scenario:- At 10:30 AM for every Sunday of every 1st month of a quarter.
30 10 * 1-12/3 7
23. What is the difference between RHEL4 & RHEL5?
RHEL4: No yum server, Selinux, secure, no cd key
RHEL5: yum server, advanced selinux, more secure, virtualization
24. What is the command to make a process to run in the foreground from background?
When the process is running, press “control+Z”. Now at the command prompt, type “bg”
25. What are the init levels in Linux?

7 level

L2 Questions and answered

1. What is the difference between service and process?
A process is any piece of software that is running on a computer. For example, your anti-virus software runs in the background as a process, which was automatically started when the computer booted. Some processes start when your computer boots, others are started manually when needed.
Some processes are services that publish methods to access them, so other programs can call them as needed. Printing services would be an example of a service type of process, where your email program can just call the print services process to say it wants to print, and the service does the actual work.
2. How to view crond status? If it’s show service is not found.
Service crond restart
3. My clients are getting services from servers but how to know which client is using which service. is there any files to keep information about these? Clients used ftp, nis, samba, apache, squid, nfs and mail services how to know how many users got service from server side with date, time and client system ip?
Mail server – /var/log/mail/maillog [RedHat,centos]
ssh – /var/log/secure
Apache – /var/log/http/access.log
nfs – /var/lib/nfs/rmtab
4. How to FTP user access other directory except his own home directory?
vim /etc/vsftpd/vsftpd.conf
Chroot_list_enable=yes
5. What are the Linux-based security tools?
Selinux
Firewall
iptables
Tcp-wrappers
6. What are the basic elements of firewall?
A firewall should be able to filter packets (drop/pass them) based on certain rules specified by the user. The rules may be used to identify an incoming packet to the computer or outgoing packet from the computer, it can be based on target port number/ip add , traffic from a particular Network card etc…
The firewall rules can be in a tabular form (saved on the disk) from where the firewall software can read them and implement it. iptables firewall on Linux is a great example
7. What is a command to display top 10 users who are using huge space?
du -sh /home/* | sort -r | head -10
8. How do find all failed login attempts via ssh?
tail -f /var/log/secure | grep Failed
9. How do you configure Linux system as a router?
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
system-config-network
eth0 192.168.1.120 eth0:1 172.24.0.1
255.255.255.0 255.255.0.0
172.24.0.1 192.168.1.120
10. What is the UID and GID of root user? Can a normal user can change the ownership of a file? What is the command to change ownership of a file?
The root UID/GID is 0 (zero). Which is why he can able to intervene in all normal users files even though he don’t had permission. A normal user will don’t have the permission to change ownership of file. The command to change ownership is < chown user.user file >
11. What is the diff b/w ext2 and ext3?
Ext3 is a tiny bit slower than ext2 is, but it holds tremendous advantages. There is really only one difference between ext2 and ext3, and that is that ext3 uses a journal to prevent filesystem corruption in the case of an unclean shutdown (ie. before the filesystem is synced to disk). That makes ext3 a bit slower than ext2 since all metadata changes are written to the journal, and then flushed to disk, but on the other hand you don’t risk having the entire filesystem destroyed at power failure or if an unwitted person turns the computer off uncleanly. You don’t have to check the filesystem after an unclean shutdown either. Ext3 has three levels of journalling. Metadata (ie. internal filesystem structures) are always journalled, so that the filesystem itself is never corrupted. How ordinary data is written to the file system is controllable, though. The default option is the “ordered” mode, which causes file contents to be written to the filesystem before metadata is even committed to the journal. The highest reliable mode is called the “journal” mode, which causes file data to be committed to the journal before it is flushed to its final place, like the metadata. The least reliable mode, but rumoured to be the fastest, is called the “writeback” mode, which makes no promises at all regarding the consistency of file data. Only metadata is output reliably in writeback mode. So as for anything else, it’s mainly a matter of priority. If you don’t want ultimate speed, go with ext3. If you need the highest speed that is theoratically aquirable though, then go with ext2. For that to be effective you’ll probably need a really advanced hard drive controller, though.
12. As the system administrator you need to review Bob’s cronjobs. What command would you use?
crontab –lu Bob
13. What command is used to remove the password assigned to a group?
gpasswd –r groupname
14. What are the different RAID levels?
 RAID level 0
 RAID level RAID level 1
 RAID level 2
 RAID level 3
 RAID level 4
 RAID level 5
 RAID level 6
 RAID level 10
 RAID level 50
15. How do you create a swapfile?
dd if=/dev/zero of=/swapfile bs=1024 count=200M
mkswap /swapfile
swapon /swapfile
16. What does nslookup do?
Nslookup is a program used to find information about internet Domain Name server.
The two modes of nslookup are: Interactive and non-interactive.
Using ‘interactive mode’ user can query the name servers for the information pertaining to hosts and domains.
Using ‘non-interactive mode’ the user can just print the name and requested information of a host.
17. What is the difference between UDP and TCP?
TCP is a Transmission Control Protocol.
UDP is a User Datagram Protocol.
There are four major differences between UDP and TCP:
1. TCP can establish a Connection and UDP cannot.
2. TCP provides a stream of unlimited length, UDP sends Small packets.
3.TCP gurantees that as long as you have a connection data sent will arrive at the destination, UDP provides not guarantee delivery.
4.UDP is faster for sending small amounts of data since no connection setup is required, the data can be sent in less time then it takes for TCP to establish a connection.
18. What command do you run to check file system consistency?
Need to run fsck [file system consistency check] command to check file system consistency and repair a Linux / UNIX file system.
fsck
19. What is the command to remove Lvm ,Pv and vg
1st remove the entry on /etc/fstab file & save – quit.
2nd remove LVM – lvremove lvname
3rd remove VG – vgremove vgname
4th remove PV – pvremove pvname
20. How to create SAMBA server in fedora 9 Linux?
yum install samba -y
yum install samba-swat –y
vi /etc/samba/smb.conf
comment = windows sharing
path = path/your/share/directory
valid users = surendra
writable = yes
browseable = yes
then type testparm for code testing.
smbpasswd -a username
smbpasswd -e username
service smb restart
chkconfig smb on
21. How to schedule cron backup to run on 4th Saturday of month?
* * * * 6 weekdaynum 4 && sh /backup/test.sh
22. What is an inode?
ext2 and ext3 file systems keep a list of the files they contain in a table called an inode table. The inode is referenced by its number. This is unique within a file system.
The inode contains the metadata about files. Among the data stored in the inode is
File type
File permissions
Link count
User ID number of the file owner and the group ID number of the associated group
Last modification time
Location of the data on the hard disk
Other metadata about the file
ls -li – view inode number only
stat /etc/passwd – view inode details
23. How to see unallocated hard disk space on linux
df -h
24. How do u find remote machine operating system and version?
nmap -A –v 192.168.1.100
25. How do you port scanning with netstat command?
netstat –an
26. Linux system monitoring Tools?
top – Process Activity Command
vmstat – System Activity, Hardware and System Information
w – Find out Who Is Logged on And What They Are Doing
Uptime – Tell How Long the System Has Been Running
ps – Displays the Processes
free – Memory Usage
iostat – Average CPU Load, Disk Activity
sar – Collect and Report System Activity
mpstat – Multiprocessor Usage
pmap – Process Memory Usage
27. Linux Network monitoring Tools?
netstat and ss – Network Statistics
iptraf – Real-time Network Statistics
tcpdump – Detailed Network Traffic Analysis
strace – System Calls
/Proc file system – Various Kernel Statistics
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts
Nagios – Server And Network Monitoring
Cacti – Web-based Monitoring Tool
Gnome System Monitor – Real-time Systems Reporting and Graphing
28. What is mean by system calls?
A system call is the mechanism used by an application program to request service from the operating system.
On Unix-based and POSIX-based systems, popular system calls are open, read, write, close, wait, exec, fork, exit, and kill. Many of today’s operating systems have hundreds of system calls. For example, Linux has 319 different system calls. FreeBSD has about the same (almost 330). Tools such as strace and truss report the system calls made by a running process.
29. Important port no:
NFS – 2049
FTP – 21
SAMBA – 445
SSH – 22
DNS – 53
POP3 – 110
IMAP – 143
HTTPS – 443
HTTP – 80
30. How do u extract files from iso cd images in linux?

mount –o loop disk1.iso /mnt/iso

Sunday, 22 March 2015

DNS : Its working

 
In Network, the hosts primarily communicate between each other through IP addresses.
 
 For example, google search from your local PC, your computer is actually communicating with the IP address of one of the web servers of google.com. However, even if the computer is efficient with numbers, humans on the other hand work better with names. For this reason, the TCP/IP protocol includes the Domain Name System (DNS)  to link between IPs and computer names i.e. hostnames.
 
 The DNS is a distributed database of computers that is responsible for resolving hostnames against IP addresses and vice-versa.
Any DNS query involves two parts.
  1. The Resolver: The resolver forms up or initiates the query. The resolver itself does not run as a program. /etc/resolv.conf is an example of a resolver.
  2. Name Server: The Name Server is the service running in the server that responds to the DNS query generated by the resolver i.e. answers to the question of the resolver.
     =========
    1. nslookup
        >> nslookup followed by the domain name will display the “A Record” ( IP Address ) of the domain.

    Eg: nslookup redhat.com
    2. Query the MX Record using -query=mx
    nslookup -query=mx redhat.com

    nslookup -type=ns redhat.com
    nslookup -type=soa redhat.com
    nslookup -type=any google.com
    nslookup 209.132.183.181
    nslookup redhat.com ns1.redhat.com
    nslookup -port 56 redhat.com
    nslookup -timeout=10 redhat.com


    dig Hostname
    dig DomaiNameHere
    dig @DNS-server-name Hostname
    dig @DNS-server-name IPAddress
    dig @DNS-server-name Hostname|IPAddress type

    For more info
    Please visit

    http://www.cyberciti.biz/faq/linux-unix-dig-command-examples-usage-syntax/