LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-14-2012, 11:38 AM   #1
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Problem understanding IPtables "-d" param


Since IPTables is always used to eg. block stuff TO the machine it's being run on, what is the "destination" parameter for? When that machine is being used as a router or something?


Thanks.
 
Old 04-14-2012, 09:44 PM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
Since IPTables is always used to eg. block stuff TO the machine it's being run on
Not so, iptables is used to manipulate/filter packets passing through the kernel tcp/ip stack. These packets can travel in any direction:
Packets that are destined FOR the iptables host (INPUT),
Packets generated BY the iptables host (OUTPUT)
Packets passing THROUGH the iptables host as it is being routed (FORWARD).

The --destination (-d) option allows you to match packets by the address they are destined for, rather than the address they are coming from. -d rules would appear more often in FORWARD rules (routed traffic) than they would in INPUT/OUTPUT rules.

Say you have iptables running on a router in a school, on one subnet you have a LAN with student, teacher, and admin machines, on another subnet you have a DMZ with some servers, and then you have a WAN connection to the internet.:
Code:
iptables -A FORWARD -i $lan_if -o $dmz_if -s $admin_ip -d $server_subnet -p tcp --dport 22 -j ACCEPT
Assuming a default policy that will drop unmatched packets. This rule will allow packets from the administrator IP address in $admin_ip destined for the DMZ subnet on SSH port 22.

Iptables is designed to be able to match packets by pretty much any conceivable pattern, so it is completely valid to include -d options in any appropriate rule, whether its necessary or not. In my example above, the -i, and -o options could be omitted. Or alternatively, the -d and -i could be omitted (of course that's unverified since this a hypothetical example).
 
Old 04-15-2012, 11:24 AM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
Thanks so much for your reply. So I was right, this would be used in a router situation....?

I'm still trying to get clear exactly what a "subnet" is - is it 2 networks separated by a router? (before the mods jump on me for not Googling.. )
 
Old 04-16-2012, 02:47 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
So I was right, this would be used in a router situation....?
It COULD be, it is a another way for iptables to match packets against rules, the matches can be attributed to any rule (with maybe a few exceptions). As I look through my rules, the only -d matches are for rules related to routed packets.
Another example may be a single host (VPS maybe), with multiple IP addresses.

Quote:
I'm still trying to get clear exactly what a "subnet" is - is it 2 networks separated by a router?
As Einstein said, "If you can't explain it simply, you don't understand it well enough". So I wont confuse you by adding what is missing from my understanding to your learning curve. But you do need a router to traverse different subnets. That router, has an IP address on each subnet, and the kernel (in the case of Linux), routes the traffic according to the rules set out in the routing tables.
 
Old 04-16-2012, 03:46 AM   #5
nikmit
Member
 
Registered: May 2011
Location: Nottingham, UK
Distribution: Debian
Posts: 178

Rep: Reputation: 34
Very nice answer, fukawi1. I kind of saw a challenge in it I could not resist How is this for a short explanation?

A subnet is a network inside which all devices have the same broadcast address.
This allows communication without the assistance of a router.

Example for 192.168.1.0/24:

192.168.1.0 - network name (the first IP in the network)
192.168.1.255 - network broadcast address (the last IP in the network)
192.168.1.1-254 - addresses available for network clients - computers, switches, routers etc.

Last edited by nikmit; 04-16-2012 at 03:58 AM. Reason: Didn't like my original ansi :p
 
  


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
git "philosophy" understanding problems - no central server? Squall90 Programming 3 08-19-2010 09:49 AM
IPTABLES: interface on "192.168.1.0/24" won't route clients from "10.65.0.0" zivota Linux - Networking 2 06-09-2008 01:35 PM
Iptables problem with "--dport" or "--sport" jmhal Slackware 5 07-03-2007 10:50 AM
problem with command "modprobe iptables" in the debian server rdr129 Linux - Networking 1 04-22-2006 08:49 AM
adsl+iptables+port forward+"-m tcp" strange problem icry0000 Linux - Networking 3 07-31-2005 09:31 PM

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

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