Kamis, 06 Agustus 2015

Setting up Sendmail

Q : Apakah server Linux atau UNIX bisa mengirim email ?

A : Bisa, saya menggunakan opensource software "sendmail" yang dapat running di port 25 (smtp). Sendmail bekerja secara Incoming Mail (reciver) dan Outgoing Mail (sender)

Berjalan di Centos/RHEL 6.3

1. Install Dependence Package

# yum install m4 telnet mailx

2. Install Sendmail dengan "yum"
 
# yum install sendmail sendmail-cf
 
3. Configuration Sendmail

Ketika sebelum configurasi sendmail, langsung dijalankan akan muncul sebagai berikut

# ps -ef | grep -v grep | grep -i sendmail
   root      3595     1  0 00:20 ?        00:00:00 sendmail: accepting connections
   smmsp     3604     1  0 00:20 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue

# netstat -an | grep :25 | grep tcp
   tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN

Sendmail masih menggunakan local interface host 127.0.0.1 dengan port 25.

Sehingga agar Sendmail bisa running maka harus kita config menjadi ip 0.0.0.0 dengan port 25 , ini karena smtp harus bisa terconnection seluruh network Linux. Confignya sebagai berikut

# vi /etc/mail/sendmail.mc

     Ubah dari :
     DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

     Menjadi :
     dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
 
Kemudian built file configurasi menggunakan "m4", sebagai berikut

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Restart sendmail untuk menjalankan service dan buat berjalan di bawah kernel dengan "chkonfig"

# service sendmail restart
# chkconfig sendmail on

Check service sendmail

# netstat -an | grep :25 | grep tcp
   tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN
 
4. Validation dan Testing

Create dua buah user di Linux
 
# useradd test1
# useradd test2

Login sebagai user "test1" dan coba kirim email ke user "test2" melalui command line

$ mail -s "Test mail from testuser1" testuser2
   Hello this is the test mail
   .
   EOT

Sekarang checking maillog di "/var/log/maillog" untuk melihat aktifitas dan melihat issue yang muncul.
 
# tail /var/log/maillog
   Aug 19 01:07:58 server001 sendmail[4019]: r7IJalr6004019: from=test1@xxx.com, size=37, class=0, nrcpts=1, msgid=, proto=SMTP, daemon=MTA,   relay=localhost [127.0.0.1]
   Aug 19 01:07:58 server001 sendmail[4022]: r7IJalr6004019: to=test2@xxx.com, ctladdr=test1@xxx.com (502/503), delay=00:00:39, xdelay=00:00:00, mailer=local, pri=30438, dsn=2.0.0, stat=Sent

Jika sendmail berhasil sukses berjalan maka akan muncul seperti berikut
 
$ mail
   N  1 test1@xxx.com       Mon Aug 19 01:07  13/503   "Sendmail Test"

5. Firewall Rule (optional)

Sebenarnya ini step optional yang bisa dijalankan dan juga bisa tidak di jalankan.

Berikut untuk open port 25 agar bisa interconnetion network dengan jaringan luar menggunkan "iptables", confignya sebagai berikut :

# iptables -A INPUT -p tcp -m tcp –dport 25 -j ACCEPT

Save dan Restart iptables

service iptables save
service iptables restart

Catatan :
Congratulation you have successfully setup MTA service using Sendmail, now is the time to configure Dovecot service to fetch mail using your favourite MUA (Mail User Agent) like MS Outlook, Thunderbird etc.


source : https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-email-mta-sendmail.html



Minggu, 08 Maret 2015

Compress and Uncompress a Whole Linux or UNIX Directory?

Q : Bagaimana compress seluruh direktori Linux atau UNIX menggunakan shell console / terminal ?

A : Saya menggunakan command Linux / UNIX

$ tar -zcvf archive-name.tar.gz directory-name ( Compress .tar.gz )

$ tar -cjf archive-name.tar.bz2 directory-name ( Compress .tar.bz2 )

Dimana,
  • -z : Compress archive using gzip program
  • -c : Create archive
  • -v : Verbose i.e display progress while creating archive
  • -f : Archive File name
  • -j : Decompress the contents of the compressed archive created by bzip2 program [tar.bz2]

Dan untuk Uncompress dengan command berikut :

$ tar -zxvf archive-name.tar.gz ( uncompress .tar.gz )

$ tar -xvf archive-name.tar.bz2 ( uncompress .tar.bz2 )

Dimana,
  • -x: Extract files

Catatan :
Dibeberapa command tar compress yang paling kecil dalam menghasilkan compressing adalah (.tar.bz2)

 source : http://www.tecmint.com/18-tar-command-examples-in-linux/