LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-24-2003, 03:20 PM   #1
eyt
Member
 
Registered: Sep 2003
Posts: 76

Rep: Reputation: 15
iptables : pop3


Hi all,

I can only send mail but cannot receive mail when I enabled the firewall. If I disable the firewall, I can send and receive mail.
The mail server and the firewall are on the same machine.

Any problem with the rules?


The script for the firewall is as follows:

#!/bin/bash

############
# VAIABLES #
############

# UPLINK - interface connect to the internet
UPLINK="eth1"

INTERNALNET="10.0.0/16"

# all network interfaces
INTERFACES="lo eth0 eth1"

# Flood variables

# Overall limit for TCP-SYN-Flood detection
TCPSYNLIMIT="5/s"
# Burst limit for TCP-SYN-Flood detection
TCPSYNLIMITBURST="10"

# Overall limit for logging in logging-chain
LOGLIMIT="2/s"
# Burst limit for logging in logging-chain
LOGLIMITBURST="10"

# Overall limit for Ping-flood-detection
PINGLIMIT="5/s"
PINGLIMITBURST="10"


case "$1" in
stop)
echo "Shutting down firewall..."
# clear and reset all chains
iptables -F
iptables -F -t mangle
iptables -F -t nat
iptables -X
iptables -X -t mangle
iptables -X -t nat

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# turn off NAT/masqerading, if any
iptables -t nat -F POSTROUTING

echo "...done"
;;
status)
echo "The status comand is not supported for iptables"
;;
restart|reload)
$0 stop
$0 start
;;
start)

echo "Starting firewall..."
# flush everything
iptables -F
iptables -F -t mangle
iptables -F -t nat
iptables -X
iptables -X -t mangle

iptables -X -t nat

# set the default policies
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP


##################################################
# set network sysct1 options which affect tcp/ip #
##################################################

# enable forwarding in kernel
echo 1 > /proc/sys/net/ipv4/ip_forward

# disable IP spooling attacks, dropped spooled packets from all interfaces
echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter

# don't respond to broadcast pings (Smurf-Amplifier-Protection)
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

# block all source routing
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

# enable SYN Cookies
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

# kill redirects
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

# set out local port range
echo "32768 61000" > /proc/sys/net/ipv4/ip_local_port_range

# reduce DoS'ing ability by reducing timeouts
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo 1280 > /proc/sys/net/ipv4/tcp_max_syn_backlog

# explicitly disable ECN
if [ -e /proc/sys/net/ipv4/tcp_ecn ]
then
echo 0 > /proc/sys/net/ipv4/tcp_ecn
fi


###############
# INPUT_CHAIN #
###############


# kill invalid packets (illegal combinations of flag)
iptables -A INPUT -j DROP -m state --state INVALID

# allow all connections on the internal interfaces
iptables -A INPUT -j ACCEPT -i ! ${UPLINK}

# block all connections except initiated from the protected network
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED
iptables -A INPUT -j ACCEPT -m state --state NEW -i ! ${UPLINK}


# kill all connection to the local interface from the outside world
#iptables -A INPUT -j REJECT -d 127.0.0.0/8


# Ping flood protection
iptables -A INPUT -j ACCEPT -p icmp --icmp-type echo-request -m \
limit --limit 1/s

iptables -A INPUT -j DROP -p icmp --icmp-type echo-request

# Allow all other icmp
iptables -A INPUT -j ACCEPT -p icmp


############################################
# ENABLE PUBLIC ACCESS TO CERTAIN SERVICE ##
############################################

## named queries
iptables -A INPUT -j ACCEPT -p udp --dport domain
iptables -A INPUT -j ACCEPT -p udp --sport domain
iptables -A INPUT -j ACCEPT -p tcp --dport domain
iptables -A INPUT -j ACCEPT -p tcp --sport domain

# http
iptables -A INPUT -j ACCEPT -p tcp --dport 80
iptables -A INPUT -j ACCEPT -p tcp --sport 80

# mail - only allow to send mail from internal network
iptables -A INPUT -j ACCEPT -p tcp -i eth0 --sport mail


# mail rules for popping mail from outside world pop-3
iptables -A INPUT -p tcp --dport 110 -j ACCEPT


# allow ssh
iptables -A INPUT -j ACCEPT -p tcp --dport 22
iptables -A INPUT -j ACCEPT -p tcp --sport 22


# mysql
iptables -A INPUT -j ACCEPT -p tcp --dport 3306
iptables -A INPUT -j ACCEPT -p tcp --sport 3306


################
# OUTPUT-CHAIN #
################

# allow packets to go outside
iptables -A OUTPUT -j ACCEPT


###########
# LOGGING #
###########


# catch all the rules
iptables -A INPUT -p tcp -m limit --limit ${LOGLIMIT} --limit-burst ${LOGLIMITBURST} \
-j LOG --log-prefix "TCP packets: "

iptables -A INPUT -p udp -m limit --limit ${LOGLIMIT} --limit-burst ${LOGLIMITBURST} \
-j LOG --log-prefix "UDP packets: "

iptables -A INPUT -p icmp -m limit --limit ${LOGLIMIT} --limit-burst ${LOGLIMITBURST} \
-j LOG --log-prefix "ICMP packets: "


# Logging for connection requests only
iptables -A INPUT -p tcp --syn -m limit --limit 5/minute \
-j LOG --log-prefix "Firewall packet:"


iptables -A FORWARD -m limit --limit 3/min \
-j LOG --log-prefix "Forwarded: " --log-level info


iptables -A INPUT -m limit --limit $LOGLIMIT --limit-burst $LOGLIMITBURST \
-j LOG --log-prefix "fp=INVALID:1 a=DROP "


echo "...done"
;;
*)
echo "Usage: firewall (start|stop|restart)"
esac
 
Old 10-24-2003, 04:03 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
SMTP runs on port 35 you will needto add a rule to allow that as you have done for ssh and http.
 
Old 10-24-2003, 04:11 PM   #3
eyt
Member
 
Registered: Sep 2003
Posts: 76

Original Poster
Rep: Reputation: 15
I can send mail but I cannot receive mail.
 
Old 10-24-2003, 04:13 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Yes but if you don't let other servers access port 25 on your machine they will be unable to deliver.
 
Old 10-24-2003, 06:53 PM   #5
eyt
Member
 
Registered: Sep 2003
Posts: 76

Original Poster
Rep: Reputation: 15
Thanks, It is working now.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables DNAT of pop3 won't work danGynn Linux - Networking 0 02-26-2004 11:49 AM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
help please with sendmail, pop3, outlook 2002 and iptables Tigger Linux - Newbie 5 06-02-2003 10:50 AM
POP3/SMTP-IPTABLES Problems chris Linux - Networking 1 02-28-2003 04:55 AM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:26 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