Monday, March 12, 2012

Installing and Configuring DHCP server

DHCP is a protocol that can provide the service to assign an ip address automatically. Many articles that explain about the dhcp. Click here to directly drop into landing page.

Now, let's get start.

I impltemented it in CentOS release 5.3 (Final) x86_64 architecture.

Well, install dhcpd first, follow the step below,
yum install -y dhcp
If you successfully install it, now let's configure dhcpd.conf file, follow the configuration below,
nano /etc/dhcpd.conf
and fill the configuration file with the configuration below,
# usual configuration
default-lease-time 86400;
max-lease-time 172800;
authoritative;
ddns-update-style ad-hoc;
log-facility local7;

# option DNS
option domain-name "YourDomainName";
option domain-name-servers aaa.bbb.ccc.ddd, eee.fff.ggg.hhh;

# option ntp-servers WINS
option netbios-name-servers 192.168.1.131;

# INTERNAL SCOOPE

        subnet 192.168.1.128 netmask 255.255.255.128 {
                range 192.168.1.150 192.168.1.250;

        # --- default gateway
                option routers 192.168.1.129;
                option subnet-mask 255.255.255.128;
        }
Example : option domain-name "myDomain.go", option domain-name-server "222.333.233.111, 222.222.333.444".

Then save it by pressing 'CTRL+x' then press 'y' and press 'ENTER' to confirm saving the file. Now, restart your dhcpd server using the command below,
service dhcpd start
That's it.

There's a tip from me, if you want to assign a specific ip address on a host, you can add this configuration at last line of  dhcpd.conf, take a look at the piece of configuration below,

# specific host with specific ip address

host edd {
       hardware ethernet 00:11:22:33:44:55;
       fixed-address 192.168.1.159;
       option host-name "Freddy";
}
note : wondering what is the hardware ethernet? it was your mac address, you can check yours by typing the command "ifconfig" without quote on linux machine or "ipconfig /all" without quote if you are in windowsX machine.

At last, set dhcpd service run on boot, follow the command below, 
echo service dhcpd start >> /etc/rc.local
Well, if you guys have any question, you my add the comments. That's all from me, thanks for visiting, and see you on the next tutorial ^^

Keep Learning ^^

Friday, March 9, 2012

Auto Backup mysql Data Using shell script and crontab

In this note i will give some trick that can help you to backup your mysql data without typing the command repeatedly everyday or every night. Naaa, i'm talking to much, then let's start it.

I implemented it on CentOS 5.5 i386 architecture. I think it can be run with almost all of unix distro. And you don't have to change your unix distro to the same as mine for successfully configuring.

Well, the command was same as you learned before at different articles, i'm not about to lead you up but, i just remembering all of you. Follow the step below. 

Make sure that you are as root. Now, create a directory that you will use to put your backup data, you can use this command below,
mkdir /home/backup
But before we continue, i will show you how do i backing up mysql data, here is the command,
mysqldump -uroot -pMyP4s5W0rD my_database_name > /home/backup/backup.my_databases.sql
note : command "-p" was the command to put your password after it.

You have to change some the command, because we are doing on different machine, different password, different database and different destination folder. adjust it with yours. If your basic command same as with me, then it will be not hard to scripting our autobackup shell script.

Well, let's create our shell file to /bin directory, follow this command below,
touch /bin/yourBackupShellFileName.sh
then, type this command below to edit our file and fill it with our shell script,
nano /bin/yourBackupShellFileName.sh
fill that file with this script,
#!/bin/sh
# yourBackupShellFileName.sh
Mdate="$(date +"%d-%m-%Y | %H:%M:%S")"
mysqldump -uroot -pMyP4s5W0rD my_database_name > /home/backup/backup.$Mdate.my_database_name.sql
wall messages you want to tell.
Then save it by pressing 'CTRL+X' then press 'y' then press 'enter' to confirm for saving file. Now, let's set the permission of that file we'v create like so,
chmod 770 /bin/yourBackupShellFileName.sh
or, if you want the permission for that file execute only, follow this command below,
chmod +x /bin/yourBackupShellFileName.sh
Well, you may test your shell script before set it up being autorun, by using this command below,
sh /bin/yourBackupShellFileName.sh
or
yourBackupShellFileName.sh
note : or change your directory to /bin directory and type yourBackupShellFileName.sh

It's looked like ok so far. Now, like i said before, we will use the crontab to make this shell script to be auto run in the time that we will setup. Click here for more information about crontab. Let's continue the configuration with crontab.

Now, open your crontab file by following this command below,
nano /etc/crontab
it will be shown us like this picture,













now, add our custom setting at the last line, like so,
22 17 * * * root /bin/yourBackupShellFileName.sh
note : i set my shell script to be autorun at 17 through 22 minutes. Sequentially, it was minute (0 - 59), hour (0 - 23), day of month (1 - 31), month (1 - 12), and day of week (0 - 6) (0 is Sunday, or use names). And you may change with your own custom time.

look at the picture below, it should be like this,













Then save it by pressing 'CTRL+X' then press 'y' then press 'enter' to confirm for saving file. 

Well, that's it. I hope this sort tutorial will help you to relieve your performance. See you on the next tutorial ^^

Thursday, March 8, 2012

How to Disable root Access on SSH Login

SSH is a network protocol use for remote a machine. you can read more about SSH by clicking here to directly move to landing page.


let's start our configuration by configuring sshd_confing file, follow this command below,
 nano /etc/ssh/sshd_config

Look at this picture below,


find on that lines,

# Authentication: 

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

Look at this picture below,














Then, remove the hash tag(#) at the "#PermitRootLogin yes" line and change the boolean "yes" to be "no". It should be like this below,
# Authentication: 

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6

Look at this picture below,














Then, save your Configuration by pressing 'CTRL+X' then press 'y' and then enter to confirm. You may restart your sshd service by using this command below,
 service sshd restart
or
 /etc/init.d/sshd restart

Well, that's it. i hope this sort tutorial will help you to more securing your own server from any intruder might be attacking your system. See you on the next tutorial ^^