LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-05-2004, 10:05 PM   #1
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Rep: Reputation: 0
Firewall Behind a Linksys Router


Hello ppl, I would like to ask for help in configuring my iptables firewall. Any help would be appreciated.

Here is the setup.

I have a Linksys router that can share internet connection in my house and I have a dsl line with a dynamic ipaddress. They say that the Router has a firewall capability but i want to make a linux firewall, cuz i know that it is bettter.

I would like to put my firewall between the router and my network to ensure security.

I have read some faqs, docu's and howto's of iptables and came up with this script, pls tell me if there are things i need to change because I cant browse the internet on the firewall.

I havent put the local network connection to connect because i want to test the firewall first by itself.

My router's ip address is 192.168.1.1

#!/bin/bash

# - Interface eth0 is the internet interface

# Initialize all the chains

iptables --flush
iptables -t nat --flush
iptables -t mangle --flush

iptables --delete-chain
iptables -t nat --delete-chain
iptables -t mangle --delete-chain

# If a packet doesn't match one of the built in chains, then Drop it

iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables --policy FORWARD DROP

#allow loopback traffic

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT


# Allow outbound DNS queries from the FW and the replies too

iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 \
-j ACCEPT

iptables -A INPUT -p udp -i eth0 --sport 53 --dport 1024:65535 \
-j ACCEPT


# Allow port 80 (www) and 443 (https) connections to the firewall
# I want to surf on the firewall for testing purposes

iptables -A OUTPUT -j ACCEPT -m state --state NEW \
-o eth0 -p tcp -m multiport --dport 80,443 --sport 1024:65535

iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED \
-i eth0 -p tcp

I would like to resolve the fact that i cant browse on the firewall using these setting.
 
Old 08-05-2004, 10:24 PM   #2
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
I think you need an ESTABLISHED,RELATED rule for the OUTPUT chain as well. Otherwise only the first packet will be allowed out and nothing else.
 
Old 08-05-2004, 10:26 PM   #3
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
is this it?

iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED \
-i eth0 -p tcp
 
Old 08-05-2004, 10:27 PM   #4
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
btw, depending on what linksys model you are using, it might be a linux firewall as well:

http://www.linksys.com/support/gpl.asp
 
Old 08-05-2004, 10:29 PM   #5
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
To allow others use internet from behind your linux router, you would need to add a MASQUERADE rule. As you have successfully built a firewall script with some reading, I would leave the onus on you to do some more reading to get the MASQUERADE in place.

You would also need to enable ip forwarding .. in one of the following ways

edit /etc/sysctl.conf and add/modify the following parameter

net.ipv4.ip_forward=1

OR

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

Last edited by ppuru; 08-05-2004 at 10:31 PM.
 
Old 08-05-2004, 10:29 PM   #6
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Re: is this it?

Quote:
Originally posted by toffe0202
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED \
-i eth0 -p tcp
I believe that's the same one you had before, right? I think what you looking for is:

iptables -A OUTPUT -j ACCEPT -m state --state ESTABLISHED,RELATED \
-i eth0 -p tcp
 
Old 08-05-2004, 10:30 PM   #7
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
yes i forgot the model but it also has firewall capabilities that i can turn off.
from the script do you think that there is something wrong in it? btw thanks for the reply.
 
Old 08-05-2004, 10:33 PM   #8
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
mr. ppuru, i have read ip masqurading, and i still have no plans in touching it because of the firewall no been able to surf the web. Thanks anyway.
 
Old 08-05-2004, 10:34 PM   #9
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Quote:
Originally posted by toffe0202
from the script do you think that there is something wrong in it? btw thanks for the reply.
Yes, it certainly doesn't work. Try adding the iptables line from my previous post. Btw, welcome to linuxquestions.org!
 
Old 08-05-2004, 10:37 PM   #10
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Smile

Thank Capt_Caveman, and i'm proud of being a member.
 
Old 08-05-2004, 11:15 PM   #11
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
toffe0202, just a doubt .. perhaps you need to enable MASQUERADING on the LinkSys router to allow 192.168 traffic on the internet.
 
Old 08-06-2004, 01:00 AM   #12
nex6
Member
 
Registered: Apr 2004
Distribution: Ubuntu;Debain;Redhat
Posts: 46

Rep: Reputation: 16
Firewalling a box behind a firewall is a good idea, but puting a firewall/router and having it NAT the LAN behind it is not so good. that comes under NAT'ing a NAT which is not a good practice.

You will have less network problems if you leave the Linksys up and firewall each box themselfs.


just my 2 cents.


-Nex6
 
Old 08-06-2004, 02:56 AM   #13
toffe0202
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Original Poster
Rep: Reputation: 0
I have solved the WWW problem by doing this

# Allow www outbound to 80.
iptables -A INPUT -i eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# Allow www outbound to 443.
iptables -A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT

I can now surf provided that i know the ipaddress of the site that i'm goin to surf.

I know that its a DNS problem, and i added logging at the end of my script to solve it but when i booted up again in CLI, the monitor is clogged up by logs continously and i cant see the shell. Is there a way to turn the logging from reflecting on my monitor so i can just look at the logs at /var/log like other normal linux users do?
 
Old 08-06-2004, 04:11 PM   #14
nex6
Member
 
Registered: Apr 2004
Distribution: Ubuntu;Debain;Redhat
Posts: 46

Rep: Reputation: 16
Try, hard coding the DNS servers, instead of DHCP.

and sure port 53 TCP and UDP has outbound access.


-Nex6
 
  


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
Small Linux Router/firewall behind D-Link Hardware router dleidlein Linux - Networking 6 04-30-2007 05:12 AM
Need Help W/ Linksys Router Please cmd Linux - Wireless Networking 1 02-21-2004 11:46 PM
VPN with Linksys BEFsx41 Firewall Router mobassir Linux - Networking 0 01-02-2004 08:18 AM
Mandrake Firewall/router networked to US Robotics 8000A router jrzplace Linux - Networking 0 11-17-2003 04:48 PM
router problem with linksys router scheiße_comp Linux - Networking 10 08-20-2002 10:18 AM

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

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