Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-03-2013, 04:16 PM
|
#1
|
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Rep:
|
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!!
|
|
|
04-03-2013, 05:19 PM
|
#2
|
Senior Member
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,694
|
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
|
|
|
04-03-2013, 05:38 PM
|
#3
|
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
|
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
|
|
|
04-03-2013, 06:14 PM
|
#4
|
Member
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347
Rep:
|
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.
|
04-04-2013, 05:53 AM
|
#5
|
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
|
Thanks, now I get it!
|
|
|
All times are GMT -5. The time now is 08:27 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|