Sunday, May 24, 2015

Setup DHCP Server On Ubuntu 14.04

DHCP server is used to assign IP address to client computers and other Network devices . Basically we need Ipaddress, Subnet mask, Gateway and DNS for network settings . We need to define these values in the DHCP server, so that the client computer connected to that network gets values automatically from DHCP server.
This guide helps you to setup DHCP server on ubuntu 14.04.

Setup DHCP server on ubuntu 14.04
Before installation, Make sure you have assigned static IP to the server.
Step 1 » Issue the below command to update repository.
raja@linuxforfreshers:~$ sudo apt-get update

Step 2 » Now install isc-dhcp-server package and dependencies.
raja@linuxforfreshers:~$ sudo apt-get install isc-dhcp-server -y

Step 3 » After installing, open /etc/default/isc-dhcp-server file and assign interface.
raja@linuxforfreshers:~$ sudo nano /etc/default/isc-dhcp-server

INTERFACES="eth0"

Step 4 » We need to define below values in dhcpd.conf file located in /etc/dhcp/ directory.

Example scenario:
Network : 192.168.1.0/24
Range : 192.168.1.20 ( Starting IP ) – 192.168.1.100 ( Ending IP )
Gateway : 192.168.1.1
Primary DNS : 192.168.1.5
Sec DNS : 8.8.8.8

Take backup copy before making changes to the original file .Better rename the file and create a new one .
raja@linuxforfreshers:~$ sudo mv /etc/dhcp/dhcpd.conf    /etc/dhcp/dhcpd.conf.org
raja@linuxforfreshers:~$ sudo nano /etc/dhcp/dhcpd.conf

and add the below code after making changes as per your network values.
# option definitions common to all supported networks...
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

subnet 192.168.1.0 netmask 255.255.255.0 {  #network
            range 192.168.1.10 192.168.100.100; # Range
            option domain-name-servers 192.168.1.5, 8.8.8.8; #Pri DNS , Sec DNS
            option domain-name "linuxforfreshers.com"; #Domain name
            option routers 192.168.1.1; #Gateway
            option broadcast-address 192.168.1.255; #Broadcast
            default-lease-time 600;
            max-lease-time 7200;
}

Step 5 » Now start/restart dhcp service using the below command.

raja@linuxforfreshers:~$ sudo service isc-dhcp-server restart

Address Reservation

Sometimes you need to reserve IP to some devices like printers, camera, linux machines etc.
In this case, first you need to find MAC Address of that device and define values in that particular subnet.

For example, Printer with 00:DD:HD:66:55:9B MAC Address has to be assigned with 192.168.100.50 IP. For this, you need to add code like below to that subnet.
subnet 192.168.1.0 netmask 255.255.255.0 {  #network
       -  -   -    -   - 
       max-lease-time 7200;
      host printer-finance {
                hardware ethernet 00:DD:HD:66:55:9B;
                fixed-address 192.168.1.50;
        }
       host cam-gate {
                hardware ethernet 00:KK:HD:44:55:22;
                fixed-address 192.168.1.90;
        }
}

and restart DHCP service.

raja@linuxforfreshers:~$ sudo service isc-dhcp-server restart



Sunday, May 17, 2015

Ubuntu apt-get & apt-cache commands



Apt-get & apt-cache are the command line package management utility in Ubuntu Linux. GUI version of apt-get command is the Synaptic Package Manager, in this post we are going to discuss 15 different examples of apt-get & apt-cache commands.

Example:1 List of all the available packages
ubuntu@localhost:~$ apt-cache pkgnames
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
e3
gnome-commander-data
grub-gfxpayload-lists
gweled
.......................................

Example:2 Search Packages using keywords
This command is very helpful when you are not sure about package name , just enter the keyword and apt-get command will list packages related to the keyword.
ubuntu@localhost:~$ apt-cache search "web server"
apache2 - Apache HTTP Server
apache2-bin - Apache HTTP Server (binary files and modules)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)
apache2-doc - Apache HTTP Server (on-site documentation)
apache2-utils - Apache HTTP Server (utility programs for web servers)
......................................................................
Note: If you have installed “apt-file” package then we can also search the package using config files as shown below :
ubuntu@localhost:~$ apt-file search nagios.cfg
ganglia-nagios-bridge: /usr/share/doc/ganglia-nagios-bridge/nagios.cfg
nagios3-common: /etc/nagios3/nagios.cfg
nagios3-common: /usr/share/doc/nagios3-common/examples/nagios.cfg.gz
pnp4nagios-bin: /etc/pnp4nagios/nagios.cfg
pnp4nagios-bin: /usr/share/doc/pnp4nagios/examples/nagios.cfg

