• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 667
  • Last Modified:

iptables multiple ip's

Im extremely new to iptables and i need to block all traffic outgoing on port 25 except from a few machines.  I have it setup for 1 IP, but how do I set it up for multiple?  Here is the code I have. A.A.A.A is the IP.  I have 3 mail servers that i need to allow through.
#!/bin/sh
# Used for private firewall rules
 
# See how we were called.
case "$1" in
  start)
        ## add your 'start' rules here
        # Add SMTP Block   
	/sbin/iptables -A CUSTOMFORWARD -p tcp  -s ! A.A.A.A --destination-port 25 -i eth0 -j LOG --log-prefix "PORT25_REFUSED"   
	
	/sbin/iptables -A CUSTOMFORWARD -p tcp  -s ! A.A.A.A --destination-port 25 -i eth0 -j DROP
	
	 ;;
  stop)
        ## add your 'stop' rules here
        # Remove SMTP Block   
	/sbin/iptables -D CUSTOMFORWARD -p tcp  -s ! A.A.A.A --destination-port 25 -i eth0 -j LOG --log-prefix "PORT25_REFUSED"   
	
	/sbin/iptables -D CUSTOMFORWARD -p tcp  -s ! A.A.A.A --destination-port 25 -i eth0 -j DROP
	
	 ;;
  reload)
        $0 stop
        $0 start
        ## add your 'reload' rules here
        ;;
  *)
        echo "Usage: $0 {start|stop|reload}"
        ;;
esac

Open in new window

0
anauj0101
Asked:
anauj0101
1 Solution
 
giltjrCommented:
What I would suggest is that you code multiple accepts for the IP addresses you want, and then code a final drop something like:


/sbin/iptables -A CUSTOMFORWARD -p tcp  -s a.a.a.1 --destination-port 25 -i eth0 -j ACCEPT --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A CUSTOMFORWARD -p tcp  -s a.a.a.2 --destination-port 25 -i eth0 -j ACCEPT --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A CUSTOMFORWARD -p tcp  -s a.a.a.3 --destination-port 25 -i eth0 -j ACCEPT --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A CUSTOMFORWARD -p tcp  -s a.a.a.4 --destination-port 25 -i eth0 -j --log-prefix "PORT25_REFUSED"  
/sbin/iptables -A CUSTOMFORWARD -p tcp   --destination-port 25 -i eth0 -j DROP
0

Featured Post

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now