LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2005, 08:27 PM   #1
bradb21
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Rep: Reputation: 0
IPTABLES with SENDMAIL on local machine


I have several services running on my machine (web, pop, smtp) running on my server and I'm having a hell of a hard time with IPTABLES and Sendmail in particular.

I've been testing a simple IPTABLES configuration, and even though I open port 25 I can still not telnet to my server on port 25. All the other ports/services seem to work without any problems. I can remove the rule for port 80 and my web site stops working, I add it back in, and it works again.

This is my simple config

iptables -A INPUT -p tcp -s 0/0 -d 0/0 --destination-port 22 --syn -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --destination-port 25 --syn -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --destination-port 110 --syn -j ACCEPT
iiptables -A INPUT -p tcp -s 0/0 -d 0/0 --destination-port 80 --syn -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --destination-port 443 --syn -j ACCEPT
iptables -A INPUT -s 0/0 -d 0/0 -p udp -j DROP
iptables -A INPUT -s 0/0 -d 0/0 -p tcp --syn -j DROP

So when I do this everything works except my SMTP on port 25, when I try to telnet to port 25 it just hangs. Then I do a IPTABLES -F and I can then telnet to port 25 again.

This doesn't make any sense. Is there some other port that I need to open for Sendmail SMTP? With IPTABLES flushed, I telnet to port 25 and do a NETSTAT at the console and all I see it my IP connected on SMTP.

I've tried several other iptable configs, and all of them always dropped my SSH connection and I had to reboot the server (this is a virtual host on the internet). This one has gotten me the closest to have a primative firewall, but only SMTP is not working???

Any ideas?

Thanks!

Brad
 
Old 06-01-2005, 09:04 PM   #2
mjsurette
Member
 
Registered: May 2005
Distribution: spiral, fedora
Posts: 65

Rep: Reputation: 18
The best way to find out what other traffic is happening is to flush the firewall, start tcpdump in a second window, and connect. The output of tcpdump will show you what's happening.

My first guess would be ident (port 113) If that's the case then it can be turned off in the sendmail.conf file by setting Timeout.ident = 0.

Mike
 
Old 06-02-2005, 06:26 AM   #3
bradb21
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
That makes sense, because I just discovered that if I let that telnet sit for a about 90sec it will connect.
 
Old 06-02-2005, 07:42 AM   #4
bradb21
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Yeah that ident setting was already in my SENDMAIL config, so that didn't help. I know I'm on the right track, but??

I did the flush and the TCPDUMP. The only thing I see happening immediately after I see my connection on port 25 the server seems to do a reverse DNS lookup on my ip address. It looks like somehow I'm blocking this DNS lookup from happening although I'm not blocking any outgoing packets with iptables. My statements are all incoming???

Thanks!

Brad
 
Old 06-02-2005, 11:14 PM   #5
mjsurette
Member
 
Registered: May 2005
Distribution: spiral, fedora
Posts: 65

Rep: Reputation: 18
DNS would be something else that sendmail needs. Try putting your IP address and hostname in /etc/hosts.

Also adding this to your script would probably help....

iptables -A INPUT -i lo -j ACCEPT

I assume that you have a policy of ACCEPT on your OUTPUT table.

Mike
 
Old 06-03-2005, 11:01 AM   #6
bradb21
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
This VPS that I'm running doesn't have the stateful module installed for iptables. I think that is the main problem.

I went to a simpler config that seems to be working OK for me now.

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -N valid-tcp-flags
iptables -A INPUT -p tcp -j valid-tcp-flags
iptables -A OUTPUT -p tcp -j valid-tcp-flags
iptables -A FORWARD -p tcp -j valid-tcp-flags
iptables -N valid-source-address
iptables -A INPUT -p ! tcp -j valid-source-address
iptables -A INPUT -p tcp --syn -j valid-source-address
iptables -A FORWARD -p ! tcp -j valid-source-address
iptables -A FORWARD -p tcp --syn -j valid-source-address
iptables -N valid-destination-address
iptables -A OUTPUT -j valid-destination-address
iptables -A FORWARD -j valid-destination-address
iptables -A valid-tcp-flags -p tcp --tcp-flags ALL NONE -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags ACK,FIN FIN -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags ACK,PSH PSH -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags ACK,URG URG -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A valid-tcp-flags -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
iptables -A valid-source-address -s 10.0.0.0/8 -j DROP
iptables -A valid-source-address -s 172.16.0.0/12 -j DROP
iptables -A valid-source-address -s 192.168.0.0/16 -j DROP
iptables -A valid-source-address -s 224.0.0.0/4 -j DROP
iptables -A valid-source-address -s 240.0.0.0/5 -j DROP
iptables -A valid-source-address -s 127.0.0.0/8 -j DROP
iptables -A valid-source-address -s 0.0.0.0/8 -j DROP
iptables -A valid-source-address -d 255.255.255.255 -j DROP
iptables -A valid-source-address -s 169.254.0.0/16 -j DROP
iptables -A valid-source-address -s 192.0.2.0/24 -j DROP
iptables -A OUTPUT -p udp --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p udp --sport 53 --dport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 995 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p tcp --dport 8443 --sport 1024:65535 -j DROP
iptables -A INPUT -p tcp --dport 3306 --sport 1024:65535 -j DROP
iptables -A INPUT -p tcp --dport 1:1023 -j DROP

Thanks!

Brad
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp: copy a file from local machine to remote machine seran Linux - Newbie 8 10-30-2007 12:23 PM
Setup local machine to allow lan machines to retrieve its local user mail. Brian1 Linux - Networking 3 03-30-2006 05:04 AM
trying to copy files from another machine to the local machine using telnet,..how? shrike_912 Programming 6 03-14-2006 04:45 PM
how to open a dilog on local machine when i do ssh to remote machine fahad26 Programming 3 05-03-2005 07:39 PM
Sendmail - Can I make sendmail think its a different machine? Thorkyl Linux - Networking 7 01-05-2004 06:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration