RE: Hostname with DNAT ? {OK}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> $IPTABLES -A PREROUTING -t nat -i eth0 -p tcp -d mail.server1.com --dport 25 -j DNAT --to 192.168.14.254:25
> $IPTABLES -A FORWARD -i eth0 -p tcp -d mail1.server.com --dport 25 -j ACCEPT
>
> $IPTABLES -A PREROUTING -t nat -i eth0 -p tcp -d mail.server2.com --dport 25 -j DNAT --to 192.168.14.251:25
> $IPTABLES -A FORWARD -i eth0 -p tcp -d mail.server2.com --dport 25 -j ACCEPT
>
> $IPTABLES -A PREROUTING -t nat -i eth0 -p tcp -d server3.com --dport 25 -j DNAT --to 192.168.14.253:25
> $IPTABLES -A FORWARD -i eth0 -p tcp -d server3.com --dport 25 -j ACCEPT
> $IPTABLES -A PREROUTING -t nat -i eth0 -p tcp -d mail.server3.com --dport 25 -j DNAT --to 192.168.14.253:25
> $IPTABLES -A FORWARD -i eth0 -p tcp -d mail.server3.com --dport 25 -j ACCEPT
>
> Is posibble to use names instead of IP like in my situation ?

using a resolvable hostname instead of an IP in a rule is perfectly valid.  the caveat is:  at the time you execute the script, the hostname is resolved to an IP address and the IP is what ends up in the rule.  if the IP associated with the hostname changes after the rules are loaded--you must reload the rules for the new IP to be used in the rule.

my guess is that the reason you wish to do this is that you have a dynamic IP address and are using some sort of dynamic DNS service.  you will probably want to incorporate the re-loading of your ruleset into your DHCP client whenever your IP changes.  you could actually do this without utilizing the "dynamic DNS + hostname in rules" solution  by incorporating something like this into your ruleset:

	MY_IF="eth0"
	MY_IP=`ip addr sh $MY_IF | grep inet | awk '{print $2}' | cut -d"/" -f1`

	$IPTABLES -A PREROUTING -t nat -i $MY_IF -p tcp -d $MY_IP \
	  --dport 25 -j DNAT --to 192.168.14.251:25

and whenever your IP changes--have the script re-execute to pickup the new IP.

-j




[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux