LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-09-2005, 03:22 AM   #1
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Rep: Reputation: 15
Firewall Security / Gateway Routing


Howdy all..

I have my network setup with ppp0 frontend to net which server gateway/router to the other 2 boxes on net IPs (not NAT).

Anyhow I originally was using NAT and wrote firewall using IN to block data. I think now I need to write it using different rules, cause each the other machines are getting every connection attempt coming through.

My firewall goes something like this:
Code:
#!/bin/sh

iptables=/sbin/iptables
modprobe=/sbin/modprobe
mynetwork=A.B.C.144/29

# Flushing tables..
$iptables -F
$iptables -t nat -F

# MASQ rules for gateway

echo "1" > /proc/sys/net/ipv4/ip_forward

# Loading modules

$modprobe ip_conntrack_irc
$modprobe ip_nat_irc
$modprobe ip_conntrack_ftp
$modprobe ip_nat_ftp

# Functions

allowPorts () {
        case "$1" in
                permit)
                        $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.146 --dport A -j ACCEPT
                        $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.146 --dport B -j ACCEPT
                        $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.146 --dport C -j ACCEPT
                        $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.146 --dport 146 -j ACCEPT
                ;;

                forward)
                ;;
        esac
}
blockAll () {
        $iptables -A INPUT -i ppp0 -p all -j DROP
}

# Switch
case "$1" in
        start|restart|reload)
                # PERMIT SELECTED PORTS
                $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.143 --dport 22 -j ACCEPT
                $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.143 --dport 80 -j ACCEPT
                $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.145 --dport 22 -j ACCEPT
                $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.145 --dport 80 -j ACCEPT
                $iptables -A INPUT -i ppp0 -p tcp --destination A.B.C.146 --dport 113 -j ACCEPT
                allowPorts permit

                # ALLOW INCOMING BASED ON EXISTING
                $iptables -A INPUT -m state --state NEW -i ! ppp0 -j ACCEPT
                $iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

                # BLOCK REMAINING
                blockAll

                # ETHERNET PORT FORWARDING
                allowPorts forward

                echo "Firewall rules loaded successfully!"
                ;;

        stop|kill|drop)

                echo "Firewall rules unloaded successfully!"
                ;;

        paranoid|insane)
                # ALLOW INCOMING SSH
                $iptables -A INPUT -i ppp0 -p tcp --dport 22 -j ACCEPT

                # BLOCK REMAINING
                blockAll

                echo "Firewall rules loaded successfully! Only allowing SSH connections."
                ;;

        *)
                echo "Usage: /etc/init.d/firewall (start|stop|reload|restart|paranoid)"
                exit 1
                ;;

esac

exit 0
Sort of ignore the opened port access and A,B,Cs but you should get the idea.

143 is the gateway and I want only 22 and 80 open on it, as for remaining network I I want 22,80 open on 145 and the rest DROPPED.

I guess more than anything i'm after the command. I tried using -A FORWARD but that blocked outgoing traffic too..


Please, any help would be great!
 
Old 09-09-2005, 07:11 AM   #2
maxut
Senior Member
 
Registered: May 2003
Location: istanbul
Distribution: debian - redhat - others
Posts: 1,188

Rep: Reputation: 50
u can block net activity via FORWARD chain.
expamle:

box1: ip=A.A.A.2 needs port 80
box2: ip=A.A.A.3 needs port 22
Code:
iptables -F FORWARD
iptables -P FORWARD DROP
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth(local) -s localnet/subnet -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp -dport 80 -d A.A.A.2 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp -dport 22 -d A.A.A.3 -j ACCEPT
i hope this helps u.

good luck.

Last edited by maxut; 09-09-2005 at 07:13 AM.
 
Old 09-09-2005, 06:26 PM   #3
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by maxut
u can block net activity via FORWARD chain.
expamle:

box1: ip=A.A.A.2 needs port 80
box2: ip=A.A.A.3 needs port 22
Code:
iptables -F FORWARD
iptables -P FORWARD DROP
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth(local) -s localnet/subnet -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp -dport 80 -d A.A.A.2 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp -dport 22 -d A.A.A.3 -j ACCEPT
i hope this helps u.

good luck.

I thought it was allow then block
 
Old 09-09-2005, 06:40 PM   #4
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Original Poster
Rep: Reputation: 15
I got it now, thanks mate that worked well.. -P policy
 
  


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
Firewall Security / Gateway Routing colabus Linux - Networking 1 09-13-2005 11:15 PM
routing/gateway/masquerade help wanted -=dionis=- Linux - Networking 4 06-25-2005 07:17 AM
Routing/Gateway with suse 9.2 is giving me a HARD time. AliDigitaly Linux - Networking 5 04-29-2005 09:02 AM
Default Gateway Not Listed In Routing Table krazyace78 Linux - Networking 0 10-05-2004 12:09 PM
pppoe gateway routing problems jvannucci Linux - Networking 2 06-26-2003 06:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 05:12 PM.

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