hannuh
November 22nd, 2012, 03:12 PM
I am converting our mail server to a "closed circuit" mail server, which will not attempt to send mail to world addresses other than specified in the host.txt file. Similarly, it should not accept mail from machines other than those in the hosts.txt. The server has a working sendmail for smtp, and dovecot for pop3 and imap.
I don't have much experience with iptables or ufw, so I'd like to run this by somebody who knows this stuff.
Would this work:
#!/bin/bash
# disable firewall
ufw disable
# reset all firewall rules
ufw reset
# set default rules
#
ufw default allow incoming
ufw default allow outgoing
# that's to allow all other services as before
#
ufw default deny smtp
ufw default deny pop3
ufw default deny imap
# that's to disable mail services
#
cat "/usr/local/bin/hosts.txt" | while read LINE
do
ufw allow smtp from $LINE to yyy.xxx.yyy.100
ufw allow pop3 from $LINE to yyy.xxx.yyy.100
ufw allow imap from $LINE to yyy.xxx.yyy.100
ufw allow smtp to $LINE from yyy.xxx.yyy.100
ufw allow pop3 to $LINE from yyy.xxx.yyy.100
ufw allow imap to $LINE from yyy.xxx.yyy.100
done
ufw enable
#
cat "/usr/local/bin/hosts.txt" | while read LINE
do
ufw allow smtp from $LINE to yyy.xxx.yyy.100
ufw allow pop3 from $LINE to yyy.xxx.yyy.100
ufw allow imap from $LINE to yyy.xxx.yyy.100
ufw allow smtp to $LINE from yyy.xxx.yyy.100
ufw allow pop3 to $LINE from yyy.xxx.yyy.100
ufw allow imap to $LINE from yyy.xxx.yyy.100
done
# where yyy.xxx.yyy.100 is the mail server and
# host.txt would be something like:
# xxx.yyy.xxx.0/24
# yyy.xxx.yyy.0/24
# xxy.yyx.xxy.0/24
#
ufw enable
As mentioned, I am not sure about my ufw syntax, there seem to be a lot variations that one can use.
All help appreciated,
Hannu
I don't have much experience with iptables or ufw, so I'd like to run this by somebody who knows this stuff.
Would this work:
#!/bin/bash
# disable firewall
ufw disable
# reset all firewall rules
ufw reset
# set default rules
#
ufw default allow incoming
ufw default allow outgoing
# that's to allow all other services as before
#
ufw default deny smtp
ufw default deny pop3
ufw default deny imap
# that's to disable mail services
#
cat "/usr/local/bin/hosts.txt" | while read LINE
do
ufw allow smtp from $LINE to yyy.xxx.yyy.100
ufw allow pop3 from $LINE to yyy.xxx.yyy.100
ufw allow imap from $LINE to yyy.xxx.yyy.100
ufw allow smtp to $LINE from yyy.xxx.yyy.100
ufw allow pop3 to $LINE from yyy.xxx.yyy.100
ufw allow imap to $LINE from yyy.xxx.yyy.100
done
ufw enable
#
cat "/usr/local/bin/hosts.txt" | while read LINE
do
ufw allow smtp from $LINE to yyy.xxx.yyy.100
ufw allow pop3 from $LINE to yyy.xxx.yyy.100
ufw allow imap from $LINE to yyy.xxx.yyy.100
ufw allow smtp to $LINE from yyy.xxx.yyy.100
ufw allow pop3 to $LINE from yyy.xxx.yyy.100
ufw allow imap to $LINE from yyy.xxx.yyy.100
done
# where yyy.xxx.yyy.100 is the mail server and
# host.txt would be something like:
# xxx.yyy.xxx.0/24
# yyy.xxx.yyy.0/24
# xxy.yyx.xxy.0/24
#
ufw enable
As mentioned, I am not sure about my ufw syntax, there seem to be a lot variations that one can use.
All help appreciated,
Hannu