Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 06-19-2006, 04:45 AM   #1
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 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, 07:40 AM   #2
Registered: Apr 2005
Location: Jordan
Distribution: Debian (Sarge), Ubuntu (6.06)
Posts: 271

Rep: Reputation: 31
Check out the -i and -o parameters for iptables.
$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:
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


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 10:50 AM
iptable dnat to lo interface - is it possible? idg Linux - Security 1 06-20-2005 08:00 AM
looking for graphical Interface pour iptable gcossiaux Linux - Software 1 02-12-2004 11:13 AM
ipaddress syntax - iptables arobinson74 Linux - Networking 3 03-31-2003 01:34 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration