LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-03-2013, 04:16 PM   #1
Annielover
Member
 
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90

Rep: Reputation: 8
IPTABLES: question about forwarding rules


Hi all,

First of all: this is my network layout:

internal network (192.168.100.0) --> (eth1) firewall (eth0) --> internet

Consider this script:
Code:
#!/bin/bash
#
###################
# FIREWALL SCRIPT #
###################

# Flush existing rules
iptables -F
iptables -t nat -F
iptables -t mangle -F

# Set default policy
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

# Allow all SSH traffic on all interfaces
iptables -A INPUT -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# Configure NAT
# eth0 is the public (internet) network interface
# eth1 is the private network interface
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.100.0/24 -d 0/0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED, ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state NEW, ESTABLISHED, RELATED -j ACCEPT

# Block all other traffic
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP
iptables -A OUTPUT -j DROP
As you can see I'm forwarding all traffic between the two interfaces.
With these firewall rules, will my internal clients be able to access the internet?

Or do I have to add following rules?
Code:
# Allow WWW access
iptables -A INPUT -p tcp --dport 80 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

# Allow sWWW access
iptables -A INPUT -p tcp --dport 443 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
I'm a little confused about that and I'm unable to test 'cause currently I'm at an external location...

Thank you very much!!
 
Old 04-03-2013, 05:19 PM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,694
Blog Entries: 33

Rep: Reputation: 290Reputation: 290Reputation: 290
Hi, you may need this line, net/ipv4/ip_forward = 1
Code:
#---------------------------------------------------------------
# Enable IP routing. Required if your firewall is protecting a
# network, NAT included
#---------------------------------------------------------------

net/ipv4/ip_forward = 1

net.ipv4.icmp_ignore_bogus_error_responses=1
in /etc/sysctl.conf
 
Old 04-03-2013, 05:38 PM   #3
Annielover
Member
 
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90

Original Poster
Rep: Reputation: 8
Hi,

I already set up "ip_forward=1"

I'm just wondering if I have to add those rules in addition to the FORWARD rules:
Am I correct that iptables forwards all traffic coming from eth1 to eth0 or do I need to tell iptables what type of traffic is allowed to be forwarded?
Code:
# Allow WWW access
iptables -A INPUT -p tcp --dport 80 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

# Allow sWWW access
iptables -A INPUT -p tcp --dport 443 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
 
Old 04-03-2013, 06:14 PM   #4
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
Quote:
Or do I have to add following rules?
Code:

# Allow WWW access
iptables -A INPUT -p tcp --dport 80 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

# Allow sWWW access
iptables -A INPUT -p tcp --dport 443 -m state --state NEW, ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

I'm a little confused about that and I'm unable to test 'cause currently I'm at an external location...
INPUT chain contains the rules that allow or deny only the traffic destined for firewall it self. Means server running firewall. In your case you want to allow to FORWARD traffic so you dont need this

OUTPUT chain contains the rules that allow or deny the traffic that is generated, itself from the firewall. Means from the server running firewall. Even in this case you want allow traffic from network behind the firewall server. You dont need it.
 
1 members found this post helpful.
Old 04-04-2013, 05:53 AM   #5
Annielover
Member
 
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90

Original Poster
Rep: Reputation: 8
Thanks, now I get it!
 
  


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
IPTables Port forwarding rules works only for some hosts BushNik Linux - Networking 2 11-19-2012 04:37 PM
iptables rules to limit nat forwarding sleepylight Linux - Security 1 07-19-2012 06:06 PM
IPTables Rules Question dman777 Linux - Networking 5 04-12-2011 12:16 AM
Iptables rules on pppoe connection. Need help forwarding / routing. Repgahroll Linux - Networking 1 09-23-2010 11:57 AM
Question about iptables rules huanvnn Linux - Security 4 06-02-2006 09:05 PM

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

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