LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-17-2006, 10:36 AM   #1
ger87410
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
Need help allowing smtp from specific addresses


Redhat 9.0. (Upgrading is not an option.) T1 connected via wan0 and eth1 connects internal network.
Relatively new to firewalls.
We have a firewall script setup where we're blocking all connection from overseas.
Here's the script:
***********************************************************************
#!/bin/bash

# allow loopback to/from bba1
# allow bba1|LAN->Net DNS (udp 53), PASV FTP (tcp 21, 1024+), telnet
# allow HTTP (tcp 80), HTTPS (tcp 443) from LAN,Net
# allow SSH (tcp 22) from anywhere
# allow SMTP (tcp 25) to/from Net
# allow POP3 (tcp 110) from LAN

# blackship tracert to public IP gets timeout on 1st hop (bba1)
# but otherwise goes through for higher hop counts

iptables -F

iptables -X AVCIN
iptables -X AVCOUT
iptables -X AVCFWD

iptables -N AVCIN
iptables -N AVCOUT
iptables -N AVCFWD

#iptables -A AVCIN -p tcp ! --syn -m state --state NEW -j DROP
#iptables -A AVCFWD -p tcp ! --syn -m state --state NEW -j DROP

iptables -A AVCOUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A AVCIN -p icmp --icmp-type echo-reply -j ACCEPT
iptables -A AVCFWD -p icmp --icmp-type echo-reply -j ACCEPT

exec 3< /avc/data/badIps.txt
while read LINE <&3 ; do
LINE=${LINE#* }
LINE=${LINE% *}
iptables -A AVCIN -s $LINE -j REJECT
done

/*We're taking the ip addresses out of a text files here and assigning the value to the variable $LINE*/
exec 3< /avc/data/goodIps.txt
while read LINE <&3 ; do
LINE=${LINE#* }
LINE=${LINE% *}
# iptables -A AVCIN -s $LINE -j ACCEPT
iptables -A AVCIN -m multiport -p tcp -s $LINE --dport smtp,www,ftp,ftp-data,irc -j ACCEPT
iptables -A AVCIN -m multiport -p udp -s $LINE --dport smtp,www,ftp,ftp-data,irc -j ACCEPT
done

iptables -A AVCIN -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p tcp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A AVCIN -p udp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p udp -m state --state ESTABLISHED -j ACCEPT
iptables -A AVCOUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCFWD -p udp -m state --state ESTABLISHED -j ACCEPT
#iptables -A AVCFWD -i eth0 -p udp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCFWD -s 192.168.1.0/24 -p udp -m state --state NEW,ESTABLISHED -j
ACCEPT

# for ikano radius - eliminate the tcp ?
iptables -A AVCIN -p tcp -s 216.126.204.0/24 --dport 1645:1646 -m state --state
NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p tcp -s 165.154.11.0/24 --dport 1645:1646 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p udp -s 216.126.204.0/24 --dport 1645:1646 -m state --state
NEW,ESTABLISHED -j ACCEPT
iptables -A AVCIN -p udp -s 165.154.11.0/24 --dport 1645:1646 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A AVCIN -p tcp -m state --state ESTABLISHED -j ACCEPT
iptables -A AVCOUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCFWD -p tcp -m state --state ESTABLISHED -j ACCEPT
#iptables -A AVCFWD -i eth0 -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A AVCFWD -s 192.168.1.0/24 -p tcp -m state --state NEW,ESTABLISHED -j
ACCEPT

iptables -A AVCOUT -p tcp --sport 1024: --dport 1024: -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A AVCFWD -i eth0 -p tcp --sport 1024: --dport 1024: -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A AVCFWD -s 192.168.1.0/24 -p tcp --sport 1024: --dport 1024: -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A AVCIN -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A AVCOUT -p icmp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A AVCFWD -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A AVCFWD -i eth0 -p icmp -m state --state NEW,ESTABLISHED,RELATED -j
ACCEPT
iptables -A AVCFWD -s 192.168.1.0/24 -p icmp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

iptables -A AVCIN -s 192.168.1.0/24 -j ACCEPT

#iptables -A AVCIN -i lo -j ACCEPT
#iptables -A AVCOUT -o lo -j ACCEPT
iptables -A AVCIN -s 127.0.0.0/8 -j ACCEPT
iptables -A AVCOUT -d 127.0.0.0/8 -j ACCEPT

#iptables -A AVCIN -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A AVCIN -j DROP
iptables -A AVCOUT -j DROP
iptables -A AVCFWD -j DROP

iptables -I INPUT 1 -j AVCIN
iptables -I OUTPUT 1 -j AVCOUT
iptables -I FORWARD 1 -j AVCFWD

# this net addr trans rule is added in /etc/wanpipe/scripts/wanpipe1-wan0-start
#iptables -t nat -A POSTROUTING -j SNAT --source 192.168.1.0/24 --out-interface
wan0 --to-source 216.161.43.122

************************************************************************

We love this because it cuts our spam down to almost nill, but some of our customers have email account where the server is overseas. We're also blocking them (on accident).
Running that script will result in me not being able to `telnet mx01.perfora.net 25` (connection times out). As soon as I take out the part where it blocks the overseas ips, I can `telnet mx01.perfora.net 25` successfully.
How do I make it so that we can accept smtp connections from the addresses in goodIps.txt?
Thanks.
Gerald
 
Old 08-18-2006, 03:43 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
this might solve the problem.
iptables -A AVCOUT -p tcp --dport 25 -s ! mx01.perfora.net -m state --state NEW,ESTABLISHED -j ACCEPT
 
  


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
Allowing access only to specific websites? matux Linux - Security 2 11-28-2005 09:18 PM
block specific ip addresses paperdiesel Linux - Security 3 07-21-2004 11:47 AM
Suse 9.0 Pro Firewall not allowing multiple IP addresses youcanlaugh Linux - Networking 1 06-29-2004 05:11 PM
iptables - allowing hostnames from ip addresses chrisfirestar Linux - Security 13 01-20-2004 09:42 PM
Allowing a specific host to connect using ipchains Gameon Linux - Security 7 01-17-2002 04:15 AM

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

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