LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 07-11-2010, 07:56 PM   #1
n7okn
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Rep: Reputation: 0
IPTables line syntax needed for embedded DD-WRT


I'm using a DD-WRT linux embedded router and I need an IPTables line to put into the command section. I get awlully confused with IP tables, and I'm told that the syntax is no different than what comes with the Linux kernel. What I need to do is to block all outgoing TCP port 53 traffic except to IP address 208.67.222.123 and 208.67.220.123. Can someone please show me what the syntax looks like?
 
Old 07-12-2010, 04:12 PM   #2
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by n7okn View Post
... I get awlully confused with IP tables, and I'm told that the syntax is no different than what comes with the Linux kernel.
Well, iptables syntax ought to be iptables syntax, ot it wouldn't be iptables.

Now, if you don't mind, I'll go down the 'teach a man to fish' route. The documentation is to be found at frozentux - download the pdf, you'll probably want to look at it several times.

Quote:
What I need to do is to block all outgoing TCP port 53 traffic except to IP address 208.67.222.123 and 208.67.220.123.
Well, there are several ways that you could do this, depending on how it fits into the other stuff going on, and how heavy the workload is.

(Warning, pseudocode alert!)

You could just put in a sequence like:
Code:
'if it is port 53, and ip_1 then let it pass'
'if it is port 53, and ip_2 then let it pass'
'if it is port 53, drop'
OTOH, I think that I would prefer
Code:
'if it is port 53, jump to p53_chain'

p53_chain
if dest = ip_1, then let it pass
if dest = ip_2, then let it pass
drop
(I'm anticpating, maybe incorrectly, mostly traffic not to port 53, and in the second approach the rest of the traffic goes through fewer conditional tests. Maybe this is irrelevant, but if you are really interested, you can do testing.)

Last edited by salasi; 07-12-2010 at 04:14 PM.
 
Old 07-13-2010, 10:12 AM   #3
n7okn
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
wow...

OK well I never had someone explain it to me that way before. That's brilliant. I've always asked "What the heck is an IP chain and what does it mean in IP tables." I use webmin and have tried to make heads or tails out of that and still come up short. I will try that and see how it goes.

Quote:
Originally Posted by salasi View Post
Well, iptables syntax ought to be iptables syntax, ot it wouldn't be iptables.

Now, if you don't mind, I'll go down the 'teach a man to fish' route. The documentation is to be found at frozentux - download the pdf, you'll probably want to look at it several times.



Well, there are several ways that you could do this, depending on how it fits into the other stuff going on, and how heavy the workload is.

(Warning, pseudocode alert!)

You could just put in a sequence like:
Code:
'if it is port 53, and ip_1 then let it pass'
'if it is port 53, and ip_2 then let it pass'
'if it is port 53, drop'
OTOH, I think that I would prefer
Code:
'if it is port 53, jump to p53_chain'

p53_chain
if dest = ip_1, then let it pass
if dest = ip_2, then let it pass
drop
(I'm anticpating, maybe incorrectly, mostly traffic not to port 53, and in the second approach the rest of the traffic goes through fewer conditional tests. Maybe this is irrelevant, but if you are really interested, you can do testing.)
 
Old 07-13-2010, 05:48 PM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by n7okn View Post
I've always asked "What the heck is an IP chain and what does it mean in IP tables." I use webmin...
Sorry, I don't know how much easier (or the exact opposite of easier) Webmin makes things, never having tried it for firewalling, but...

Most of the easy-gui things make simple cases rather easy to deal with, at the expense of getting in the way of you learning what is really going on underneath. Technically, this is called making the learning curve shallower and it isn't always helpful.

Iptables is a simple programming language for building a firewall, and it is genuinely simple. It is easy to learn. But, to put the knowledge to some use, without being a danger to yourself, you do have to have some basic appreciation of networking and an ability to work out which packets are going where and an ability to plan out what you want to happen.

This is also easy; I think if you want to impress people, you have to be able to do this in your head, but there should be no objection to you working it out on a flowchart, if you want to - just don't tell anyone else that this is what you did!

Now the doc at frozentux; it is quite long, quite comprehensive, but you don't need to read all of it, by any means. I think you may only have to read the part about the one or two specific instructions that you need, but you may also want to skim through the introduction/basic part, too. (Chapters 1, 3 and the start of ch 11...ch 6, if you are still in any doubt about traversing tables and chains...you may want to look at 'how a rule is built in ch 9, but the answer to the specific question that you started off by asking is in ch 10).

(One piece of advice; don't treat modules like an 'all you can eat buffet' and try to get as many on your plate as possible; certainly, to start, the fewer you need the better as some are big and complex, and it is easy to slow the whole thing down by using everything that has a fun feature.)
 
Old 07-13-2010, 08:29 PM   #5
n7okn
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by salasi View Post
Sorry, I don't know how much easier (or the exact opposite of easier) Webmin makes things, never having tried it for firewalling, but...

Most of the easy-gui things make simple cases rather easy to deal with, at the expense of getting in the way of you learning what is really going on underneath. Technically, this is called making the learning curve shallower and it isn't always helpful.

Iptables is a simple programming language for building a firewall, and it is genuinely simple. It is easy to learn. But, to put the knowledge to some use, without being a danger to yourself, you do have to have some basic appreciation of networking and an ability to work out which packets are going where and an ability to plan out what you want to happen.

This is also easy; I think if you want to impress people, you have to be able to do this in your head, but there should be no objection to you working it out on a flowchart, if you want to - just don't tell anyone else that this is what you did!

Now the doc at frozentux; it is quite long, quite comprehensive, but you don't need to read all of it, by any means. I think you may only have to read the part about the one or two specific instructions that you need, but you may also want to skim through the introduction/basic part, too. (Chapters 1, 3 and the start of ch 11...ch 6, if you are still in any doubt about traversing tables and chains...you may want to look at 'how a rule is built in ch 9, but the answer to the specific question that you started off by asking is in ch 10).

(One piece of advice; don't treat modules like an 'all you can eat buffet' and try to get as many on your plate as possible; certainly, to start, the fewer you need the better as some are big and complex, and it is easy to slow the whole thing down by using everything that has a fun feature.)
OK Thanks for that. I also had posted the same query in the dd-wrt forum, and someone had exact syntax for me and with some head scratching, got it to work perfectly. Thanks you so much for your friendly help. I will take a look at the manual.
 
  


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
iptables DD-WRT nazihhaddad Linux - Networking 1 05-19-2010 11:16 AM
Command line syntax Steve36810 Linux - Newbie 2 02-24-2009 02:29 PM
Help with sh script syntax needed ! MikeAtVillage Programming 4 03-31-2006 02:39 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM
iptables syntax Ge64 Linux - Security 3 08-20-2003 10:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

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