====== MultiWAN DDNS Load Sharing ====== In a MultiWAN configuration, FreshTomato can make use of multiple Internet connections simultaneously. It is also possible to make a service hosted on the local network accessible from the Internet through multiple WAN interfaces, using a single FQDN (Fully Qualified Domain Name). This can be achieved by combining Dynamic DNS (DDNS) with DNS round-robin. \\ ===== How it works ===== Normally, a DDNS hostname is associated with a single IP address. Whenever the WAN IP address changes, FreshTomato updates the corresponding DNS record at the DDNS provider. Some DDNS providers, however, allow multiple A records to share the same hostname while pointing to different IP addresses. By configuring an independent DDNS update for each WAN interface, multiple dynamic IP addresses can be associated with the same FQDN. For example: ^ FQDN ^ WAN interface ^ Public IP address ^ | server.example.com | WAN0 | 203.0.113.10 | | server.example.com | WAN1 | 198.51.100.20 | When an Internet client resolves server.example.com, both IP addresses can be returned by the DNS provider. The client can then establish a connection using either IP address. This technique is commonly referred to as DNS round-robin or DNS-based load sharing. Although this example makes use of two WAN interfaces, the technique is not limited to two WANs. Additional WAN interfaces can participate, provided that the DDNS provider supports the corresponding number of independently updated A records and the FreshTomato build supports the required DDNS configurations. \\ ===== DDNS provider compatibility ===== Not all DDNS providers support this configuration. The DDNS provider must support: * Multiple A records sharing the same FQDN. \\ \\ * Independent dynamic updates of each A record, without overwriting the other records. Providers offering relevant functionality include: * [[https://freedns.afraid.org/|FreeDNS (Afraid.org)]] * [[https://www.noip.com/|No-IP]] * [[https://www.dynu.com/|Dynu]] Compatibility may depend on the subscription, update protocol and implementation of the DDNS client. FreeDNS is particularly suitable for this purpose because each DNS record can be updated using its own unique update token (hash), rather than using only the hostname as the record identifier. Refer to the [[https://freedns.afraid.org/faq/|FreeDNS FAQ]] for further details. \\ ===== Configure DDNS load sharing ===== The following example makes use of FreeDNS and two WAN interfaces. On the DDNS provider's website: \\ - Create two A records with the same FQDN but different IP addresses. \\ \\ - Obtain the individual DDNS update token (hash) for each record. \\ \\ - Disable any option you might have to "Link updates of the same IP together", this ensures that each record can be updated independently. \\ Next, in the /Basic/[[basic-ddns|DDNS]] menu: \\ - Configure the first DDNS entry using the first update token and select WAN0 as the IP address source. \\ \\ - Configure the second DDNS entry using the second update token and select WAN1 as the IP address source. \\ \\ - Save the configuration and verify that both DDNS updates are successful. \\ Each WAN interface will now independently update its corresponding A record whenever its public IP address changes. The hostname remains the same regardless of which WAN IP address is updated. An Internet client contacting the FQDN in question will now be served a random IP from the ones you linked to it on your DDNS provider account configuration. \\ ===== Port forwarding ===== DDNS only provides name resolution. It does not automatically make a service accessible through all WAN interfaces. If a service is hosted on a device connected to the LAN, the relevant port must be forwarded on every participating WAN interface. Depending on the FreshTomato version and configuration, the standard /Port Forwarding/[[forward-basic|Basic]] menu may not provide the required MultiWAN port forwarding functionality. Additional port forwarding rules can be implemented using a Firewall script. \\ ==== Example: Forward TCP port 80 on WAN1 ==== In this example: * WAN0 is already configured to forward TCP port 80. * WAN1 uses the vlan3 network interface. * The web server is located at 192.168.1.100. * The web server is listening on TCP port 80. * The web server uses FreshTomato as its default gateway. To additionally forward incoming TCP port 80 traffic on WAN1, add the following commands to the Firewall field in the /Administration/[[admin-scripts|Scripts]] menu: For the sake of this example we'll assume WAN1 is server via vlan3 and we have a webserver on the LAN reponding to port TCP 80. iptables -t nat -I PREROUTING -i vlan3 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.100:80 iptables -I FORWARD -i vlan3 -p tcp -d 192.168.1.100 --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT The first command redirects incoming TCP port 80 traffic on vlan3 to the internal web server. The second command allows the corresponding traffic to pass through the firewall. Adjust the interface name, destination IP address and port number according to your configuration. Note that vlan3 is used here as an example. The actual WAN interface name may differ depending on the hardware, VLAN configuration and WAN connection type (e.g. PPPoE). Additional rules can be added for other WAN interfaces and/or services as required. Return traffic must leave through the same WAN interface through which the connection was originally established. Verify that the existing MultiWAN routing configuration handles this correctly. Refer to the /Advanced/[[advanced-pbr|MultiWAN Routing]] menu for further information. **Important:** Port forwarding exposes the destination service to the Internet. Ensure that the service is appropriately secured. HTTPS is recommended for web services. \\ ===== Verify the configuration ===== From a computer, resolve the configured FQDN using a DNS lookup tool. For example: nslookup server.example.com The result should contain the public IP addresses associated with the participating WAN interfaces. Next, from a device outside the local network, verify that the service is accessible independently through each WAN IP address. For example: curl --resolve server.example.com:80:203.0.113.10 http://server.example.com/ curl --resolve server.example.com:80:198.51.100.20 http://server.example.com/ Testing from outside the local network avoids potential complications associated with NAT loopback. Also verify that a change to the IP address of one WAN updates only its corresponding DNS record. \\ ===== Limitations ===== * **This is a load sharing mechanism, not a failover mechanism.** \\ \\ If a WAN connection becomes unavailable, its IP address may remain published in DNS. Some clients may therefore attempt to connect through the unavailable WAN. \\ \\ * DNS round-robin does not guarantee an equal distribution of incoming connections between WAN interfaces. \\ \\ * DNS caching may introduce a delay before changes to WAN IP addresses become visible to Internet clients. \\ \\ * All participating WAN connections must be externally reachable. CGNAT, upstream NAT and ISP port restrictions may prevent incoming connections. \\ \\ * Port forwarding and return-path routing must be configured correctly for each participating WAN interface. \\ \\ * Existing connections cannot normally migrate between WAN interfaces when a connection becomes unavailable. \\ \\ * This mechanism operates independently of FreshTomato's outbound MultiWAN load balancing weights. \\ Automatic DNS-based failover would require an additional mechanism capable of detecting WAN unavailability and removing or replacing the corresponding DNS record. Standard DDNS updates and DNS round-robin alone do not provide this functionality. \\ \\