Port forwarding to dynamic IP

Is it possible to configure port to be forwarded to a dynamic IP address assigned by Omnia via DHCP? I would like to eliminate static DHCP leases and have port forwarding destination to be identified by hostname or MAC rather than static IP.

It doesn’t seem like a reasonable plan… so I’ll ask:

** What is the reason for this wish ?
** Why doesn’t the statics lease suit ?
** From where should it be forwarded to the individual station identified by MAC ?

1 Like

Why isn’t it reasonable? Computers exist to automate things. Why do I need to worry about assigning static IPs to hosts?

For the lasts question, I don’t understand what you’re asking. Port forwarding goes from WAN to LAN. Nothing changes in that regard.

Since I have no idea how complex and complicated your requirements are, I suggest the traditional way… fixed IP and simple port forwarding. I’m sure there are other, more complex solutions… reasonably more difficult.

Personally, I think assigning a static address is the easiest way to allow simple relationships for communication from the WAN to individual stations, and likewise “for example” backups from stations via FTP to NAS or whatever. For devices connected via WIFI, you’ll need to set a static MAC for each of them (the default is variable). Anything else will be more complicated

Now to the point : have you considered using www.zerotier.com or something similar ?

1 Like

To be honest, I don’t see how you go from my request to Zerotier. It’d be much easier to assign static leases (which is what I’m doing right now) than use Zerotier. Furthermore, it doesn’t address the general case of port forwarding where I need anyone on the Internet to be able to connect to my machine on the local network.

I think it is doable with a little bit of work by subscribing to the DHCP events.

At the beginning you announced the requirement of dynamic IPs plus dynamic forwards and opposed my recommendation of static IPs.

Citation from youre post: Why do I need to worry about assigning static IPs to hosts?

Somehow I don’t understand the whole discussion.

1 Like

To subscribe to the DHCP events you can create a shell script and add to the


You can check either by HOSTNAME or MACADDR.

Something like this(POZOR!!! this is just to give an idea, not tested, may not be even fully correct!!)


## use one of these either mac or hostname
if [ MACADDR != "your_mac" ]; then
	exit 0 #mac not matching, do nothing

## or

if [ HOSTNAME != "your_hostname" ]; then
	exit 0 #hostname not matching, do nothing

#this rule is just a sample but with current IPADDR, so update according to your needs
#important is the rule name we add by comment param to find it later, must be unique
rule_to_add="-A zone_lan_prerouting -m comment --comment 'YOUR_RULE' -p tcp -s x.x.x.x/ -d y.y.y.y/ -m tcp --dport 2222 -j DNAT --to-destination $IPADDR:22"

if iptables -t nat -S|grep -q 'YOUR_RULE'; then
	if iptables -t nat -S|grep -q 'YOUR_RULE' |grep -q '$IPADDR'; then
		exit 0 #rule exist with ip, do nothing
		rule_to_delete="$(iptables -S |grep 'YOUR_RULE' | sed -e 's/-A/-D/g')"
		iptables -t nat $rule_to_delete  # remove old rule
		iptables -t nat $rule_to_add  # add new rule
	iptables -t nat $rule_to_add  # add new rule

EDIT: updated.

1 Like

The dynamic IP is on internal network. The router knows exactly what it is. DNS already has a mapping from host name to that dynamic IP.

This looks like what I asked for, though in the meanwhile I’ve actually looked into UPnP. I’ll experiment with both and see what works best for me. Thanks.

Just updated the script, made more generic. So when you define your rule correctly it should work.

POZOR me dostalo :smiley: :smiley:

1 Like