Jan 10, 2011

How to Install PPTP on CentOS

1. Use yum install ppp to install ppp

2. Download the last version of pptpd from below link :

http://poptop.sourceforge.net/yum/stable/packages/

3. Use rpm –ivh pptpd-lastversion.rpm to install the pptpd package

4. Open /etc/pptpd.conf, uncomment and edit localip and remoteip as you want.

5. Open /etc/ppp/chap-secrets and add the users connection information there :

# client server secret IP addresses

username pptpd password *

6. Restart the PPTP server.

* To use DNS address for clients open /etc/ppp/options.pptpd, uncomment and edit the DNS part :

ms-dns DNS Server Address

7. Open /etc/sysctl.conf and change net.ipv4.ip_forward=0 to 1

8. Use iptables command as below :

# iptables -t nat -I POSTROUTING -s source network -o output Ethernet -j SNAT --to gateway IP address

Ex. # iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to 192.168.1.1

9. Save your configuration :

/sbin/service iptables save

Apr 17, 2010

How to Find Who Use a File

It’s simply easy to find the user that reach a specific file with two regular commands.

1. Use fuser command to find the PID of that as bellow :

    fuser “file path/file name”

2. Use ps with grep to find who match with that PID :

    PS –aux | grep “PID Number” 

Apr 6, 2010

IPtables Tutorial

I was googling for IPtable and found the IPtable Tutorial 1.2.2, it was web edition and some other tried to make pdf one but they were terrible, I was searching more and finally found a great pdf edition, so I thought to share it with others.

IPtable Tutorial – Box.net

IPtable Tutorial – StoreGate

IPtable Tutorial – Ziddu

IPtable Tutorial – Drop.io

Nov 14, 2009

Bind 9 in a Chroot Jail (CentOS)

1. Install Bind in a folder as you like :

# ./configure --prefix=/usr/local/dns/Bind-9.6.1-P1/

# make && make install

2. It’s not a good idea to run Bind as root so create another username and group for this purpose :

# useradd –c NameServer –s /bin/false named

* named is the username I chose

3. Create a couple of folders for our Chroot Jail as I show below :

/chroot +—named

                       +—dev

                                  +—etc

                                  | +—namedb

                                  |            +—slave

                                 +—var

                                          +—run

4. Change all files and folders permission to 700 and select “named” as owner and group unless Chroot ( you may need Chroot folder for other purpose )  :

# chmod 700 named

# chown named:named named

5. Go to the Bind installation folder --> sbin and follow below commands :

# rndc-confgen –a  ( that makes a default rndc.key )

# rndc-confgen

6. Open rndc.key and replace the key with secret that I showed below in green and  copy all of them to named.conf in /chroot/named/etc/namedb folder.

key "rndc-key" {
       algorithm hmac-md5;
       secret "m2gKdMpZbyG49C9v+uXM6Q==";
};
controls {
       inet 127.0.0.1 port 953
               allow { 127.0.0.1; } keys { "rndc-key"; };
};

7. We need at least 2 necessary files and a symbolic link  :

  • named.conf
  • a zone file that specified in named.conf or other included file
  • a symbolic link for named.conf in /etc/namedb

8. Create 2 device in /chroot/named/dev folder :

# mknod /chroot/named/dev/null c 1 3

# mknod /chroot/named/dev/random c 1 8

# chmod 666 /chroot/named/dev/{null,random}

9. Now it’s ok to run named like something like this :

# /usr/local/dns/Bind-9.6.1-P1/named –4 –c /etc/namedb/named.conf –t \  /chroot/named –u named

* You can put the above command and also rndc ( if you like ) to a file in /etc/init.d folder and run it as a service.

* You have to specify the PID file path in named.conf or options that included  if you don’t want the Bind create an extra folder in chroot/named folder.

e.g.

options {
        directory "/etc/namedb";
        version "[If you have a legitimate reason for requesting this info, please contact ]";
        listen-on-v6 { none; };
        pid-file "/var/run/named/named.pid";
};

Oct 8, 2009

Solve the boot problem on Slackware with CCISS device

1. If you use CCISS device like “HP DL360” be sure follow by these command exactly:

# mkdir /mnt/root

# mount /dev/cciss/c0d0p1 /mnt/root (c0d0p1 is my / Partition)

# mount -o bind /dev /mnt/root/dev

# mount -t proc none /mnt/root/proc

# chroot /mnt/root

* codop1 = czerodzeropone

2. In lilo.conf file edit boot option as below:

boot = /dev/cciss/c0d0p1

3. Use these commands as next step:

# lilo -M /dev/cciss/c0d0 mbr

# lilo

# reboot

How to update Slackware kernel to the latest release

1. Follow by these commands:

# cd /usr/src

# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2

# tar –jxf linux-2.6.31.tar.bz2

# ln -s linux-2.6.31 linux

# cd /usr/src/linux

# cp /proc/config.gz

# gunzip config.gz

# mv config .config

2.    For customize the kernel configuration:

# make menuconfig

*   It’s recommended to reload the old config file in “Load an Alternate Configuration File”

3.    For compile and add it to boot folder:

# make all && make modules_install

# cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.31-l7

# cp System.map /boot/System.map-2.6.31-l7

# cp .config /boot/config-2.6.31-l7

4.    Edit lilo.conf with “vi /etc/lilo.conf” and add these lines at the top of older one:

default = Sl-2.6.31

image = /boot/vmlinuz-2.6.31-l7

root = /dev/sda2

label = Sl-2.6.31

read-only

5.    For update the LILO:

# lilo

# Reboot

Aug 28, 2009

PostFix On Linux (Ubuntu)

Before I begin to show how install and configure PostFix, I want to thank one of my best friend Nasser who encourage me to R&D on Linux and update my blog.

1. You can install PostFix easily with apt-get install postfix command.

2. For testing your mail server you need Mailx utility so install it same way as install PostFix.

3. After installing those packages you need to add and edit some parameters in your mail server configuration file, you can do this in two ways :

a. you can open the main.cf file in PostFix folder and edit or add your configuration lines like :

myhostname = mail.youdomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.yourdomain.com, localhost.yourdomain.com, localhost
relayhost =
mynetworks = 127.0.0.0/8, 192.168.1.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
default_transport = error
relay_transport = error
home_mailbox = Maildir/
inet_protocols = all

b. you can use postconf -e command for add or edit your configuration file as bellow :

postconf -e "mynetworks = 127.0.0.0/8, 192.168.1.0/24"

postconf -e "inet_interfaces = all"

4. Now you have to restart the PostFix with /etc/init.d/postfix restart.

5. Test your mail server with netcat command :

netcat mail.yourdomain.com 25

ehlo yourdomain.com
mail from: root@yourdomain.com
rcpt to: username@yourdomain.com
data
Subject: My first mail

Hi,
Are you there?
regards,
Admin. (and Enter In a new Line)
quit

6. Check your Maildir in your home directory, if there is a mail here from root, you did your job great.

* Remember to make Maildir directory if you want a tidy home directory.

7. For using POP3 service you have to install an extra package that call courier-pop.

8. After installation, you can test it with netcat command like :

netcat mail.yourdomain.com 110

user username
+OK Password required.
pass password
+OK logged in.
quit