LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 06-19-2006, 03:45 AM   #1
gopalgurus
LQ Newbie
 
Registered: Jun 2006
Posts: 1

Rep: Reputation: 0
Question Is there any way in iptables to find ipaddress of a interface while firing iptable ru


I want to add an iptable rule in the INPUT chain of
filter table.

The rule is like

iptables -t filter -A INPUT sport 123 dport 321 srcip 1.1.11.1 destip ???

Here i want that the destination ip should be the ip of the
interface on which the packet arrived .

How do i find the ipaddress of the interface using iptables.

I actually want the rule to become independent of the
interface address so that even if the interface's ip address
change i don't have to change the rule .

The rule itself should be such that it will take the current
interface address.
 
Old 06-19-2006, 06:40 AM   #2
Notwerk
Member
 
Registered: Apr 2005
Location: Jordan
Distribution: Debian (Sarge), Ubuntu (6.06)
Posts: 271

Rep: Reputation: 30
Check out the -i and -o parameters for iptables.
Code:
$man iptables
If this doesn't do what you want then here's a few hints on how to go about it. I'm not at a linux machine so plz double check syntax/paths for errors

1) Write a script that flushes your iptables then sets all the rules. In this script don't use the IP addresse, but instead use a variable to describe it (e.g. $INT_IP).

2) At the beginning of the script initialize $INT_IP to be the device's IP address:
Code:
INT_IP=`ifconfig -a | grep -A 1 eth[x] | grep inet | awk -F: '{print $2}'`
3) Finally, hack the script that brings the ethernet device to "up" state to run your new script before it's done. Should be smoewhere inside /etc/sysconfig/network-script/ if i remember right

Happy Hunting
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to find ipaddress of the other system when we r chatting.. ramabrahmam Linux - Networking 1 04-29-2006 09:50 AM
iptable dnat to lo interface - is it possible? idg Linux - Security 1 06-20-2005 07:00 AM
looking for graphical Interface pour iptable gcossiaux Linux - Software 1 02-12-2004 10:13 AM
ipaddress syntax - iptables arobinson74 Linux - Networking 3 03-31-2003 12:34 PM


All times are GMT -5. The time now is 04:03 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration