Tuesday, December 17, 2013

CentOS Linux: Add Static Routing

You can add static route On CentOS Enterprise Linux.
 
You can use any one of the following command line utility to add, delete, display, or manipulate the Linux kernel routing table on CentOS and friends:










  • ip command - A CentOS Linux command line tool to print / manipulate routing, devices, policy routing and tunnels.
  • route command - Older command line utility to show or manipulate the Linux kernel routing table. I suggest that you use ip command instead of route command. This command exists for historical and compatibility reasons only.
You need to edit the following configuration files for static route configuration :
  • /etc/sysconfig/network - Edit this file to set default gateway IP address.
  • /etc/sysconfig/network-scripts/route-ethX - Edit this file to set additional static gateway IP address.

CentOS: Displaying current routing table

Type any one of the following command:

# netstat -nr
# route -n
# ip route list


Sample outputs:
Fig.01: ip command displaying current CentOS Linux routing table
Fig.01: ip command displaying current CentOS Linux routing table

Warning: It is important that you configure routing correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.

CentOS Linux add a default gateway

In this example, route all traffic via 192.168.1.254 gateway connected via eth0 network interface. The following command will set a default gateway for both internal and external network (if any):

# route add default gw 192.168.1.254 eth0
OR
# ip route add 192.168.1.0/24 dev eth0

You can make routing changes persistent across CentOS Linux server reboots.

To set default gateway edit /etc/sysconfig/network as follows:

# cat /etc/sysconfig/network

Sample configuration file:
 
NETWORKING=yes
## server name ##
HOSTNAME=server1.cyberciti.biz
## Default route ##
GATEWAY=192.168.1.254
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no
 
Save and close the file. Restart the networking service on CentOS Linux, type:

# service network restart
# ip route list


To verify new settings ping to the default gateway and external network:

# ping 192.168.1.254
# ping www.cyberciti.biz
# host google.com

CentOS Linux static routing config for eth1 interface

The following is a sample route-eth1 file. The default gateway set to 192.168.2.254, interface eth1. The static route is 10.10.29.65 for 10.0.0.0/8 network:

# cat /etc/sysconfig/network-scripts/route-eth1

Sample configurations:

default 192.168.2.254 dev eth1
10.0.0.0/8 via 10.10.29.65 dev eth1
 
Alert: For eth0 interface use /etc/sysconfig/network-scripts/route-eth0 file. Avoid setting duplicate default gateways; either use /etc/sysconfig/network or /etc/sysconfig/network-scripts/route-ethX file. Do not use both files to configure default gateways.

A note about GUI/TUI tool

If you don't have X windows GUI (gnome/kde desktop) installed on CentOS server / system, than type the following command at shell prompt. This method can only set the default gateway. It can not be used to set additional static routing for interface. Type the following command:

# system-config-network-tui &

Fig.01: CentOS command line network config tool (click to large)

Fig.01: CentOS command line network config tool (click to large)
Select your Ethernet card such as eth0 or eth1 and hit [Enter] or [F12] special key to configure IP properties for selected NIC:

Fig.02: Setting up IPv4 properties on CentOS including default gateway (click to large)
Fig.02: Setting up IPv4 properties on CentOS including default gateway

You can obtain an IP address using DHCP or setup IP address manually. Once an IP address assigned, click on the Ok button to save the changes.

Debian Linux Install GNU GCC Compiler and Development Environment

How do I install GNU/GCC compiler and related tools (such as make, debugger, man pages) collection under Debian Linux system using command line options?

You need to install following packages on Debian and Ubuntu Linux:[a] build-essential package - Installs the following collection to compile c/c++ program on Debian/Ubuntu Linux:










  1. libc6-dev - C standard library.
  2. gcc - C compiler.
  3. g++ - C++ compiler.
  4. make - GNU make utility to maintain groups of programs.
  5. dpkg-dev - Debian package development tools.
Basically, build-essential package contains an informational list of packages which are considered essential for building Debian packages including gcc compiler, make and other required tools. This package also depends on the packages on that list, to make it easy to have the build-essential packages installed.

Installation

Open the Terminal and then type the following apt-get command as root user:

# apt-get update && apt-get upgrade
# apt-get install build-essential


OR

$ sudo apt-get install build-essential

Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  dpkg-dev fakeroot g++ g++-4.7 gcc gcc-4.7 libalgorithm-diff-perl 
libalgorithm-diff-xs-perl libalgorithm-merge-perl libc-dev-bin libc6-dev libdpkg-perl
  libfile-fcntllock-perl libitm1 libstdc++6-4.7-dev libtimedate-perl 
linux-libc-dev make manpages-dev
Suggested packages:
  debian-keyring g++-multilib g++-4.7-multilib gcc-4.7-doc libstdc++6-4.7-dbg 
gcc-multilib autoconf automake1.9 libtool flex bison gdb gcc-doc gcc-4.7-multilib
  libmudflap0-4.7-dev gcc-4.7-locales libgcc1-dbg libgomp1-dbg libitm1-dbg 
libquadmath0-dbg libmudflap0-dbg libcloog-ppl0 libppl-c2 libppl7 binutils-gold glibc-doc
  libstdc++6-4.7-doc make-doc
The following NEW packages will be installed:
  build-essential dpkg-dev fakeroot g++ g++-4.7 gcc gcc-4.7 libalgorithm-diff-perl 
libalgorithm-diff-xs-perl libalgorithm-merge-perl libc-dev-bin libc6-dev libdpkg-perl
  libfile-fcntllock-perl libitm1 libstdc++6-4.7-dev libtimedate-perl linux-libc-dev 
make manpages-dev
0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.5 MB of archives.
After this operation, 67.6 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrors.kernel.org/debian/ stable/main libitm1 amd64 4.7.2-5 [36.6 kB]
Get:2 http://mirrors.kernel.org/debian/ stable/main libc-dev-bin amd64 2.13-38 [224 kB]
.....
....
....
Setting up manpages-dev (3.44-1) ...
Setting up g++-4.7 (4.7.2-5) ...
Setting up g++ (4:4.7.2-1) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (11.5) ...
Setting up libstdc++6-4.7-dev (4.7.2-5) ...

Verify installation

You can verify gcc compiler and make tool using the following syntax:

# whereis gcc make
# gcc -v
# make -v


Sample outputs:

gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc
make: /usr/bin/make /usr/bin/X11/make /usr/share/man/man1/make.1.gz
...
..
gcc version 4.7.2 (Debian 4.7.2-5)
...
..
GNU Make 3.81
..
 
Now, you should able to compile software, create Debian packages or simply write a code using C / C++ compilers.

Reset your Forgotten Password quickly Ubuntu/Linux Mint/ and Related Distributions

If you have forgotten your Linux password, Many people face this problem you are not alone. It is probably one of the most common tech support problems. Luckily if you are using Ubuntu/any Linux they made it incredibly easy to reset your password.

So First Step is Boot in to Recovery Mode:


ubuntu password

You will see the following screen. Now select "root - Drop to root shell prompt" and press "Ok"

Ubuntu reset password

Here is video tutorial

If you forgot your username enter this command to know:



In linux case is sensitive about username and password, If you have upper case than you need to enter same letters.
Mount root with following command:



Now Enter following command to reset your password:



For example (See the picture above):



Now enter your new password and confirm it.
Reboot pc:



That's all

Wednesday, December 11, 2013

DNS (Domain Name Server) Fundamentals






DNS stands for Domain Name System, or Domain Name Server. DNS resolves an IP address to a hostname or vice versa. DNS is basically a large database which resides on various computers that contains the names and IP addresses of various hosts/domains. Other than ip-address DNS also associates various information with the domain names.

Structure of a DNS

DNS uses a hierarchical tree based name structure. At top of the tree is the “root” ( represented as a dot (.) ) followed by the TLD ( Top Level Domain ), then by the domain-name and any number of lower level sob-domains separated by a dot.

The Top Level Domains are divided into 2 categories:
1. Generic TLD (gTLD)

2. Country Code TLD (ccTLD)

Below are some of the common Generic Top Level Domains:
  • .com – comercial web sites
  • .org – non profit organizations web sites
  • .edu – restricted to schools and institutions.
  • .net – originally for network infrastructures, now unrestricted
Below are some fo the Country Code Top Level Domains:
  • .us – United States
  • .in – India
  • .uk – United Kingdom
  • .ru – Russia
The following shows a sample representation of the structure of the DNS tree:


Authority, Delegation and Zone

The Authority for the root domain and gTLD lies with Internet Corporation for Assigned Numbers and Names (ICANN). ccTLD’s are delegated to individual countries for administration purpose. Each level in the hierarchy may delegate the authoritative control to the next lower level. There is a DNS server running in every level of the hierarchy and the responsibility of running the DNS server lies with the Authority at that level.

For Example, when the root domain gets a DNS query for www.example.com, the root will delegate responsibility for resolving to its lower level “.com”, which in-turn will delegate to “example”. Finally the DNS server in the “example” will respond with the IP address of the hostname “www”.
A zone is simply a portion of a domain. For example, the domain example.com may contain all the information for a.example.com, b.example.com and c.example.com. However, the zone example.com contains only information for example.com and delegates the responsibility to the authoritative name servers for the subdomains. In general, if there are no subdomains, then the zone and domain are essentially the same.

Resource Records

A DNS zone database is made up of a collection of resource records. Each resource record specifies information about a particular object. The DNS server uses these records to answer queries for hosts in its zone. For example, address mapping (A) record, map a host name to an IP address, and reverse-lookup pointer (PTR) records map an IP address to a host name. Here are some of commonly used Resource Records.
  • A Record: The ‘A’ record specifies the IP address of a host. ‘A’ record will have the details of the domainname and its associated IP address. When a Query is given to resolve domainname, DNS server will refer the ‘A’ record and answer with the IP address present in the record.
  • PTR Record: A PTR record maps the IP address to a specific host.
  • NS Record: An NS record or name server record maps a domain name to a list of DNS
  • servers authoritative for that domain. Delegations depend on NS records.
  • MX Record: An MX record or mail exchange record maps a domain name to a list of mail exchange servers for that domain. For example, when you send a mail to alpha@example.com, the mail will be routed to the Mail Server as specified in MX record.
You can use dig command to query DNS server and view the above information.

DNS Queries

A DNS query would be something like ‘what is the IP address of a.example.com’. A DNS server may receive such a query for any domain, to which it has no information about. The DNS server will respond is different ways for which it has no information about.
The following are the three types of DNS queries:
  • Recursive query
  • Iterative query
  • Inverse query
In Recursive query, the following are the steps involved when a host queries its local DNS server for ‘a.example.com’.
  • Host sends query ‘what is the IP address of a.example.com’ to locally configured DNS server.
  • DNS server looks up a.example.com in local tables – not found
  • DNS sends query to a root-server for the IP of a.example.com
  • The root-server replies with a referral to the TLD servers for .com
  • The DNS server sends query ‘what is the IP address a.example.com’ to one of the .com TLD servers.
  • The TLD server replies with a referral to the name servers for example.com
  • The DNS server sends query ‘what is the IP address a.example.com’ to name server for example.com.
  • Zone file defines a A record which shows ‘a”s IP address is x.x.x.x.
  • DNS returns the A record for ‘a’.
In Iterative query, if the DNS server doesn’t know the answer, it will refer other DNS server as response. So the client which initiates the query will once again contact the DNS server which came in as response.In Inverse query, an IP address will be provided and a hostname will be asked.

How to Access iCloud From Windows

access-icloud-from-windows-browser

iCloud is Apple’s cloud storage service, offering integrated online backup and syncing for Apple devices. iCloud is built-in on iPhones, iPads, and Macs, but can also be accessed on Windows.
While other services allow you to upload any type of file, Apple chooses to place your data into different compartments. This can be confusing — for example, iCloud will store your documents forever, but will delete your stored photos eventually.

What iCloud Syncs and Backs Up

iCloud is an online service linked to your Apple ID. When you set up a new iPad or iPhone, iCloud is enabled by default. Apple provides a free 5 GB of iCloud space to each account, which is used to store the following things online:
  • Mail: You can choose to use an @icloud.com email address on your device. If you do, iCloud will store your mail and it will also be accessible on icloud.com. If you use another email service, such as Gmail, Outlook.com, or Yahoo! Mail, this feature does nothing.
  • Contacts: iCloud syncs your contacts, or address book, between your devices and makes it accessible on icloud.com.
  • Calendars: Calendar events you create on your device can be synced along with your iCloud account.
  • Reminders: Reminders is Apple’s to-do list or tasks app. Reminders you create on one device are synced between your devices.
  • Safari: iCloud syncs Safari browsing data, including your bookmarks, open tabs, and reading list between your devices. On a Windows PC, you can use the iCloud Control Panel to sync Safari’s bookmarks with Internet Explorer, Firefox, or Chrome.
  • Notes: iCloud can sync notes you take in the included Notes app and make them available on the iCloud website.
  • Keychain: iCloud Keychain is a new feature that functions as a syncing password manager for Safari on iOS and Macs. It doesn’t work with third-party applications unless the apps were designed with iCloud keychain support in mind, and iOS doesn’t make it easy to copy-paste these passwords into apps. A dedicated password manager like LastPass is probably a better solution for now.
  • Photos: iCloud’s Photo Stream feature temporarily syncs some photos between your devices. Unlike many other iCloud features, Photo Stream isn’t a permanent back up, only a temporary one. In other words, iCloud isn’t backing up all your photos, so you’ll need your own backup solution.
  • Documents & Data: Documents you create with Apple’s now-free iWork apps — Pages, Numbers, and Keynote — can be synced to iCloud. They can then be accessed from iWork apps on another iOS device, a Mac, or via the iCloud website. Other apps can also choose to store their data in iCloud.
  • Find My iPhone/iPad/Mac: The “Find My” services aren’t for storage, but they’re considered part of iCloud. They can be used to track your device via the iCloud website if you lose it.
  • Device Backups: Rather than requiring regular device backups via iTunes, iOS devices can automatically back up their data over Wi-Fi to iCloud when iCloud is enabled.
These iCloud settings are all accessible in the Settings app’s iCloud section on an iPhone, iPad, or iPod Touch. You can see which types of data are set to synchronize and choose what you want to synchronize.

Apple also syncs other data — for example, your history of purchased apps and content, as well as your iMessage and SMS messages.


Using iCloud on a Mac

Apple makes both the Mac OS X and iOS operating systems, so iCloud is integrated on a Mac. When setting up your Mac, you should be prompted to sign in with an iCloud account. If you want to manage what settings sync,  you can click the Apple menu, select System Preferences, and click iCloud. From here, you can control which types of settings sync, just as you can on an iOS device.

Accessing Your iCloud Data From Windows

There are two ways to access synced iCloud data on Windows: via the iCloud Control Panel desktop application and via the iCloud website.

The iCloud Control Panel, available for download from Apple’s website, offers the following features:
  • Mail, Contacts, Calendar, and Tasks Sync: iCloud Control Panel can sync this information with Outlook 2007 or later. If you don’t use Outlook, don’t worry — you can access this data on the iCloud website. “Tasks” used here is the same thing is “Reminders.”
  • Manage iCloud Storage: This feature allows you to see what’s taking up space on your iCloud storage — for example, device backups and settings backups from apps you’ve used — and delete them to free up space.


The iCloud website, which you can access at icloud.com, offers the following features:
  • Mail, Contacts, Calendar, Notes, Reminders: Your data from these productivity apps can be viewed and edited on the iCloud website, so you can access to it from any PC, even one running Windows. You don’t have to sync via Outlook to access this.
  • Find My iPhone/iPad/iPod Touch/Mac: Apple’s Find service is accessible from here, so you can sign into iCloud on any PC and track your device if you lose it. This feature displays the GPS location of your device on a map and allows you to remotely lock or wipe it.
  • Pages, Numbers, Keynote: The iWork apps now have web versions you can access via the iCloud website. Using these, you can view and edit your synced documents on any device.
Note that some features are only accessible on the desktop, while some are only accessible on the iCloud website. For example, you can’t view your Photo Stream on the iCloud website, while you can’t edit your iWork documents outside of a browser.



If you find yourself running out of free iCloud space and don’t want to delete data, Apple allows you to purchase additional iCloud storage space.