Tuesday, 28 March 2017

How To Relay Email On A Postfix Server

https://www.howtoforge.com/how-to-relay-email-on-a-postfix-server
https://www.linode.com/docs/email/postfix/postfix-smtp-debian7

1. Prerequisites

I assume that you already have set up a working postfix server and that you have an email account at your ISP which you can access. So you will need to have a login for your IPS's email account.

2. Edit the postfix config

First you need to edit your postfix config...
nano /etc/postfix/main.cf
... and add the following code at the end of your config:
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
smtp_always_send_ehlo = yes
relayhost = smtp.yourisp.com
smtpd_use_tls=yes
smtp_always_send_ehlo = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
#smtp_generic_maps = hash:/etc/postfix/generic
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
mydestination = $myhostname, SMTP, localhost.localdomain, , localhost
relayhost = [smtp.office365.com]:587
mynetworks = 20.10.1.127/32 127.0.0.0/8 20.10.1.6/32 192.168.20.0/24 [::ffff:127.0.0.0]/104 [::1]/128


Of course replace smtp.yourisp.com with the actual smtp server of your ISP. Also SASL must be working. If you followed the perfect howtos for setting up a server as provided by Falko then you don't have to worry about it. Then save and close the file.
If your ISP requires you to use a special port for sending email, then use a line like this instead:
relayhost = [smtp.yourisp.com]:PORT
In one of the cases that I have used this, I had to enter this:
relayhost = [smtpauth.bluewin.ch]:587

3. Edit /etc/postfix/saslpasswd

After having extended the postfix config you'll still need to add the credentials to the /etc/postfix/saslpasswd file, so that you can authorize yourself at your ISP.
nano /etc/postfix/saslpasswd
and then add this:
smtp.yourisp.com     yourlogin:yourpassword
[smtp.office365.com]:587 delivery@gdeasia.com:password
Of course replace yourlogin / yourpassword with the actual username and password provided by your ISP. You don't need to add the port there.

4. Hash /etc/postfix/saslpasswd

Before postfix can use that file, it needs to be hashed by postmap:
postmap /etc/postfix/saslpasswd

5. Restart postfix

Finally you need to restart postfix to use the new config:
/etc/init.d/postfix restart

Monday, 27 March 2017

Apache的Order Allow Deny心得

http://www.fwolf.com/blog/post/191

今天又被这两个参数小小的耍了一把,痛下决心整理一下,免得再被耽误时间。
Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权。
所以,最常用的是:
 Order Deny,Allow
 Allow from All
注意“Deny,Allow”中间只有一个逗号,也只能有一个逗号,有空格都会出错;单词的大小写不限。上面设定的含义是先设定“先检查禁止设定,没有禁止的全部允许”,而第二句没有Deny,也就是没有禁止访问的设定,直接就是允许所有访问了。这个主要是用来确保或者覆盖上级目录的设置,开放所有内容的访问权。
按照上面的解释,下面的设定是无条件禁止访问:
 Order Allow,Deny
 Deny from All
如果要禁止部分内容的访问,其他的全部开放:
 Order Deny,Allow
 Deny from ip1 ip2
或者
 Order Allow,Deny
 Allow from all
 Deny from ip1 ip2
apache会按照order决定最后使用哪一条规则,比如上面的第二种方式,虽然第二句allow允许了访问,但由于在order中allow不是最后规则,因此还需要看有没有deny规则,于是到了第三句,符合ip1和ip2的访问就被禁止了。注意,order决定的“最后”规则非常重要,下面是两个错误的例子和改正方式:
 Order Deny,Allow
 Allow from all
 Deny from domain.org
错误:想禁止来自domain.org的访问,但是deny不是最后规则,apache在处理到第二句allow的时候就已经匹配成功,根本就不会去看第三句。 解决方法:Order Allow,Deny,后面两句不动,即可。
 Order Allow,Deny
 Allow from ip1
 Deny from all
错误:想只允许来自ip1的访问,但是,虽然第二句中设定了allow规则,由于order中deny在后,所以会以第三句deny为准,而第三句的范围中又明显包含了ip1(all include ip1),所以所有的访问都被禁止了。 解决方法一:直接去掉第三句。 解决方法二:
 Order Deny,Allow
 Deny from all
 Allow from ip1