Networking Forums

Networking Forums > Computer Networking > Linux Networking > IPTables port forwarding with dynamic ip address

Reply
Thread Tools Display Modes

IPTables port forwarding with dynamic ip address

 
 
David
Guest
Posts: n/a

 
      06-06-2007, 09:05 AM
Hi all,

I have the following rule used to port forward a port to an internal
host:

WAN = eth<X>

EXTERNALIP = <HARD CODED VALUE IN SCRIPT >

iptables -t -nat -A PREROUTING -p tcp -i ${WAN} -d ${EXTERNALIP} --
dport 8022 -j DNAT --to 192.168.1.X:<PORT>

If i miss out the -d ${EXTERNALIP} argument i cannot get the rule to
work. Unfortunately, the internface eth<X> is assigned a dynamic IP
address at random intervals. I am currently using dhcp to control the
interface.

Obviously when the IP changes, the ${EXTERNALIP} argument is
incorrect. Could anyone recommend, a way that i may be able to tie
this to the interface rather than the ip address. All my attempts have
failed, and im sure this could probably be done?

Any ideas, thanks in advance again for all your help.

David

 
Reply With Quote
 
 
 
 
Robert Harris
Guest
Posts: n/a

 
      06-06-2007, 10:28 AM
David wrote:
> Hi all,
>
> I have the following rule used to port forward a port to an internal
> host:
>
> WAN = eth<X>
>
> EXTERNALIP = <HARD CODED VALUE IN SCRIPT >
>
> iptables -t -nat -A PREROUTING -p tcp -i ${WAN} -d ${EXTERNALIP} --
> dport 8022 -j DNAT --to 192.168.1.X:<PORT>
>
> If i miss out the -d ${EXTERNALIP} argument i cannot get the rule to
> work. Unfortunately, the internface eth<X> is assigned a dynamic IP
> address at random intervals. I am currently using dhcp to control the
> interface.
>
> Obviously when the IP changes, the ${EXTERNALIP} argument is
> incorrect. Could anyone recommend, a way that i may be able to tie
> this to the interface rather than the ip address. All my attempts have
> failed, and im sure this could probably be done?
>
> Any ideas, thanks in advance again for all your help.
>
> David
>

You need to run your rule when the IP address is assigned. In my
distribution (Debian), that means putting a little script in the directory:

/etc/dhcp3/dhclient-exit-hooks.d

where the variable $new_ip_address will contain the new IP address.
Details are in "man dhclient-script". No doubt your distribution has
some similar arrangement.

Robert
 
Reply With Quote
 
David
Guest
Posts: n/a

 
      06-06-2007, 11:47 AM
On 6 Jun, 11:28, Robert Harris <robert.f.har...@blueyonder.co.uk>
wrote:
> David wrote:
> > Hi all,

>
> > I have the following rule used to port forward a port to an internal
> > host:

>
> > WAN = eth<X>

>
> > EXTERNALIP = <HARD CODED VALUE IN SCRIPT >

>
> > iptables -t -nat -A PREROUTING -p tcp -i ${WAN} -d ${EXTERNALIP} --
> > dport 8022 -j DNAT --to 192.168.1.X:<PORT>

>
> > If i miss out the -d ${EXTERNALIP} argument i cannot get the rule to
> > work. Unfortunately, the internface eth<X> is assigned a dynamic IP
> > address at random intervals. I am currently using dhcp to control the
> > interface.

>
> > Obviously when the IP changes, the ${EXTERNALIP} argument is
> > incorrect. Could anyone recommend, a way that i may be able to tie
> > this to the interface rather than the ip address. All my attempts have
> > failed, and im sure this could probably be done?

>
> > Any ideas, thanks in advance again for all your help.

>
> > David

>
> You need to run your rule when the IP address is assigned. In my
> distribution (Debian), that means putting a little script in the directory:
>
> /etc/dhcp3/dhclient-exit-hooks.d
>
> where the variable $new_ip_address will contain the new IP address.
> Details are in "man dhclient-script". No doubt your distribution has
> some similar arrangement.
>
> Robert- Hide quoted text -
>
> - Show quoted text -


Hi, just wanted to say thanks. That is definately what im looking
for.

Thanks for the help

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IPTables port forwarding Miguel Sanders Linux Networking 1 10-11-2007 12:19 PM
ssh dynamic port forwarding: works but getting connection errors Anthropic Aorta Linux Networking 0 10-30-2005 02:33 PM
iptables port forwarding Jason Lee Linux Networking 4 10-13-2003 12:53 AM
port forwarding with iptables Allan Bruce Linux Networking 9 09-24-2003 04:31 PM
Port Forwarding with iptables Allan Bruce Linux Networking 0 08-27-2003 11:44 AM



1 2 3 4 5 6 7 8 9 10 11