Pages

Wednesday, July 26, 2017

What is Run Queue

Every processor in a CPU has queue called runqueue associated with it. Each runqueue has 2 priority arrays, the active and the expired. Active array stores the processes that still have some time slice. Once this time finished, they go to the expired array. Each array has 140 entries (queues), one for each privilege level (So 140 + 140 ).

Run queue has priority values for each process, which will be used by the scheduler to determine which process to run next. To ensure each program has a fair share of resources, each one is run for some time period (quantum) before it is paused and placed back into the run queue. When a program is stopped to let another run, the program with the highest priority in the run queue is then allowed to execute. Active processes are placed in an array called a run queue

Processes are also removed from the run queue when they ask to sleep, are waiting on a resource to become available, or have been terminated.

In the Linux operating system (prior to kernel 2.6.23), each CPU in the system is given a run queue, which maintains both an active and expired array of processes.The scheduler selects the next process from the active array with highest priority. When a process' quantum expires, it is placed into the expired array with some priority.

How to Check 

a) sar -q command is used to check the run queue.

runq-sz : Run queue length (number of tasks waiting for run time)
plist-sz : Number of tasks in the task list.

b) vmstat can also be used to determine the number of processes that are queued to run or waiting to run. These appear in the 'r' column.

What is Ready Queue and Run Queue

In operating system , Process that are ready to execute when given the opportunity to execute are sent to ready queue.

Whenever there is a space in run queue, for running the process, Process from ready state in ready queue is sent to run queue.

Tuesday, July 25, 2017

What is Authoritave, Non Authoritative, Recurvise DNS Server

What is a Authoritative Name Server?

Basically authoritative DNS means the place where the Domain is actualy hosted. For Eg. if Www.example1.com is hosted nameserver1 then the response from nameserver1 is known as authoritative

It's distinction between a nameserver that's an official nameserver for the domain you're querying, and a nameserver that isn't. Nameservers that aren't authoritative are getting their answers second (or third or fourth...) hand - just relaying the information along from somewhere else.

An authoritative answer comes from a nameserver that is considered authoritative for the domain which it's returning a record for (one of the nameservers in the list for the domain you did a lookup on), and a non-authoritative answer comes from anywhere else (a nameserver not in the list for the domain you did a lookup on).containing complete and accurate information, and therefore respected:

So, for example, If we do an nslookup of maps.google.com we would get a response from one of my configured nameservers. (Either from my ISP, or my domain.) It would come back as non-authoritative because neither my ISP's nameservers, nor my own are in the list of nameservers for google.com. They aren't Google's nameservers, so they're not the authoritative source that creates the NS records.

The list of authoritative nameservers for Google is below (from whois.internic.net).

Domain Name: GOOGLE.COM
Registrar: MARKMONITOR INC.
Whois Server: whois.markmonitor.com
Name Server: NS1.GOOGLE.COM
Name Server: NS2.GOOGLE.COM
Name Server: NS3.GOOGLE.COM
Name Server: NS4.GOOGLE.COM

Non-authoritative nameservers 

Non-authoritative nameservers get their NS records from the authoritative servers somewhere down the line.

The answer you've received is essentially a cached or forwarded response from your local DNS server. Basically, a non-authoritative name server is one that does not contain the records for the zone being queried; your local DNS is likely not going to have Google's name records, for example.

You can get the name servers that are authoritative for a given domain by running host -t ns example.com to retrieve the NS record for example.com.

In the case of Google, we see:

$ host -t ns google.com
google.com name server ns4.google.com.
google.com name server ns1.google.com.
google.com name server ns2.google.com.
google.com name server ns3.google.com.

If you subsequently run your nslookup command against one of those servers, you will get the authoritative answer:

$ nslookup www.google.com ns1.google.com
Server:         ns1.google.com
Address:        216.239.32.10#53

www.google.com  canonical name = www.l.google.com.
Name:   www.l.google.com
Address: 173.194.43.49
Name:   www.l.google.com
Address: 173.194.43.50
Name:   www.l.google.com
Address: 173.194.43.48
Name:   www.l.google.com
Address: 173.194.43.52
Name:   www.l.google.com
Address: 173.194.43.51
If you're using nslookup, to get the NS record type, you can run something like this in interactive mode:

$ nslookup
> set querytype=ns
> google.com
Server:         127.0.0.1
Address:        127.0.0.1#53

Non-authoritative answer:
google.com      nameserver = ns3.google.com.
google.com      nameserver = ns4.google.com.
google.com      nameserver = ns1.google.com.
google.com      nameserver = ns2.google.com.

Authoritative answers can be found from:
ns1.google.com  internet address = 216.239.32.10
So, setting querytype=ns does what the above host command did.

What is a Recursive DNS Server?

Basically the DNS server which is managed by ISP.

You might have been able to guess what a recursive DNS server does by its name—it recurses, which means that it refers back to itself. Recursive DNS nameservers are responsible for providing the proper IP address of the intended domain name to the requesting host. Recursive nameservers are like the phone operator looking up a phone number from multiple phone books on behalf of the requesting party (the users’ computer on behalf of an application), some phone books will list just last names, then other phone books exist per last name, and list first names.

For example, when making a request to a website from your browser, the host (computer) will then make a request to recursive DNS server to find the IP address associated with the website; this is assuming your operating system and Web browser do not already have a response cached. From there, the recursive server will check to see if it has a cached DNS record from the authoritative nameserver, and still has a valid time-to-live (TTL). If the recursive server does not have the DNS record cached, it begins the recursive process of going through the authoritative DNS hierarchy, which I will explain further down in this post.

Basically, it's what the name says it is. An authoritative answer comes from a nameserver that is considered authoritative for the domain which it's returning a record for (one of the nameservers in the list for the domain you did a lookup on), and a non-authoritative answer comes from anywhere else (a nameserver not in the list for the domain you did a lookup on).

What it GTLD


Generic top-level domains (gTLDs) are one of the categories of top-level domains (TLDs) maintained by the Internet Assigned Numbers Authority (IANA) for use in the Domain Name System of the Internet. A top-level domain is the last label of every fully qualified domain name. They are called generic for historic reasons; initially, they were contrasted with country-specific TLDs in RFC 920.


The core group of generic top-level domains consists of the com, info, net, and org domains

When someone registers a domain name, he/she can specify which DNS server is the authoritative DNS server. This information is called an NS record. The NS record will tell a top-level domain DNS server which nameserver holds the domain's A record, MX record, etc.

How zone transfer happens in DNS

Zone transfer uses TCP for transport. The client requesting a zone transfer may be a slave server or secondary server, requesting data from a master server, sometimes called a primary server. 


Zone transfer comprises a introduction followed by the actual data transfer. The introduction comprises a Start of Authority (SOA) resource record for the "zone apex", the node of the DNS namespace that is at the top of the "zone". The fields of this SOA resource record, in particular the "serial number", determine whether the actual data transfer need to occur at all. The client compares the serial number of the SOA resource record with the serial number in the last copy of that resource record that it has. If the serial number of the record being transferred is greater, the data in the zone are deemed to have "changed" (in some fashion) and the slave proceeds to request the actual zone data transfer. If the serial numbers are identical, the data in the zone are deemed not to have "changed", and the client may continue to use the copy of the database that it already has, if it has one.

The actual data transfer process begins by the client sending a query (opcode 0) with the special query type AXFR (value 252) over the TCP connection to the server. The server responds with a series of response messages, comprising all of the resource records for every domain name in the "zone". The first response comprises the SOA resource record for the zone apex. The other data follows in no specified order. The end of the data is signaled by the server repeating the response containing the SOA resource record for the zone apex.

Some zone transfer clients perform the SOA lookup of the preamble using their system's normal DNS query resolution mechanism. These clients do not open a TCP connection to the server until they have determined that they need to perform the actual data transfer. However, since TCP can be used for normal DNS transactions, as well as for zone transfer, other zone transfer clients perform the SOA lookup preamble over the same TCP connection as they then (may) perform the actual data transfer. These clients open the TCP connection to the server before they even perform the preamble.

The preceding describes full zone transfer. Incremental zone transfer differs from full zone transfer in the following respects:

The client sends the SOA resource record for the zone apex that it currently has, if any, in the IXFR message, letting the server know which version of the "zone" it believes to be current.