Example:3 Display the basic information of Specific package.
ubuntu@localhost:~$ apt-cache show postfix
Package: postfix
Priority: optional
Section: mail
Installed-Size: 3524
Maintainer: LaMont Jones <lamont@debian.org>
Architecture: amd64
Version: 2.11.1-1
Replaces: mail-transport-agent
Provides: default-mta, mail-transport-agent
.....................................................
Example:4 List the dependency of Package.
ubuntu@localhost:~$ apt-cache depends postfix
postfix
 Depends: libc6
 Depends: libdb5.3
 Depends: libsasl2-2
 Depends: libsqlite3-0
 Depends: libssl1.0.0
 |Depends: debconf
 Depends: <debconf-2.0>
 cdebconf
 debconf
 Depends: netbase
 Depends: adduser
 Depends: dpkg
............................................
Example:5 Display the Cache Statistics using apt-cache.
ubuntu@localhost:~$ apt-cache stats
Total package names: 60877 (1,218 k)
Total package structures: 102824 (5,758 k)
 Normal packages: 71285
 Pure virtual packages: 1102
 Single virtual packages: 9151
 Mixed virtual packages: 1827
 Missing: 19459
Total distinct versions: 74913 (5,394 k)
Total distinct descriptions: 93792 (2,251 k)
Total dependencies: 573443 (16.1 M)
Total ver/file relations: 78007 (1,872 k)
Total Desc/File relations: 93792 (2,251 k)
Total Provides mappings: 16583 (332 k)
Total globbed strings: 171 (2,263 )
Total dependency version space: 2,665 k
Total slack space: 37.3 k
Total space accounted for: 29.5 M
Example:6 Update the package repository using “apt-get update”
Using the command “apt-get update” , we can resynchronize the package index files from their sources repository. Package index are retrieved from the file located at “/etc/apt/sources.list”
ubuntu@localhost:~$ sudo apt-get update
 Ign http://extras.ubuntu.com utopic InRelease
 Hit http://extras.ubuntu.com utopic Release.gpg
 Hit http://extras.ubuntu.com utopic Release
 Hit http://extras.ubuntu.com utopic/main Sources
 Hit http://extras.ubuntu.com utopic/main amd64 Packages
 Hit http://extras.ubuntu.com utopic/main i386 Packages
 Ign http://in.archive.ubuntu.com utopic InRelease
 Ign http://in.archive.ubuntu.com utopic-updates InRelease
 Ign http://in.archive.ubuntu.com utopic-backports InRelease
 ................................................................
Example:7 Install a package using apt-get command.
ubuntu@localhost:~$ sudo apt-get install icinga
In the above example we are installing a package named “icinga”

Example:8 Upgrade all the Installed Packages

ubuntu@localhost:~$ sudo apt-get upgrade

Example:9 Upgrade a Particular Package.

“install” option along with “–only-upgrade” in apt-get command is used to upgrade a particular package , example is shown below :
ubuntu@localhost:~$ sudo apt-get install filezilla --only-upgrade

Example:10 Removing a package using apt-get command.

ubuntu@localhost:~$ sudo apt-get remove skype
Above command will remove or delete the skype package only , if you want to delete its config files then use the “purge” option in the apt-get command. Example is shown below :
ubuntu@localhost:~$ sudo apt-get purge skype
We can also use the combination of above commands :
ubuntu@localhost:~$ sudo apt-get remove --purge skype

Example:11 Download the package in the Current Working Directory

ubuntu@localhost:~$ sudo apt-get download icinga
Get:1 http://in.archive.ubuntu.com/ubuntu/ utopic/universe icinga amd64 1.11.6-1build1 [1,474 B]
Fetched 1,474 B in 1s (1,363 B/s)
Above command will download icinga package in your current working directory.

Example:12 Clear disk Space used by retrieved package files.

ubuntu@localhost:~$ sudo apt-get clean
Above Command will clear the disk space used by apt-get command while retrieving(download) packages.
We can also use “autoclean” option in place of “clean“, the main difference between them is that autoclean removes package files that can no longer be downloaded, and are largely useless.
ubuntu@localhost:~$ sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

Example:13 Remove Packages using “autoremove” option.

When we use “autoremove” option with apt-get command , then it will remove the packages that were installed to satisfy the dependency of other packages and are now no longer needed or used.
ubuntu@localhost:~$ sudo apt-get autoremove icinga

Example:14 Display Changelog of a Package.

ubuntu@localhost:~$ sudo apt-get changelog apache2
Get:1 Changelog for apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.10-1ubuntu1/changelog) [195 kB]
Fetched 195 kB in 3s (60.9 kB/s)
Above Command will download the changelog of apache2 package and will display through sensible-pager on your screen.

Example:15 List broken dependencies using “check” option

ubuntu@localhost:~$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done

Saturday, May 16, 2015

Linux backup tools

Linux backup tools, A good plan b (backup) is essential in order to have the ability to recover from human errors, RAID or disk failure or File system corruption. A dependable backup tool is not a luxury, everyone needs to have one. But that doesn’t mean you need to spend a fortune.

Here some of my favorites Linux
Backup Tools

fwbackups

fwbackups is a feature-rich user backup program that allows you to backup your documents anytime, anywhere, this is, by far, the easiest of all the Linux backup tool. It is cross platform, has a user-friendly interface, and can do single backups or recurring scheduled backups. The fwbackups tool allows you to do backups either locally or remotely in tar, tar.gz, tar.bZ, or rsync format.
You can back up an entire computer or a single file. Unlike many backup utilities, fwbackups is easy to install because it will most likely be found in your distribution’s repository.

fwbackups Official Site

Bacula

Bacula is a set of Open Source, computer programs that permit you to manage backup, recovery, and verification of computer data across a network of computers of different kinds. Bacula is relatively easy to use and very efficient, while offering many advanced storage management features that make it easy to find and recover lost or damaged files. In technical terms, it is an Open Source, network based backup program.

Bacula Official Site

Rsync

Rsync is one of the most widely used Linux backup solutions. With rsync, you can do flexible incremental backups, either locally or remotely. Rsync can update whole directory trees and file systems; preserve links, ownerships, permissions, and privileges; use rsh, ssh, or direct sockets for connection; and support anonymous connections. Rsync is a command-line tool, one of the biggest pluses of using a command-line tool is that you can create simple scripts to use, in conjunction with cron, to create automated backups. For this, rsync is perfect.

Rsync Official Site

Mondorescue

Mondo Rescue is a GPL disaster recovery solution. It supports Linux and FreeBSD. It’s packaged for multiple distributions (Fedora, RHEL, openSuSE, SLES, Mandriva, Mageia, Debian, Ubuntu, Gentoo). It supports tapes, disks, network and CD/DVD as backup media, multiple filesystems, LVM, software and hardware Raid. Mondorescue is one of those tools you have around for disaster recovery because one of its strengths is backing up an entire installation, supports LVM 1/2, RAID, ext2, ext3, ext4, JFS, XFS, ReiserFS, and VFAT. Mondo is used by large companies.

Mondo Official Site

Amanda

Amanda allows an administrator to set up a single backup server and back up multiple hosts to it. It’s robust, reliable, and flexible. Amanda uses native Linux dump and/or tar to facilitate the backup process. One nice feature is that Amanda can use Samba to back up Windows clients to the same Amanda server. It’s important to note that with Amanda, there are separate applications for server and client. For the server, only Amanda is needed. For the client, the Amanda-client application must be installed.
Amanda Official Site

How to install Django on Ubuntu 14.04



 Installing Django on Ubuntu

Installation
Before we begin to install Django, we need to ensure that we have updated to the latest version of Python available.

$ apt-get update
$ apt-get install python-dev python-pip

check python version using below commands

$ python –version

Installing a database system (SQLite)


$ sudo apt-get install sqlite

Installing pip



$ sudo apt-get install python-pip

check pip version

$ pip - - version


Installing Django

$ cd /usr/local/hadoop/


 $ tar -xzvf index.html

$ cd Django-1.5.1

$ sudo python setup.py install

You can use this command to check that Django is installed and working

$ django-admin.py

Testing create a sample project 


 $ sudo django-admin.py startproject app   ( app is project name)

$ cd  app/

To run the project using following command

$ python manage.py runserver - -insecure

Run the above command get the following output

Validating models...

0 errors found
May 15, 2015 - 02:20:27
Django version 1.5.1, using settings 'app.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

goto browser type http://127.0.0.1:8000/