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 12-25-2008, 04:15 PM   #1
LQ Newbie
Registered: Aug 2007
Posts: 19

Rep: Reputation: 0
iptables script - How can I define a dynamic IPaddress

Hi, all

in my iptables script I define the environment like this:
# Private interface

# Public Interface
My question is, if I give the IF_PUB interface the DYNAMIC IPaddress assigned by my ISP how can I define it in IP_PUB and also the NET_PUB so I can then use it for the firewall rules.

exemple rule:
iptables -t nat -A POSTROUTING -s $NET_PRV -o $IF_PUB -j SNAT --to $IP_PUB
thanks you for any help
Old 12-25-2008, 05:44 PM   #2
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
... -j SNAT --to $IP_PUB
You can use this instead:
An alternative is to parse the dhcp client database (e.g. /var/lib/dhclient/ for the assigned IP address,
and to use SNAT.
Old 12-26-2008, 11:47 AM   #3
LQ Newbie
Registered: Aug 2007
Posts: 19

Original Poster
Rep: Reputation: 0
I guess what I am trying to figure out is how to UPDATE THE IPADDRESS in the iptables script, AUTOMATICALY.
Parsing dhcp.leases is ok as a way to get the address.
Probably complicated ?

Does anyone know if I can call it (the address) from the iptables script or maybe have dhclient write it there.

Thanks a bunch!


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
script to mail ipaddress aeby Linux - Networking 1 05-07-2007 08:47 AM
PTR records on dynamic ipaddress coolb Linux - Networking 8 12-21-2006 03:10 AM
Is there any way in iptables to find ipaddress of a interface while firing iptable ru gopalgurus Linux - Networking 1 06-19-2006 07:40 AM
iptables script sets wrong dynamic IP gundelgauk Linux - Security 5 09-08-2003 08:42 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 11:14 AM.

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
Open Source Consulting | Domain Registration