LinuxQuestions.org
Help answer threads with 0 replies.
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 03-07-2012, 03:22 PM   #1
serendipity77
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
Question IPTABLES (drop) dmz, lan, firewall NOT WORKING


Hello, these are my first steps setting up iptables, and i've done this script however it does not seem to work.

I have 1 firewall, 1 dmz and 1 lan.

Firewall:
Lan Iface (192.168.0.1)
Dmz Iface (172.16.0.1)
Internet Iface (i called it swan_iface) (192.168.1.134)

the ips of the computer interfaces are:
lan pc: 192.168.0.55
dmz pc: 172.16.0.11

I need the lan to have access to internet through the firewall.
The dmz should not be able to acess the lan unless it's a known connection
Internet must reach the DMZ
Internet must reach the lan in case of known connection.
Lan can access the DMZ
DMZ cannot access LAN


This is my iptable, comments on it are appreciated.

#declaring variables
swan_iface="eth1"
lan_iface="eth2"
dmz_iface="eth3"

dmz="172.16.0.11"
lan="192.168.1.0"

#resetting iptables

iptables -F
iptables -X
iptables -Z
iptables -t nat -F

#Default drop policy

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#Forwarding on

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


#Lan users can access internet, internet will only access lan if it is a known connection


iptables -A FORWARD -s $lan -p tcp --dport 80 -o $swan_iface -j ACCEPT
iptables -A FORWARD -i $swan_iface -d $lan -p tcp --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -s $lan -p udp --dport 53 -o $swan_iface -j ACCEPT
iptables -A FORWARD -i $swan_iface -d $lan -p udp --sport 53 -j ACCEPT

iptables -A FORWARD -s $lan -p tcp --dport 443 -o $swan_iface -j ACCEPT
iptables -A FORWARD -i $swan_iface -d $lan -p tcp --sport 443 -m state --state ESTABLISHED,RELATED -j ACCEPT

#Lan can access DMZ

iptables -t nat -A PREROUTING -i $swan_iface -p udp --dport 53 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 80 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 443 -j DNAT --to $dmz


#DMZ cannot access the lan unless it is a known connection

iptables -A FORWARD -i $dmz_iface -d $lan -p udp --sport 53 -j ACCEPT
iptables -A FORWARD -i $dmz_iface -d $lan -p tcp --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $dmz_iface -d $lan -p tcp --sport 443 -m state --state ESTABLISHED,RELATED -j ACCEPT

#internet can access the DMZ (http, ftp and dns)

iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 80 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p udp --dport 53 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 20:21 -j DNAT --to $dmz

#DMZ can access internet http, ftp, dns

iptables -A FORWARD -s $dmz -p tcp --sport 80 -o $swan_iface -j ACCEPT
iptables -A FORWARD -s $dmz -p udp --sport 53 -o $swan_iface -j ACCEPT
iptables -A FORWARD -s $dmz -p tcp --sport 20:21 -o $swan_iface -j ACCEPT


Any clues on what am i doing wrong???? Coz nothing works at all LOL
 
Old 03-08-2012, 10:06 AM   #2
amilo
Member
 
Registered: Oct 2011
Location: Nederland
Distribution: Debian, Centos, Ubuntu
Posts: 81

Rep: Reputation: Disabled
Read this

 
Old 06-23-2013, 09:09 AM   #3
redbrigade
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Rep: Reputation: 0
Also it doesnt look like you are not tagging any connections with NEW. So ESTABLISHED and RELATED rules wont be applied to anything.
 
Old 06-23-2013, 10:40 AM   #4
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
You have defined

Code:
Lan Iface (192.168.0.1)
and

Code:
lan="192.168.1.0"
Your lan interface IP is 192.168.0.1

So when you define "-d $lan" So no rule match . And default policy is denied as a result firewall drops packet

So you can try to change lan=192.168.0.1 NOT lan=192.168.1.0

Last edited by KinnowGrower; 06-23-2013 at 02:01 PM.
 
Old 06-23-2013, 10:43 AM   #5
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
And also when you define

lan="192.168.0.1" define mask as well

lan="192.168.0.1/24"
dmz="172.16.0.11/24"

replace 24 with correct netmask

Hope it helps
 
Old 06-23-2013, 10:58 AM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,349

Rep: Reputation: Disabled
Quote:
Originally Posted by serendipity77 View Post
This is my iptable, comments on it are appreciated.

#declaring variables
swan_iface="eth1"
lan_iface="eth2"
dmz_iface="eth3"

dmz="172.16.0.11"
lan="192.168.1.0"
The "dmz" variable contains a single IP address in the DMZ network, while the "lan" variable contains the network address of the LAN network.

Suggestion: Have both variables contain the network address and network size in CIDR format ("192.168.1.0/24" for the LAN network). Add separate variables for any specific hosts you will be referencing in your script, with descriptive names (like $dmz_ftp_server).
Quote:
Originally Posted by serendipity77 View Post
#Lan users can access internet, internet will only access lan if it is a known connection


iptables -A FORWARD -s $lan -p tcp --dport 80 -o $swan_iface -j ACCEPT
iptables -A FORWARD -i $swan_iface -d $lan -p tcp --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
This may or may not work, depending on how the iptables command interprets "192.168.1.0". My guess is it will consider it a single IP, and as a result the rule will not work. Modifying the "lan" variable as outlined above should fix that.

Suggestion: How about moving the rule permitting ESTABLISHED and RELATED traffic to a separate section at the top? Is there any interface for which you don't want to allow such traffic?

Quote:
Originally Posted by serendipity77 View Post
iptables -A FORWARD -i $swan_iface -d $lan -p udp --sport 53 -j ACCEPT
The above rule is superfluous, as DNS replies are covered by the rule permitting established/related traffic. (If the rule was not intended to cover DNS replies, it won't work anyway since the LAN network is NATed.)

Quote:
Originally Posted by serendipity77 View Post
#Lan can access DMZ

iptables -t nat -A PREROUTING -i $swan_iface -p udp --dport 53 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 80 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 443 -j DNAT --to $dmz
The heading doesn't match the rules at all; you're port forwarding traffic from the WAN interface to the DMZ network. Anyway, the last two won't work, as you're missing rules in the FORWARD chain for TCP ports 80 and 443.

Suggestion: Put all rules regarding port forwarding in a section by themselves, with the FORWARD rule in the filter chain immediately after the PREROUTING rule in the nat chain. That way it's very obvious that the two rules are related.

Quote:
Originally Posted by serendipity77 View Post
#DMZ cannot access the lan unless it is a known connection

iptables -A FORWARD -i $dmz_iface -d $lan -p udp --sport 53 -j ACCEPT
iptables -A FORWARD -i $dmz_iface -d $lan -p tcp --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $dmz_iface -d $lan -p tcp --sport 443 -m state --state ESTABLISHED,RELATED -j ACCEPT
Apart from the misleading heading, all these rules could be replaced by a general rule covering ESTABLISHED and RELATED traffic.

Quote:
Originally Posted by serendipity77 View Post
#internet can access the DMZ (http, ftp and dns)

iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 80 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p udp --dport 53 -j DNAT --to $dmz
iptables -t nat -A PREROUTING -i $swan_iface -p tcp --dport 20:21 -j DNAT --to $dmz
You already did this. Besides, these are not access rules as the heading indicates, but NAT rules.

Also, you don't need to include port 20 for FTP traffic. The netfilter FTP ALG module handles that automatically.

Quote:
Originally Posted by serendipity77 View Post
#DMZ can access internet http, ftp, dns
iptables -A FORWARD -s $dmz -p tcp --sport 80 -o $swan_iface -j ACCEPT
iptables -A FORWARD -s $dmz -p udp --sport 53 -o $swan_iface -j ACCEPT
iptables -A FORWARD -s $dmz -p tcp --sport 20:21 -o $swan_iface -j ACCEPT
This looks OK, but you seem to be missing a rule to perform source NAT (overloading) for traffic exiting $swan_iface
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Howto setup iptables firewall and DMZ with multiple public IP's ? hendrixx Linux - Networking 2 11-30-2008 08:03 AM
iptables: deny connections from dmz to lan t0bias Linux - Security 3 10-03-2007 07:56 AM
Drop connections to port 80 at firewall machine also drop at protected network? Niceman2005 Linux - Security 2 10-27-2005 08:21 AM
RH 9 Firewall/Router Iptables DMZ Dammas Linux - Software 0 03-30-2004 01:02 AM
IPTABLES - LAN can't get to DMZ with public IP dknell Linux - Security 4 02-28-2002 08:02 AM

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

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