Monday, October 18, 2010

POSTFIX - Creating a restriction on sending to a particular user or group

Requirement:

email / group email: test_group001@mydomain.com
Allowed on to send on this mail is only good.user@yahoo.com


Setup:

1. Existing working smtp postfix server.

Needed configs:


1. mkdir /etc/postfix/global_restriction
2. create a file /etc/postfix/global_restriction/global_group_allowed
#/etc/postfix/global_restriction/global_group_allowed
#entry for that file:
good.user@yahoo.com OK

3. create a file /etc/postfix/global_restriction/global_group_restriction
#/etc/postfix/global_restriction/global_group_restriction
#entry for the file below:
test_group001@ class_allowed_to_send_to_global_group

4. Create a restriction class at /etc/postfix/main.cf

Below should exist on that file:

smtpd_recipient_restrictions =
check_recipient_access hash:/etc/postfix/global_restriction/global_group_restriction
permit_mynetworks
#premit my network should be under check_recipinet_access so it will not allow thus sender with network

smtpd_client_restrictions =
check_recipient_access hash:/etc/postfix/global_restriction/global_group_restriction
permit_mynetworks


smtpd_restriction_classes = class_allowed_to_send_to_global_group
class_allowed_to_send_to_global_group = check_sender_access hash:/etc/postfix/global_restriction/global_group_allowed, reject


5. After creating, postmap all related file and postfix reload

Sunday, October 17, 2010

Bash Script to process csv

Task: To process the login id and Name using CSV, and this is only a 2 column csv.

example csv

#/$HOME/file1.txt
juan.delacruz,Juan Dela Cruz
pnoy.aquino,Ninoy Aquino
ohbet.gomez,Ohbet Gomez
#eof

#Script
#!/bin/bash
#
#
#
while IFS=, read login name
do
echo NAME:$name and LOGIN ID: $login
done < /$HOME/testtxt2
#eof



Note: IFS=, where "," is the delimiter (of course, its a csv :P)


#Output
[xxx@localhost ~]$ bin/test3.sh
NAME:Juan Dela Cruz and LOGIN ID: juan.delacruz
NAME:Ninoy Aquino and LOGIN ID: pnoy.aquino
NAME:Ohbet Gomez and LOGIN ID: ohbet.gomez

Tuesday, October 12, 2010

TIPS on Creating multiple directory on linux shell

I just want to create a multiple directory ranging from a - z on my /home

here how, just so I wont forget it, need to post it here.


the command echo {a..z} will result on
# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z


so creating under /home


mkdir /home/{a..z}


will result on, when doing ls -l /home


drwxr-xr-x 2 root root 4096 Oct 12 17:32 a
drwxr-xr-x 2 root root 4096 Oct 12 17:37 b
drwxr-xr-x 2 root root 4096 Oct 12 17:37 c
drwxr-xr-x 2 root root 4096 Oct 12 17:37 d
drwxr-xr-x 2 root root 4096 Oct 12 17:37 e
drwxr-xr-x 2 root root 4096 Oct 12 17:37 f
drwxr-xr-x 2 root root 4096 Oct 12 17:37 g
drwxr-xr-x 2 root root 4096 Oct 12 17:37 h
drwxr-xr-x 2 root root 4096 Oct 12 17:37 i
drwxr-xr-x 2 root root 4096 Oct 12 17:37 j
drwxr-xr-x 2 root root 4096 Oct 12 17:37 k
drwxr-xr-x 2 root root 4096 Oct 12 17:37 l
drwxr-xr-x 2 root root 4096 Oct 12 17:37 m
drwxr-xr-x 2 root root 4096 Oct 12 17:37 n
drwxr-xr-x 2 root root 4096 Oct 12 17:37 o
drwxr-xr-x 2 root root 4096 Oct 12 17:37 p
drwxr-xr-x 2 root root 4096 Oct 12 17:37 q
drwxr-xr-x 2 root root 4096 Oct 12 17:37 r
drwxr-xr-x 2 root root 4096 Oct 12 17:37 s
drwxr-xr-x 2 root root 4096 Oct 12 17:37 t
drwxr-xr-x 2 root root 4096 Oct 12 17:37 u
drwxr-xr-x 2 root root 4096 Oct 12 17:37 v
drwxr-xr-x 2 root root 4096 Oct 12 17:37 w
drwxr-xr-x 2 root root 4096 Oct 12 17:37 x
drwxr-xr-x 2 root root 4096 Oct 12 17:37 y
drwxr-xr-x 2 root root 4096 Oct 12 17:37 z


just as what I need to do.

Tuesday, May 11, 2010

Postfix Fallback Relay