Though the server may respond in the normal AXFR manner with the full data for the zone, it may also instead respond with an "incremental" data transfer. This latter comprises the list of changes to the zone data, in zone serial number order, between the version of the zone that the client reported to the server as having and the version of the zone that is current at the server. The changes comprise two lists, one of resource records that are deleted and one of resource records that are inserted. (A modification to a resource record is represented as a deletion followed by an insertion.)

Zone transfer is entirely client-initiated. Though servers can send a NOTIFY message to clients (that they have been informed about) whenever a change to the zone data has been made, the scheduling of zone transfers is entirely under the control of the clients. Clients schedule zone transfers initially, when their databases are empty, and thereafter at regular intervals, in a pattern controlled by the values in the "refresh", "retry", and "expire" fields in the SOA resource record of the zone apex.

In your case, you probably have the correct internal address in /etc/hosts.

If you host your DNS outside reistrar then you need to register your name server IP's to registrar. Registries use the Extensible Provisioning Protocol (EPP) to facilitate their registrar interactions. It's worth noting that this is a whole separate protocol from DNS itself, specifically dealing with name registration and provisioning. It only indirectly populates the relevant zone in DNS.

Domain Name System (DNS) Security Extensions Mapping for the Extensible Provisioning Protocol (EPP)

As more of a sidenote, the root servers deal with the root zone (aka .), a TLD zone is not the same as the "root". If you register for instance example.com through your registrar nothing changes in the root zone, your delegation is only entered into the com zone.

Difference between Zone and Domain/Domain Name Server and Domian Name System

Difference between zone and domain

Domain name servers store information about part of the domain name space called a zone. The name server is authoritative for a particular zone. A single name server can be authoritative for many zones.

Understanding the difference between a zone and a domain is sometimes confusing. A zone is simply a portion of a domain. If there are no subdomains, then the zone and domain are essentially the same. In this case the zone contains all data for the domain

For example, the Domain google.com may contain all of the data for google.com, maps.google.com and testing.google.com(Like SOA, MX, TXT...). 

However, the zone google.com contains only information for google.com and references to the authoritative name servers for the subdomains. The zone google.com can contain the data for subdomains of google.com if they have not been delegated to another server. For example, maps.google.com may manage its own delegated zone. testing.google.com may be managed by the parent, google.com.

Domain name server & domain name system

DNS(domain name server) is the backend system that resolves domain names and IPs worldwide. DNS (domain name system) is the whole system in whcih the process of resolving is done. You can say DNS as Domain name system or server.

Monday, July 24, 2017

Quick Reference

1) How to find WWN number of HBA

# cat /sys/class/fc_host/host*/node_name
# cat /sys/class/scsi_host/host*/device/fc_host/host*/node_name
# systool -c scsi_host -v

2) How to scan LUN in the server

For FC Host

# echo "1" > /sys/class/fc_host/host*/issue_lip

Above command performs a Loop Initialization Protocol (LIP) and then scans the interconnect and causes the SCSI layer to be updated to reflect the devices currently on the bus. A LIP is, essentially, a bus reset,  and will cause device addition and removal. This procedure is necessary to configure a new SCSI target on a Fibre Channel interconnect. Bear in mind that issue_lip is an asynchronous operation.

The command may complete before the entire scan has completed. You must monitor /var/log/messages to determine when it is done. 

For SCSI Host

# echo "- - -" > /sys/class/scsi_host/host*/scan

It means that you are echoing a wildcard value of "Channel, Target and Lun" (CTL), and the operating system will rescan the device path.

3) How to check the correct swapiness value

To check the swappiness value

# cat /proc/sys/vm/swappiness

swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible


swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

Default = 60




4) How to check which services use TCP Wrappers


TCP wrappers is used by the services which use libwrap.so module.

To check whether the program is using libwrap or not use below command.


# ldd /usr/sbin/rpc.mountd | grep -i libwrap.so
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f6b7c731000) 



5) How to check check NFS version from client

a) From Client : nfsstat -m


b) From server we can use: mount -v &  nfsstat -m


6) How to enable SFTP


subsystem sftp /usr/lib/openssh/sftpserver


7) cp and mv


cp - new inode number will be created. So source and destination will have difference INODE number.


mv - Only file name will get change there won't be any change in the inode number.number.


8) How to enable disable arp

To supress ARP on interface eth0 run the following command as root:
# ip link set dev eth0 arp off

To turn it back on again:
# ip link set dev eth0 arp on

9) How to check the I/O statistics of block devices



Below two file displays the I/O statistics of block devices.

# /proc/diskstats 

# cat /sys/block/<dev>/stat

10) Dirname & Basename command's


dirname <Comple path of file> - Will display the complete folder path without filename. 
dirname <Comple path of file> - Will display the file name only without folder path.

11) What are the components responsible in Linux for Hot plugging device detection.



Hotplugging is achieved in Linux by a combination of three components: Udev, HAL, and Dbus

12) Run multiple commands with Sudo



sudo sh -c 'command1 && command2'
sudo -- sh -c 'command1 && command2'
sudo -u userNameHere -- sh -c 'command1; command2'
sudo -- sh -c 'command1; command2'
sudo -- bash -c 'command1; command2'
sudo -i -- 'command1; command2; command3'
sudo -i -- sh -c 'command1 && command2 && command3'

13) What are by-uuid, by-id and by-path folders

by-UUID

UUID is a mechanism to give each filesystem a unique identifier. These identifiers are generated by filesystem utilities (e.g. mkfs.*) When the partition gets formatted and are designed so that collisions are unlikely. FAT and NTFS filesystems (fat and windows labels above) do not support UUID, but are still listed in /dev/disk/by-uuid with a shorter UID 


by-id and by-path


by-id creates a unique name depending on the hardware serial number, 
by-path depending on the shortest physical path (according to sysfs).

14) How to Assign IP in dhcp based on MAC



host blah {
    hardware ethernet <mac address>;
    fixed-address <ip address>;

}

15) Rename Ethernet device name in Linux


Linux Rename Eth0 Network Interface Card Name [ Udev ]


Step #1: Find out the MAC address of the Ethernet device


Note down the MAC address.


Step #2: Rename eth0 as wan0


To rename eth0 as wan0, edit a file called 70-persistent-net.rules in /etc/udev/rules.d/ directory, enter:


# vi /etc/udev/rules.d/70-persistent-net.rules



The names of the Ethernet devices are listed in this file as follows:

16) To Get list of file names in FTP to Local



ftp> dir -Rl <filename>  - Will transfer the list of files recursively to <filename> to local folder

Command Line Arguments/Substitutions & Referencing Variables

Example HTML page
List of some of command line arguments

$0 - Name of the script from the command line
$1 - First command-line argument
$2 - Second command-line argument
$3 - Third command-line argument
$4 - Fourth command-line argument
$5 - Fifth command-line argument
$6 - Sixth command-line argument
$7 - Seventh command-line argument
$8 - Eighth command-line argument
$9 - Ninth command-line argument
$# - Number of command-line arguments
$*, $@ - All command-line arguments, separated with spaces
$? - Return status of previous command
$$ - PID of the current shell under which they are executing

Referencing Variables


a) ${var := word) - If variable value is not set or null then var is set to the value of record


b) ${var :? message) - If variable value is not set or null then Message is printed to standard error

c) ${var:-word} - If var is null or unset, word is substituted for var. The value of var does not change.

d) ${var:+word} - If var is set, word is substituted for var. The value of var does not change.

Part II


# Set the initial value.
myvar=abc
echo “Test 1 ======”
echo $myvar                    # abc
echo ${myvar}                  # same as above, abc
echo {$myvar}                  # {abc}

echo “Test 2 ======”
echo myvar                       # Just the text myvar
echo “myvar”                     # Just the text myvar
echo “$myvar”                   # abc
echo “\$myvar”                  # $myvar

echo “Test 3 ======”
echo $myvardef                # Empty line
echo ${myvar}def             # abcdef
echo ${myvar}{def}           # abc{def}

echo “Test 4 ======”
echo $myvar$myvar         # abcabc
echo ${myvar}${myvar}    # abcabc

echo “Test 5 ======”
# Reset variable value, with spaces
myvar=”a b c”
echo “$myvar”                  # a b c
echo $myvar                    # a b c

echo “Test 6 ======”
# Difference between single quotes and double quotes
myvar=abc
echo "$myvar"                 # abc    
echo '$myvar'                  # $myvar

echo " '$myvar' "             #  'abc'        ; ' ' has no special meaning inside " "
echo ' "$myvar" '             # "$myvar"  ;  " " is treated literally inside ' '

Friday, July 14, 2017

ISO/OSI Model

Layer 1: The Physical Layer :

It is the lowest layer of the OSI Model.
It activates, maintains and deactivates the physical connection.
It is responsible for transmission and reception of the unstructured raw data over network.
Voltages and data rates needed for transmission is defined in the physical layer.
It converts the digital/analog bits into electrical signal or optical signals.
Data encoding is also done in this layer.

Layer 2: Data Link Layer :

Data link layer synchronizes the information which is to be transmitted over the physical layer.
The main function of this layer is to make sure data transfer is error free from one node to another, over the physical layer.
Transmitting and receiving data frames sequentially is managed by this layer.
This layer sends and expects acknowledgements for frames received and sent respectively. Resending of non-acknowledgement received frames is also handled by this layer.
This layer establishes a logical layer between two nodes and also manages the Frame traffic control over the network. It signals the transmitting node to stop, when the frame buffers are full.

Layer 3: The Network Layer :

It routes the signal through different channels from one node to other.
It acts as a network controller. It manages the Subnet traffic.
It decides by which route data should take.
It divides the outgoing messages into packets and assembles the incoming packets into messages for higher levels.

Layer 4: Transport Layer :

It decides if data transmission should be on parallel path or single path.
Functions such as Multiplexing, Segmenting or Splitting on the data are done by this layer
It receives messages from the Session layer above it, convert the message into smaller units and passes it on to the Network layer.
Transport layer can be very complex, depending upon the network requirements.
Transport layer breaks the message (data) into small units so that they are handled more efficiently by the network layer.

Layer 5: The Session Layer :

Session layer manages and synchronize the conversation between two different applications.
Transfer of data from source to destination session layer streams of data are marked and are resynchronized properly, so that the ends of the messages are not cut prematurely and data loss is avoided.

Layer 6: The Presentation Layer :

Presentation layer takes care that the data is sent in such a way that the receiver will understand the information (data) and will be able to use the data.
While receiving the data, presentation layer transforms the data to be ready for the application layer.
Languages(syntax) can be different of the two communicating systems. Under this condition presentation layer plays a role of translator.
It perfroms Data compression, Data encryption, Data conversion etc.

Layer 7: Application Layer :

It is the topmost layer.
Transferring of files disturbing the results to the user is also done in this layer. Mail services, directory services, network resource etc are services provided by application layer.
This layer mainly holds application programs to act upon the received and to be sent data.

Sunday, July 9, 2017

Extending SWAP

Example HTML page
Swap extension in linux can be done in two ways.

a) By creating a file
b) By creating a disk

We will see the steps for both the methods.

a) By creating a disk

a.1 Extend SWAP with the existing LVM

To extend an LVM2 swap logical volume (assuming /dev/VolGroup00/LogVol01 is the volume you want to extend):

(i) Disable swap for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01

(ii) Resize the LVM2 logical volume by 256 MB:
# lvresize /dev/VolGroup00/LogVol01 -L +256M

(iii) Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01

(iv) Enable the extended logical volume:
# swapon -va

(v) Test that the logical volume has been extended properly:
# cat /proc/swaps # free

a.2  Extend SWAP by Creating a new LVM

To add a swap volume group (assuming /dev/VolGroup00/LogVol02 is the swap volume you want to add):

(i) Create the LVM2 logical volume of size 256 MB:
# lvm lvcreate VolGroup00 -n LogVol02 -L 256M

(ii) Format the new swap space:
# mkswap /dev/VolGroup00/LogVol02

(iii) Add the following entry to the /etc/fstab file:
/dev/VolGroup00/LogVol02   swap     swap    defaults     0 0

# swapon -va
Test that the logical volume has been extended properly. Above command will enable the extended logical volume:

# cat /proc/swaps # free

b) By creating a Swap File

Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.

(i) dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:

(ii) mkswap /swapfile
To enable the swap file immediately but not automatically at boot time:

(iii) swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:

/swapfile          swap            swap    defaults        0 0