Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Feb 24, 2015 7:55 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
Hi Guys, I'm noob when it comes to email servers. But setup a linode a few weeks ago, installed Ubuntu 14.0.4 and VestaCP with Exim/Dovecot, Apache, Nginx etc.

The ip was blacklisted after about a week, on CBL, for sending spam emails or emails infected with a trojan.

I've got no idea how that happened... I haven't sent a lot of emails from it.

I installed Spam assassin and ClamAV, delisted the ip and hoped that that would fix the problem.

Yesterday the server was blacklisted again :( :|

I spend hours researching and figured I needed to block outgoing SMTP port 25 connections.

I tried a few different rules, not really knowing what I was doing. Anyhow, I've ended up blocking all port 25 connections, by simply not specifying any rules for port 25 and denying all by default in iptables.

But I'm puzzled. From what I read, this should stop all incoming and outgoing mail from my server? But it appears that the mail server is still working ok? I'm able to send and receive emails.

I'm just looking for a bit of advice... Am I doing the right thing by not allowing any port 25 connections? Or should I allow incoming and not outgoing, or vice versa? What other things could I be doing to try and stop spammers from taking advantage of my server?

Any help is muchly appreciated :D

Here's my iptables:

Code:
-P INPUT DROP
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 21,12000:12100 -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 465,587,2525 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 110,995 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 143,993 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 3306,5432 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8083 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -s 45.56.85.76/32 -j ACCEPT
-A INPUT -s 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 20 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 22 -j ACCEPT
-A INPUT -p udp -m udp --sport 53 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 110 -j ACCEPT
-A INPUT -p udp -m udp --sport 123 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 143 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 3306 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 5432 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 8433 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 8083 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 12000:12100 -j ACCEPT


Top
   
PostPosted: Tue Feb 24, 2015 10:18 pm 
Offline
Senior Newbie

Joined: Fri Oct 19, 2012 8:35 pm
Posts: 15
CBL lists your Linode as a SPAM sending IP.
You need to block OUTGOING to port 25 (unless you are really running a mail server trying to communicate with other mail servers on port 25)

So appended to your rules is:
-A OUTPUT -p tcp -m tcp --dport 25 -j DROP


Top
   
PostPosted: Tue Feb 24, 2015 10:48 pm 
Offline
Senior Member
User avatar

Joined: Sun Dec 27, 2009 11:12 pm
Posts: 1038
Location: Colorado, USA
Emmanuel2 wrote:
installed Ubuntu 14.0.4 and VestaCP with Exim/Dovecot, Apache, Nginx etc.

If you don't want email, why install Exim/Dovecot?

_________________
Either provide enough details for people to help, or sit back and listen to the crickets chirp.
Security thru obscurity is a myth - and really really annoying.


Top
   
PostPosted: Tue Feb 24, 2015 11:17 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
Thanks guys. Yes, I actually do run a mail server and want to be able to send emails from it.

I added these three rules:

Quote:
-A OUTPUT -s 45.56.85.76/32 -p tcp -m tcp --dport 25 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 25 -j LOG
-A OUTPUT -p tcp -m tcp --dport 25 -j DROP


Will that do the trick?

If I'm sending all my outgoing emails through port 587, then can just completely block all outgoing emails on port 25?


Top
   
PostPosted: Tue Feb 24, 2015 11:18 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
And yes, I figured that by blocking all incoming on port 25 I was stopping emails from coming in. Doh!


Top
   
PostPosted: Wed Feb 25, 2015 1:01 am 
Offline
Senior Newbie

Joined: Fri Oct 19, 2012 8:35 pm
Posts: 15
Emmanuel2 wrote:
Thanks guys. Yes, I actually do run a mail server and want to be able to send emails from it.

I added these three rules:

Quote:
-A OUTPUT -s 45.56.85.76/32 -p tcp -m tcp --dport 25 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 25 -j LOG
-A OUTPUT -p tcp -m tcp --dport 25 -j DROP


Will that do the trick?

If I'm sending all my outgoing emails through port 587, then can just completely block all outgoing emails on port 25?


It will work if your mail server is operating in smart hub mode where all mail are just given to the 45.56.85.76 server for actual delivery.

That's what I did at home since I have a domain under Google apps, then all my mail gets sent/relayed through google's smtp server under 587. (my ISP actually blocks outgoing 25)

Now if all the mail servers you are talking to uses 587, then yes you can block off 25, but last I checked actual mail server to server intra communication still uses port 25 (ie gmail.com to outlook.com)


Top
   
PostPosted: Wed Feb 25, 2015 1:09 am 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
Hmmm... ok.

How could I test to see if that configuration I have is working properly?

I seem to be able to send and receive emails no problem at the moment.


Top
   
PostPosted: Wed Feb 25, 2015 1:16 am 
Offline
Senior Newbie

Joined: Fri Oct 19, 2012 8:35 pm
Posts: 15
We seem to have gone off track.

Since you need to have port 25 open as you are running a public mail server (you are sending mail to other domains directly)
You'll need to audit your server, as CBL is claiming that your IP is involved in some hanky panky.

This is the real challenge when you are running your own server and you have no idea what's wrong.
I'm actually out of ideas right now.


Top
   
PostPosted: Wed Feb 25, 2015 1:31 am 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
Ok... well that makes two of us!


Top
   
PostPosted: Wed Feb 25, 2015 2:16 pm 
Offline
Senior Member

Joined: Wed Mar 03, 2010 2:04 pm
Posts: 111
Have you run an open relay test? Maybe you've got something misconfigured. Also check your mail logs for anything outbound that you didn't send yourself (or another valid account on the system).


Top
   
PostPosted: Wed Feb 25, 2015 7:45 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
As far as I know there is no open relay. I've tested it with mxtoolbox


Top
   
PostPosted: Wed Feb 25, 2015 8:19 pm 
Offline
Senior Member
User avatar

Joined: Sun Dec 27, 2009 11:12 pm
Posts: 1038
Location: Colorado, USA
If it's not an open relay, what else has the ability to send out emails? Something triggered the blacklists to label your IP a spammer.

_________________
Either provide enough details for people to help, or sit back and listen to the crickets chirp.
Security thru obscurity is a myth - and really really annoying.


Top
   
PostPosted: Wed Feb 25, 2015 8:31 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
Yeah, well that's the problem. Maybe there's some rogue php script?


Top
   
PostPosted: Wed Feb 25, 2015 8:35 pm 
Offline
Junior Member

Joined: Thu Dec 16, 2010 4:02 pm
Posts: 21
Website: http://www.onlythebible.com
I'm not sure what do to do try and troubleshoot it


Top
   
PostPosted: Wed Feb 25, 2015 9:37 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
You need to check your mail server logs; if you see a gazillion emails from (say) www-data then you know it's coming from a web site you're hosting. If you see a gazillion mails coming in, being relayed, going out then you have an smtp server config error.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group