Showing posts with label DNS. Show all posts
Showing posts with label DNS. Show all posts

Saturday, 24 March 2012

DNS Records

A     ## address record,Returns a 32-bit IPv4 address, most commonly used to
            map hostnames to an IP address of the host.
                            eric.ctechz.com. IN A 32.36.7.6
       
 (address) Maps a host name to an IP address. When a computer has multiple adapter cards or IP addresses, or both, it should have multiple address records.

AAAA   ## IPv6 address record, Returns a 128-bit IPv6 address, most commonly used to map hostnames to an IP address of the host.

CNAME  ## Canonical name record, Alias of one name to another: the DNS
                      lookup will continue by retrying the lookup with the new name.
                     CNAME records simply allow a machine to be known by more than
                     one hostname. There must always be an A record for the machine
                     before aliases can be added. The host name of a machine that is
                      stated in an A record is called the canonical.

                      www.ctechz. IN CNAME eric.ctechz.com.

 (canonical name) Sets an alias for a host name. For example, using this record, zeta.microsoft.com can have an alias as www.microsoft.com.

MX     ## mail exchange record, Maps a domain name to a list of message
                   transfer agents for that domain.

(mail exchange) Specifies a mail exchange server for the domain, which allows mail to be delivered to the correct mail servers in the domain.

NS    ## name server record, Delegates a DNS zone to use the given authoritative name servers.
                 ctechz.com. IN NS ravan.ctechz.com.

(name server) Specifies a name server for the domain, which allows DNS lookups within various zones. Each primary and secondary name server should be declared through this record.

PTR   ## pointer record, Pointer to a canonical name. Unlike a CNAME, DNS processing does NOT proceed, just the name is returned. The
most common use is for implementing reverse DNS lookups, but other uses
include such things as DNS-SD.

 (pointer) Creates a pointer that maps an IP address to a host name for reverse lookups.

SOA   ## start of [a zone of] authority record, Specifies authoritative
  information about a DNS zone, including the primary name server, the email of the domain administrator, the domain serial number, and
 several timers relating to refreshing the zone.

(start of authority) Declares the host that's the most authoritative for the zone and, as such, is the best source of DNS information for the zone. Each zone file must have an SOA record (which is created automatically when you add a zone).

    ctechz.com. IN SOA dom.ctechz.com.
        hostmaster.ctechz.com. (
           1996111901 ; Serial
           10800 ; Refresh
           3600 ; Retry
           3600000 ; Expire
           86400 ) ; Minimum

TXT   ## Text record, Originally for arbitrary human-readable text in a DNS
           record. 

The @ symbol in your DNS record refers to the record for your domain name without any www or sub-domain name.

The result of this record is that visitors can connect to your domain name at http://your-domain.com. You may also notice the @ symbol in the CNAME section:

ftp        @
www    @

This will create aliases to the @ A Record, which will point www.your-domain.com and ftp.your-domain.com to the same IP address.

The @ symbol may also be used in an MX record. For example:
@        mail        1
This indicates that the primary MX record for the email sent to @your-domain.com points to the A-record called "mail".

DNS Resolution Process

Let's check how a Domain Name Service works when we entering a name into a client like a browser or a mail client.

1. When a user type a host name (www.ctechz.co.in) in a browser the application then try to find the IP address associated with that domain name. The process associated with it is either called a reverse lookup or a forward lookup.

Checking of IP address associated with a domain name is
known as forward lookup and also the checking of domain name associated with an IP address is called reverse lookup.

There are 13 root name servers on the internet which provides the necessary name server details.

Each country has a name server and each organization has a name server too. Each NS only has information about machines in its own domain as well as information about other name servers. The root NS only has information on the ip address of the name servers of .com, .edu etc (top level domains).

* .in NS only has information on the IP address of the name servers of .org.in, .ac.in, .co.in etc

* .co.in NS only has information on the name servers of all indian companies or which hosted in india.

* .ctechz.co.in NS only has information on the machines at ctechz systems like www.ctechz.ci.in etc...

The Name Resolution Process

Here we can take an example with domain www.ctechz.co.in, the following take place to resolve this name into an IP address. This procedure is called hostname resolution and the algorithm performs this operation is called the resolver.

2.  The application checks local database on the local machine first. If it can get an answer directly from them it proceeds no further.

3. otherwise request will sent to NS to find the IP address associated with www.ctechz.ci.in.

4. NS determines whether that IP has been recently looked up or not. If it is there, no need to ask further. Since the result would be stored in a local cache.

5. NS checks whether the domain is local, ie, if a computer that has a direct information about. In  this case this would only be true if the NS were www.ctechz.co.in's very own NS.

6. NS strips out the TLD (top level domain) .in and it queries a root NS, asking what NS is responsible for .in. It will return an answer say a NS of IP 127.168.2.33. Depend on the answer NS will query authoritative server for IP address.

7. NS strips out the next highest domain .co.in and it queries to 127.168.2.33 asking what NS is responsible for .co.in, it will return an answer say a NS of IP 192.168.55.67.

8. NS strips out next highest domain .ctechz.co.in and it queries 192.168.55.67 asking what NS is responsible for ctechz.co.in, it will return an answer say a NS of IP 196.28.120.5

9. NS queries 196.28.120.5 asking for IP address of  www.ctechz.co.in and the answer will be 160.120.170.3

10. NS returns result to the application.

11. NS stores each of these result in local cache with an expiration date, to avoid having to look up a second time.

Configuring local Machine

Some configuration file in local machines are the following,

  /etc/host.conf
 /etc/hosts
 /etc/resolv.conf

1. Application checks /etc/host.conf which has the line order hosts,bind
 specify it should first check the local database file /etc/hosts and then query the NS specified in /etc/resolv.conf(bind)

The file /etc/hosts contain plain list of IP address and names. If an application can get an answer directly from /etc/hosts it proceeds no further.

2. The application checks in the file /etc/resolv.conf for a line 
nameserver <nameserver>

3. The application sends to the NS a query with the hostname [ checks local db first ]  then proceeds with the hierarchical queries.

Wednesday, 7 March 2012

How to enable sudo for normmal users

Sudo is a standard way to give users some administrative rights without giving out the root password. Sudo is very useful in a multi user environment with a mix of server and workstations. Simply call the command with sudo:

# sudo /etc/init.d/dhcpd restart     # Run the rc script as root
# sudo -u sysadmin whoami               # Run cmd as an other user

Sudo is configured in /etc/sudoers and must only be edited with visudo. The basic syntax is (the lists are comma separated):

user hosts = (runas) commands  # In /etc/sudoers

users one or more users or %group (like %wheel) to gain the rights
hosts list of hosts (or ALL)
runas list of users (or ALL) that the rule can be run as and enclosed in ( )!
commands list of commands (or ALL) that will be run as root or as (runas)


Additionally those keywords can be defined as alias, they are called User_Alias, Host_Alias, Runas_Alias and Cmnd_Alias. 

# cat /etc/sudoers
# Host aliases are subnets or hostnames.
  Host_Alias DMZ = 212.118.81.40/28
  Host_Alias DESKTOP = work1, work2


# User aliases are a list of users which can have the same rights
User_Alias ADMINS = colin, luca, admin

User_Alias DEVEL  = joe, jack, julia
Runas_Alias DBA   = oracle,pgsql


# Command aliases define the full path of a list of commands
Cmnd_Alias  SYSTEM = /sbin/reboot,/usr/bin/kill,/sbin/halt,/sbin/shutdown,/etc/init.d/
Cmnd_Alias  PW      = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root # Not root pwd!
Cmnd_Alias  DEBUG = /usr/sbin/tcpdump,/usr/bin/wireshark,/usr/bin/nmap

# The actual rules
root,ADMINS ALL = (ALL) NOPASSWD: ALL  # ADMINS can do anything w/o a password.
DEVEL  DESKTOP = (ALL) NOPASSWD: ALL  # Developers have full right on desktops
DEVEL DMZ =(ALL) NOPASSWD: DEBUG # Developers can debug the DMZ servers.

# User sysadmin can mess around in the DMZ servers with some commands.
sysadmin DMZ = (ALL) NOPASSWD: SYSTEM,PW,DEBUG
sysadmin ALL,!DMZ = (ALL) NOPASSWD: ALL # Can do anything outside the DMZ.

%dba  ALL = (DBA) ALL # Group dba can run as database user

# anyone can mount/unmount a cd-rom on the desktop machines
 ALL DESKTOP = NOPASSWD: /sbin/mount /cdrom,/sbin/umount /cdrom






How to clear DNS system cache in Linux / Windows / Mac

DNS (Domain Name System) is a resolution mechanism to translate, resolve and return real IP address of the serving machine against the fully qualified domain name of the URL (Uniform Resource Locator).

Whenever a domain has been resolved, the DNS resolution is stored and cached locally for future use. The caching of DNS on local system ensure the fastest speed to resolve any domain name, and reducing hits, and directly load and burn of DNS name servers. However, it may cause some issues such as some website and web pages not loading or cannot be contacted and connected when browsing, causing by changing of IP address or nameservers that hasn’t been reflected and refreshed on local copy. The symptom is more obvious when user set web browser to use proxy to surf the Internet, and these sites now can be loaded properly.

When encountering any inaccessible or unable to load web page issue, one possible resolution is to try to flush (empty and reset) the DNS cache on the system.

Flush dns to get a new name resolution. Also flush dns cache when you can’t access a newly registered domain name. You can simply flush your dns cache anytime to get new entry.

To flush DNS cache in Microsoft Windows (Win XP, Win ME, Win 2000)

Start -> Run -> type cmd

- in command prompt, type ipconfig /flushdns

- Done! You Window DNS cache has just been flush.

To flush the DNS cache in Linux, restart the nscd daemon

- To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal.

  -  /etc/rc.d/init.d/nscd stop
  -  /etc/rc.d/init.d/nscd start

- Once you run the command your linux DNS cache will flush.


To flush the DNS cache in Mac OS X Leopard

- type lookupd -flushcache in your terminal to flush the DNS resolver cache.

- Once you run the command your DNS cache (in Mac OS X) will flush.

To flush the DNS cache in Mac OS X

- type dscacheutil -flushcache in your terminal to flush the DNS resolver cache.

- Once you run the command your DNS cache (in Mac OS X Leopard) will flush.

To flush the DNS cache in Ubuntu

- sudo apt-get install nscd

- sudo service nscd restart

Clear local DNS cache for current user
nscd -i hosts

Clear local DNS cache for all users
nscd -I hosts

Flush caching BIND server dns cache

A caching BIND server obtains information from another server (a Zone Master) in response to a host query and then saves (caches) the data locally. All you have to do is restart bind to clear its cache

# /etc/init.d/named restart