LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 08-07-2006, 10:43 PM   #1
slazer
LQ Newbie
 
Registered: Oct 2005
Location: kuala lumpur, malaysia
Distribution: slackware, fedora
Posts: 26

Rep: Reputation: 15
linux box as a router...and iptables issue...


hi all,

my friend and i are planning to build a linux as our router to our home lan, basically the router will have two network interface card, eth0 connected to our internal lan hub, and the other interface (eth1)connected to our modem and straight to the internet.

so, we have installed slackware to the box, enable /proc/sys/net/ipv4/ip_forward=1, then add iptables rules like this:

iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE

so, right now our pc in the internal lan can access the internet.
but the problem come when i try to play with the iptables rules, i wanted to allow selected pc to be able to access the internet, first of all, i blocked all pc from accessing the internet like this:

iptables -A FORWARD -p all -j DROP

and all the user cannot access the internet, so it means that the rule is working, then, i put the rule like below to allow certain pc to access the internet:

iptables -A FORWARD -s 192.168.0.10 -j ACCEPT
iptables -A FORWARD -s 192.168.0.11 -j ACCEPT

but, unfortunately, the selected pc still cannot access the internet. What happened?? can you guys help me...


thanks in advance..

Last edited by slazer; 08-07-2006 at 10:45 PM.
 
Old 08-07-2006, 11:27 PM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
iptables rules are evaluated in order.

The rule:

Code:
iptables -A FORWARD -p all -j DROP
will match all packets pending forwarding... thus, all packets being forwarded will be dropped before the other two rules are ever reached:

Code:
iptables -A FORWARD -s 192.168.0.10 -j ACCEPT
iptables -A FORWARD -s 192.168.0.11 -j ACCEPT

Simply place that first rule last. Or, even better, just do:
Code:
iptables -P FORWARD DROP
Which will set the policy for the FORWARD chain to drop. When all rules within the FORWARD chain fail to match, iptables will drop the packet by default.

Last edited by zhangmaike; 08-07-2006 at 11:29 PM.
 
Old 08-07-2006, 11:46 PM   #3
slazer
LQ Newbie
 
Registered: Oct 2005
Location: kuala lumpur, malaysia
Distribution: slackware, fedora
Posts: 26

Original Poster
Rep: Reputation: 15
is iptables differ from pf??

because, from what i know, in pf, the last rule will overwrite the first rule, for example, we have to drop all packet first, then accept/allow packet base on our rules....

correct me if i'm wrong..
 
Old 08-08-2006, 12:14 AM   #4
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Your post is the first I have heard of pf, but based on your description, yes, iptables is different.

iptables rules are evaluated in order. The first rule that matches causes iptables to jump to its target (specified with -j) and, depending on the target, iptables will either: stop evaluating (this happens with terminating targets such as DROP) or continue with the next rule (this happens with non-terminating targets). It is also possible to jump to a user-defined chain (where, of course, evaluation of those rules will continue). If all the rules within a chain are evaluated and the end is reached without any rule matching, than iptables defaults to the specified policy for that chain.

Behavior similar to that which you have experienced in pf could be accomplished simply through omitting your first rule, and instead setting the policy of the FORWARD chain to DROP.

See man iptables for more information.

Last edited by zhangmaike; 08-08-2006 at 12:21 AM.
 
  


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
Linux box as a router - config issue dooda5555 Linux - Networking 4 05-19-2005 04:08 AM
Using Linux Box as a Router wasabi Linux - Networking 5 09-04-2003 05:08 PM
Linux box as a router dumpa Linux - Newbie 8 08-08-2003 04:05 PM
Linux box as router AkumaLoka Linux - Networking 3 10-14-2002 04:57 PM
Linux box as router Kapone Linux - Networking 5 07-04-2001 06:50 AM

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

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