LinuxQuestions.org
Review your favorite Linux distribution.
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 12-25-2008, 04:15 PM   #1
theinfidel
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:
Code:
# ENVIRONMENT
# Private interface
IF_PRV=eth1
IP_PRV=xxx.xxx.xxx.xxx
NET_PRV=xxx.xxx.xxx.xxx/24

# Public Interface
IF_PUB=eth0
IP_PUB=xxx.xxx.xxx.xxx
NET_PUB=xxx.xxx.xxx.xxx/24
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:
Quote:
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
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Code:
... -j SNAT --to $IP_PUB
You can use this instead:
Code:
... -j MASQUERADE
An alternative is to parse the dhcp client database (e.g. /var/lib/dhclient/dhclient-eth0.lease) for the assigned IP address,
and to use SNAT.
 
Old 12-26-2008, 11:47 AM   #3
theinfidel
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!
 
  


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
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


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