Wednesday, 10 December 2014

reduce-the-size-of-lvm-partitions



How to reduce or shrink the size of logical Volume Manager Partitions


In my case I will shrink or reduce the /data size using lvreduce command. To reduce lvm size first umount the partition and run e2fsck & then resize2fs.

Steps to reduce the /data partition to 3GB

Step:1 Check the disk space using below command












Step:2Umount /data using below command : 










Step:3 Use e2fsck command to check the file system









Step:4 Resize the partition using below command







Step:5 Use lvreduce command to reduce the size as shown below










Step:6 Mount and check the partition size












Note: Now you can see that your LVM size is 3 G only. 


Enjoy !!!!












Thursday, 27 November 2014

How to recovery log after delete in linux


Question:

The server is running Apache and by mistake one of the log files gets deleted via
rm kk.com-access_log
Without installing any 3rd party recovery tools how can you recover this file that your boss needs. Also assume that as soon as the log file was deleted that Apache was not restarted


Ans: So the simple answer is the deleted file is still held open by Apache so it can still be recovered in the /proc filesystem.
So here is how to get to it. 

For example I have a really small access_log

So let's remove it 

As we can see, there are access.log in httpd directory.



Now we will delete this access log file.   








So the file has been deleted now. So let’s find the process number for the main apache process. It will be owned by root




So we see that the pid for the main apache process is 15162. So now let’s list the file descriptors.



As you can see that is our file and it’s marked as deleted. So we can do




Now we can copy this file back to main directory.



Now you can enjoy...... your deleted file has been recovery.




Monday, 24 November 2014

What is Iptable? How to use iptable in linux

################################ Iptables ###################################


******************** Note: there is following target which use by iptables. ************************


Accept:      iptables stops further processing.
             The packet is handed over to the end application or the operating system for processing

Drop :       iptables stops further processing.
             The packet is blocked

Log :        The packet information is sent to the syslog daemon for logging
             iptables continues processing with the next rule in the table
        As you can't log and drop at the same time, it is common to have two similar rules in sequence. The first will log the packet, the second will drop it.

REJECT :     Works like the DROP target, but will also return an error message to the host sending the packet that the packet was blocked

DNAT   :     Used to do destination network address translation. ie. rewriting the destination IP address of the packet .

SNAT   :     Used to do source network address translation rewriting the source IP address of the packet
        The source IP address is user defined

MASQUERADE : Used to do Source Network Address Translation.
           
    By default the source IP address is the same as that used by the firewall's interface

***********  type of processing tables in iptables ************************************



Forward : Filters packets to servers accessible by another NIC on the firewall.

Input : Filters packets destined to the firewall.


Output : Filters packets originating from the firewall


Prerouting :   Address translation occurs before routing. Facilitates the transformation of the destination IP address to be compatible with the firewall's routing table.
      Used with NAT of the destination IP address, also known as destination NAT or DNAT.


Postrouting :  Address translation occurs after routing. This implies that there was no need to modify the destination IP address of the packet as in pre-routing.
Used with NAT of the source IP address using either one-to-one or many-to-one NAT. This is known as source NAT, or SNAT.


**********************************  iptables command Switch *************************************


-t <-table-> If you don't specify a table, then the filter table is assumed. As discussed before, the possible built-in tables include: filter, nat, mangle

-j <target> Jump to the specified target chain when the packet matches the current rule.

-A Append rule to end of a chain

-F Flush. Deletes all the rules in the selected table

-p <protocol-type> Match protocol. Types include, icmp, tcp, udp, and all

-s <ip-address> Match source IP address

-d <ip-address> Match destination IP address

-i <interface-name> Match "input" interface on which the packet enters.

-o <interface-name> Match "output" interface on which the packet exits .

-p tcp --sport <port> TCP source port. Can be a single value or a range in the format: start-port-number:end-port-number

-p tcp --dport <port> TCP destination port. Can be a single value or a range in the format: starting-port:ending-port

-p tcp --syn Used to identify a new TCP connection request. ! --syn means, not a new connection request

-p udp --sport <port> UDP source port. Can be a single value or a range in the format: starting-port:ending-port

-p udp --dport <port> UDP destination port. Can be a single value or a range in the format: starting-port:ending-port






******** there is one command for save your rules in iptables ************


iptables-save


iptables-restore < firewall-config

service iptables save .

################# Basic command of iptables #################################


        iptables -P INPUT   DROP       // set default policy to DROP
        iptables -P OUTPUT  DROP
        iptables -P FORWARD DROP
        iptables -F                    // flush all chains
        iptables -X                    // delete all chains


##############Type the following command to list current IPs in tables###########

         iptables -L -n
         iptables -L -n -v
         iptables -L chain-name -n -v
         iptables -L spamips -n -v
     
############ To display line number along with other information, enter ############

        iptables -L INPUT -n --line-numbers
        iptables -L OUTPUT -n --line-numbers
        iptables -L OUTPUT -n --line-numbers | less

Note: You will get the list of all blocked IP. Look at the number on the left, then use number to delete it. For example delete line number 10

       

         iptables -D INPUT 10



###### HOW to block particular port for particular IP #####################

         iptables -A INPUT -p tcp -s IP address --dport 22 -j DROP

###############how to block particular port for all #############

         iptables -A INPUT p tcp --dport 22 -j DROP

###How to redirect network traffic from particular ports to a particular port and ip address################



iptables -t nat -A PREROUTING -d 192.168.194.0 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 192.168.194.145:3128


10 examples of Linux ss command to monitor network connections

ss - socket statistics

In a previous tutorial we saw how to use the netstat command to get statistics on network/socket connections. However the netstat command has long been deprecated and replaced by the ss command from the iproute suite of tools.
The ss command is capable of showing more information than the netstat and is faster. The netstat command reads various /proc files to gather information. However this approach falls weak when there are lots of connections to display. This makes it slower.
The ss command gets its information directly from kernel space. The options used with the ss commands are very similar to netstat making it an easy replacement.
So in this tutorial we are going to see few examples of how to use the ss command to check the network connections and socket statistics.

1. List all connections

The simplest command is to list out all connections.
$ ss | less
Netid  State      Recv-Q Send-Q   Local Address:Port       Peer Address:Port   
u_str  ESTAB      0      0                    * 15545                 * 15544  
u_str  ESTAB      0      0                    * 12240                 * 12241  
u_str  ESTAB      0      0      @/tmp/dbus-2hQdRvvg49 12726                 * 12159  
u_str  ESTAB      0      0                    * 11808                 * 11256  
u_str  ESTAB      0      0                    * 15204                 * 15205  
.....
We are piping the output to less so that the output is scrollable. The output will contain all tcp, udp and unix socket connection details.
linux ss command

2. Filter out tcp,udp or unix connections

To view only tcp or udp or unix connections use the t, u or x option.
$ ss -t
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
ESTAB      0      0           192.168.1.2:43839     108.160.162.37:http    
ESTAB      0      0           192.168.1.2:43622     199.59.149.201:https   
ESTAB      0      0           192.168.1.2:33141      83.170.73.249:ircd    
ESTAB      0      0           192.168.1.2:54028     74.125.135.125:xmpp-client
$ ss -t
OR
$ ss -A tcp
By default the "t" option alone is going to report only those connections that are "established" or CONNECTED". It does not report the tcp sockets that are "LISTENING". Use the '-a' option together with t, to report them all at once.
List all udp connections
$ ss -ua
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
UNCONN     0      0           192.168.1.2:48268                  *:*       
UNCONN     0      0           192.168.1.2:56575                  *:*       
UNCONN     0      0                     *:40309                  *:*       
UNCONN     0      0           192.168.1.2:56879                  *:*       
UNCONN     0      0                     *:49014                  *:*       
UNCONN     0      0           192.168.1.2:53124                  *:*       
UNCONN     0      0             127.0.1.1:domain                 *:*
$ ss -a -A udp
The a option tells ss to report both "CONNECTED" and "LISTENING" sockets. Since UDP is a connection-less protocol, just "ss -u" will not report anything in most cases. Therefore we use the "a" option report all UDP connections (connected and listening).
Similarly use the x option to list out all unix socket connections.