See: http://www.postfix.org/postconf.5.html

fallback_relay (default: empty)

Optional list of relay hosts for SMTP destinations that can't be found or that are unreachable. With Postfix 2.3 this parameter is renamed to smtp_fallback_relay.

By default, mail is returned to the sender when a destination is not found, and delivery is deferred when a destination is unreachable.

The fallback relays must be SMTP destinations. Specify a domain, host, host:port, [host]:port, [address] or [address]:port; the form [host] turns off MX lookups. If you specify multiple SMTP destinations, Postfix will try them in the specified order.

Note: before Postfix 2.2, do not use the fallback_relay feature when relaying mail for a backup or primary MX domain. Mail would loop between the Postfix MX host and the fallback_relay host when the final destination is unavailable.

* In main.cf specify "relay_transport = relay",
* In master.cf specify "-o fallback_relay =" (i.e., empty) at the end of the relay entry.
* In transport maps, specify "relay:nexthop..." as the right-hand side for backup or primary MX domain entries.

Postfix version 2.2 and later will not use the fallback_relay feature for destinations that it is MX host for.

-

Here my actual scenario:

Servers:
mail1 - connected to mail2 and mail3 and internet with public IP
mail2 - connected to mail1 and mail3 and internet with public IP
mail3 - connected to mail2 and mail1 and internet with public IP


1. mail1 has its default smtp to its public IP since its a Postfix Server and its fallback_relay is mail2
2. The rest, same config, default smtp is it self, fallback_relay is the available mailx via intranet.

Config @ mail1


#/etc/postfix/main.cf
transport_maps = hash:/etc/postfix/transport



#/etc/postfix/transport
#smtp_server_mail2
@mail2.mydomain.com smtp_mail2:[mail2]
#
@mail3.mydomain.com smtp_mail3:[mail3]
#
#smtp_default, where all smtp goes thru
* smtp_default:



#/etc/postfix/master.cf
smtp_default unix - - n - - smtp -o fallback_relay=[xx.yy.zy.xz]
smtp_mail2 unix - - n - - smtp -o fallback_relay=[mail3]
smtp_mail3 unix - - n - - smtp -o fallback_relay=[mail2]
#

Thursday, April 8, 2010

Fixing rpmdb problem

I got this problem when running rpm at centos 5.3, dont know why.


[root@dimdim2 localhost ~]# yum list
rpmdb: Lock table is out of available locker entries
rpmdb: Unknown locker ID: 2a19
error: db4 error(22) from db->close: Invalid argument
error: cannot open Packages index using db3 - Cannot allocate memory (12)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.main(sys.argv[1:])
File "/usr/share/yum-cli/yummain.py", line 85, in main
base.getOptionsConfig(args)
File "/usr/share/yum-cli/cli.py", line 163, in getOptionsConfig
disabled_plugins=self.optparser._splitArg(opts.disableplugins))
File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 164, in _getConfig
self._conf = config.readMainConfig(startupconf)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 685, in readMainConfig
yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 752, in _getsysver
idx = ts.dbMatch('provides', distroverpkg)
TypeError: rpmdb open failed


the fix,

[root@dimdim2 localhost ~]# rm /var/lib/rpm/__db.00*
rm: remove regular empty file `/var/lib/rpm/__db.000'? y
rm: remove regular file `/var/lib/rpm/__db.001'? y
rm: remove regular file `/var/lib/rpm/__db.002'? y
rm: remove regular file `/var/lib/rpm/__db.003'? y


[root@dimdim2 localhost ~]# rpm --rebuilddb

Friday, May 29, 2009

Tips on nagios installation to bypass selinux

I installed a nagios3 monitoring on a centos 5 server, forgot to disable SELinux and I encountered some issue related to cgi and running external command. so here are some commands that can help without the need to restart the server.

Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

ref: nagios documentation - specific to fedora



chcon -R -t httpd_sys_script_rw_t /usr/local/nagios/var/rw/

ref: http://www.mail-archive.com/nagios-users@lists.sourceforge.net/msg14819.html

This allows the running of external command.

Btw, I installed nagios from source that is why the path referred to /usr/local/nagios.

hope it can help me next time. :D

Setting TimeZone at Linux via CLI

Quick how to change TimeZone under Linux using cli.

1. Login as root.

2. Issue command below:

mv /etc/localtime /etc/localtime-orig

- renaming the localtime reference file

3. Command for new timezone.

ln -sf /usr/share/zoneinfo/EST /etc/localtime

- this sets the timezone to EST

ln -sf /usr/share/zoneinfo/Asia/Manila /etc/localtime

- this sets the timezone to PHT

thats it!