3. Do not resolve hostname

To get the output faster, use the "n" option to prevent ss from resolving ip addresses to hostnames. But this will prevent resolution of port numbers as well.
$ ss -nt
State      Recv-Q Send-Q      Local Address:Port        Peer Address:Port 
ESTAB      0      0             192.168.1.2:43839     108.160.162.37:80    
ESTAB      0      0             192.168.1.2:51350      74.125.200.84:443   
ESTAB      0      0             192.168.1.2:33141      83.170.73.249:6667  
ESTAB      0      0             192.168.1.2:54028     74.125.135.125:5222  
ESTAB      0      0             192.168.1.2:48156      66.196.120.44:5050

4. Show only listening sockets

This will list out all the listening sockets. For example apache web server opens a socket connection on port 80 to listen for incoming connections.
$ ss -ltn
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      5                 127.0.1.1:53                       *:*     
LISTEN     0      128               127.0.0.1:631                      *:*     
LISTEN     0      128                     ::1:631                     :::*
The above command lists out all "listening" "tcp" connections. The n option disables hostname resolution of the ip addresses giving the output faster.
To list out all listening udp connections replace t by u
$ ss -lun
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
UNCONN     0      0                 127.0.1.1:53                       *:*     
UNCONN     0      0                         *:68                       *:*     
UNCONN     0      0               192.168.1.2:123                      *:*     
UNCONN     0      0                 127.0.0.1:123                      *:*     
UNCONN     0      0                         *:123                      *:*     
UNCONN     0      0                         *:5353                     *:*     
UNCONN     0      0                         *:47799                    *:*     
UNCONN     0      0                         *:25322                    *:*     
UNCONN     0      0                        :::54310                   :::*     
.....

5. Print process name and pid

To print out the process name/pid which owns the connection use the p option
$ ss -ltp
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
LISTEN     0      100           127.0.0.1:smtp                   *:*       
LISTEN     0      128           127.0.0.1:9050                   *:*       
LISTEN     0      128                   *:90                     *:*       
LISTEN     0      128                   *:db-lsp                 *:*        users:(("dropbox",3566,32))
LISTEN     0      5             127.0.0.1:6600                   *:*       
LISTEN     0      128           127.0.0.1:9000                   *:*        users:(("php5-fpm",1620,0),("php5-fpm",1619,0))
In the above output the last column contains the process name and pid. In this example dnsmasq is the process name and 1299 is the pid.
$ sudo ss -ltp
[sudo] password for enlightened: 
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
LISTEN     0      100           127.0.0.1:smtp                   *:*        users:(("master",2051,12))
LISTEN     0      128                   *:90                     *:*        users:(("nginx",1701,6),("nginx",1700,6),("nginx",1699,6),("nginx",1697,6),("nginx",1696,6))
LISTEN     0      5             127.0.0.1:6600                   *:*        users:(("mpd",2392,5))
LISTEN     0      128           127.0.0.1:9000                   *:*        users:(("php5-fpm",1620,0),("php5-fpm",1619,0),("php5-fpm",1616,7))
LISTEN     0      16                    *:2633                   *:*        users:(("oned",1853,16))
LISTEN     0      50            127.0.0.1:mysql                  *:*        users:(("mysqld",1095,10))
LISTEN     0      5             127.0.1.1:domain                 *:*        users:(("dnsmasq",1347,5))
LISTEN     0      32                    *:ftp                    *:*        users:(("vsftpd",1051,3))
LISTEN     0      128                   *:ssh                    *:*        users:(("sshd",1015,3))
LISTEN     0      128           127.0.0.1:ipp                    *:*        users:(("cupsd",688,11))
LISTEN     0      128                  :::http                  :::*        users:(("apache2",5322,4),("apache2",5321,4),("apache2",5317,4),("apache2",5316,4),("apache2",5313,4),("apache2",2505,4))
LISTEN     0      128                  :::ssh                   :::*        users:(("sshd",1015,4))
LISTEN     0      128                 ::1:ipp                   :::*        users:(("cupsd",688,10))

6. Print summary statistics

The s option prints out the statistics.
$ ss -s
Total: 526 (kernel 0)
TCP:   10 (estab 7, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0

Transport Total     IP        IPv6
*   0         -         -        
RAW   0         0         0        
UDP   15        9         6        
TCP   10        9         1        
INET   25        18        7        
FRAG   0         0         0

7. Display timer information

With the '-o' option, the time information of each connection would be displayed. The timer information tells how long with
$ ss -tn -o
State      Recv-Q Send-Q      Local Address:Port        Peer Address:Port 
ESTAB      0      0             192.168.1.2:43839     108.160.162.37:80    
ESTAB      0      0             192.168.1.2:36335     204.144.140.26:80     timer:(keepalive,26sec,0)
ESTAB      0      0             192.168.1.2:33141      83.170.73.249:6667  
ESTAB      0      0             192.168.1.2:58857      74.121.141.84:80     timer:(keepalive,23sec,0)
ESTAB      0      0             192.168.1.2:42794     173.194.40.239:80     timer:(keepalive,32sec,0)

8. Display only IPv4 or IPv6 socket connections

To display only IPv4 socket connections use the '-f inet' or '-4' option.
$ ss -tl -f inet
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
LISTEN     0      100           127.0.0.1:smtp                   *:*       
LISTEN     0      128           127.0.0.1:9050                   *:*       
LISTEN     0      128                   *:90                     *:*       
LISTEN     0      128                   *:db-lsp                 *:*       
LISTEN     0      5             127.0.0.1:6600                   *:*
To display only IPv6 connections use the '-f inet6' or '-6' option.
$ ss -tl6
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
LISTEN     0      100                 ::1:smtp                  :::*       
LISTEN     0      128                  :::12865                 :::*       
LISTEN     0      128                  :::http                  :::*       
LISTEN     0      128                  :::ssh                   :::*       
LISTEN     0      128                 ::1:ipp                   :::*

9. Filtering connections by tcp state

The ss command supports filters that can be use to display only specific connections. The filter expression should be suffixed after all options. The ss command accepts filter in the following format.
$ ss [ OPTIONS ] [ STATE-FILTER ] [ ADDRESS-FILTER ]
Now here are some examples of how to filter socket connections by socket states.
To display all Ipv4 tcp sockets that are in "connected" state.
$ ss -t4 state established
Recv-Q Send-Q         Local Address:Port             Peer Address:Port   
0      0                192.168.1.2:54436          165.193.246.23:https   
0      0                192.168.1.2:43386          173.194.72.125:xmpp-client 
0      0                192.168.1.2:38355           199.59.150.46:https   
0      0                192.168.1.2:56198          108.160.162.37:http
Display sockets with state time-wait
$ ss -t4 state time-wait
Recv-Q Send-Q         Local Address:Port             Peer Address:Port   
0      0                192.168.1.2:42261           199.59.150.39:https   
0      0                  127.0.0.1:43541               127.0.0.1:2633
The state can be either of the following
1. established 2. syn-sent 3. syn-recv 4. fin-wait-1 5. fin-wait-2 6. time-wait 7. closed 8. close-wait 9. last-ack 10. closing 11. all - All of the above states 12. connected - All the states except for listen and closed 13. synchronized - All the connected states except for syn-sent 14. bucket - Show states, which are maintained as minisockets, i.e. time-wait and syn-recv. 15. big - Opposite to bucket state.
Note that many states like syn-sent, syn-recv would not show any sockets most of the time, since sockets remain in such states for a very short time. It would be ideal to use the watch command to detect such socket states in real time.
Here is an example
$ watch -n 1 "ss -t4 state syn-sent"
After running the above command, try opening some website in a browser or download something from some url. Immediately you should see socket connections appearing in the output, but for a very short while.
Every 1.0s: ss -t4 state syn-sent                   Tue Apr  1 10:07:33 2014

Recv-Q Send-Q           Local Address:Port               Peer Address:Port

0      1                  192.168.1.2:55089            202.79.210.121:https

0      1                  192.168.1.2:33733             203.84.220.80:https

0      1                  192.168.1.2:36240             106.10.198.33:https

10. Filter connections by address and port number

Apart from tcp socket states, the ss command also supports filtering based on address and port number of the socket. The following examples demonstrate that.
Display all socket connections with source or destination port of ssh.
$ ss -at '( dport = :ssh or sport = :ssh )'
State      Recv-Q Send-Q    Local Address:Port        Peer Address:Port   
LISTEN     0      128                   *:ssh                    *:*       
LISTEN     0      128                  :::ssh                   :::*
Sockets with destination port 443 or 80
$ ss -nt '( dst :443 or dst :80 )'
State      Recv-Q Send-Q      Local Address:Port        Peer Address:Port 
ESTAB      0      0             192.168.1.2:58844      199.59.148.82:443   
ESTAB      0      0             192.168.1.2:55320     165.193.246.23:443   
ESTAB      0      0             192.168.1.2:56198     108.160.162.37:80    
ESTAB      0      0             192.168.1.2:54889    192.241.177.148:443   
ESTAB      0      0             192.168.1.2:39893      173.255.230.5:80    
ESTAB      0      0             192.168.1.2:33440      38.127.167.38:443
The following syntax would also work
$ ss -nt dst :443 or dst :80
More examples
# Filter by address
$ ss -nt dst 74.125.236.178

# CIDR notation is also supported
$ ss -nt dst 74.125.236.178/16

# Address and Port combined
$ ss -nt dst 74.125.236.178:80
Ports can also be filtered with dport/sport options. Port numbers must be prefixed with a ":".
$ ss -nt dport = :80
State      Recv-Q Send-Q      Local Address:Port        Peer Address:Port 
ESTAB      0      0             192.168.1.2:56198     108.160.162.37:80    
ESTAB      0      0             192.168.1.2:39893      173.255.230.5:80    
ESTAB      0      0             192.168.1.2:55043     74.125.236.178:80
The above is same as > ss -nt dst :80
Some more examples of filtering
# source address is 127.0.0.1 and source port is greater than 5000
$ ss -nt src 127.0.0.1 sport gt :5000

# local smtp (port 25) sockets
$ sudo ss -ntlp sport eq :smtp

# port numbers greater than 25
$ sudo ss -nt sport gt :1024

# sockets with remote ports less than 100
$ sudo ss -nt dport \< :100

# connections to remote port 80
$ sudo ss -nt state connected dport = :80
The following operators are supported when comparing port numbers
<= or le : Less than or equal to port >= or ge : Greater than or equal to port == or eq : Equal to port != or ne : Not equal to port < or gt : Less than to port > or lt : Greater than to port

Summary

The above examples cover most of what the ss command supports. For more information check the man pages.
Documentation of the filter syntax can be found in the package iproute2-doc that can be installed on debian/ubuntu systems
$ sudo apt-get install iproute2-doc
The file /usr/share/doc/iproute2-doc/ss.html contains details about the ss command filter syntax.

HOW TO CHECK TCP CONNECTION IN LINUX

############ HOW  TO CHECK TCP CONNECTION WITH PID  #############

  netstat -A inet  -p

[root@station ~]# netstat -A  inet -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0     52 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
[root@station ~]#







## TO CHECK ONLINE CONNECTION ###############


Command:    netstat  -A inet  -p  -c



[root@station ~]# netstat -A  inet -p  -c
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0     52 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0    196 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 station.example.com:ssh     192.168.194.1:51680         ESTABLISHED 6658/sshd
tcp        0      0 station.example.com:40538   63-150-12-26.dia.stati:http ESTABLISHED 3710/clock-applet
tcp        0      0 station.example.com:21064   192.168.194.173:55170       ESTABLISHED -






HOW TO CONFIGURE DNS IN LINUX/REDHAT 6/CENTOS 6


                                                                  How to configure DNS

What is DNS?
Domain Name System
The Domain Name System (DNS) is the crucial glue that keeps computer networks in harmony by converting human-friendly hostnames to the numerical IP addresses computers require to communicate with each other. DNS is one of the largest and most important distributed databases the world depends on by serving billions of DNS requests daily for public IP addresses. Most public DNS servers today are run by larger ISPs and commercial companies but private DNS servers can also be useful for private home networks.


Hostname: station.example.com
IP Address : 192.168.194.171



First check the IP:








To Set DNS Server IP

[root@station ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Note:  Please write ip  address of DNS server  in this file.





To Set Hostname

Note: Please write the hostname in below files.

[root@station ~]# hostname station.example.com


[root@station ~]# vi /etc/sysconfig/network

[root@station ~]# vi /etc/hosts









To Install Package



To Change directory


To create configuration file




To Change Group Name


To Copy File same Location



To change directory


To edit configuration file

[root@station named]# cat for.zone
$TTL 1D
@       IN SOA  example.com. root.example.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      station.example.com.
station IN      A       192.168.194.171
[root@station named]#


[root@station named]# cat rev.zone
$TTL 1D
@       IN SOA  example.com. root.example.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      station.example.com.
171       IN      PTR   station.example.com.


[root@station named]#





To Change Group Name


[root@station named]# chgrp named for.zone
[root@station named]# chgrp named rev.zone

To Restart Service & On

[root@station ~]#
[root@station ~]# service named restart
Stopping named: .                                          [  OK  ]
Starting named:                                            [  OK  ]
[root@station ~]#
[root@station ~]# chkconfig named on
[root@station ~]#


To Check Named Server



[root@station ~]#
[root@station ~]# dig 192.168.194.171

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 <<>> 192.168.194.171
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 15040
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;192.168.194.171.               IN      A

;; AUTHORITY SECTION:
.                       10800   IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2014112400 1800 900 604800 86400

;; Query time: 308 msec
;; SERVER: 192.168.194.171#53(192.168.194.171)
;; WHEN: Mon Nov 24 20:43:23 2014
;; MSG SIZE  rcvd: 108

[root@station ~]#

[root@station ~]#
[root@station ~]# dig station.example.com

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 <<>> station.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49533
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;station.example.com.           IN      A

;; ANSWER SECTION:
station.example.com.    86400   IN      A       192.168.194.171

;; AUTHORITY SECTION:
example.com.            86400   IN      NS      station.example.com.

;; Query time: 0 msec
;; SERVER: 192.168.194.171#53(192.168.194.171)
;; WHEN: Mon Nov 24 20:43:55 2014
;; MSG SIZE  rcvd: 67


[root@station ~]#
[root@station ~]# nslookup 192.168.194.171
Server:         192.168.194.171
Address:        192.168.194.171#53

171.194.168.192.in-addr.arpa    name = station.example.com.

[root@station ~]#

[root@station ~]#
[root@station ~]# nslookup station.example.com
Server:         192.168.194.171
Address:        192.168.194.171#53

Name:   station.example.com
Address: 192.168.194.171

[root@station ~]#

Client end setting:

Please write IP address of DNS server in /etc/resolv.conf

[root@station2 ~]#
[root@station2 ~]# cat /etc/resolv.conf
search station.example.com
nameserver 192.168.194.171
[root@station2 ~]#

[root@station2 ~]#
[root@station2 ~]#
[root@station2 ~]# dig 192.168.194.171

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 <<>> 192.168.194.171
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 62190
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;192.168.194.171.               IN      A

;; AUTHORITY SECTION:
.                       10490   IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2014112400 1800 900 604800 86400

;; Query time: 1 msec
;; SERVER: 192.168.194.171#53(192.168.194.171)
;; WHEN: Mon Nov 24 20:48:34 2014
;; MSG SIZE  rcvd: 108

[root@station2 ~]# dig station.example.com

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 <<>> station.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56694
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;station.example.com.           IN      A

;; ANSWER SECTION:
station.example.com.    86400   IN      A       192.168.194.171

;; AUTHORITY SECTION:
example.com.            86400   IN      NS      station.example.com.

;; Query time: 1 msec
;; SERVER: 192.168.194.171#53(192.168.194.171)
;; WHEN: Mon Nov 24 20:48:55 2014
;; MSG SIZE  rcvd: 67

[root@station2 ~]#