Could you manually exploit this extended match ?Currently we can only port forward to a single internal IP. Is it possible to add the capability for portforwarding to multiple internal IPs given a port? Possibly add the capability of checking if there is something listening first before forwarding.
iptables -m statistic -help
iptables -A PREROUTING -p tcp -m tcp --dport 50000 -m statistic --mode nth --every 3 -j REDIRECT --to-ports 10001 -d 192.168.1.99
iptables -A PREROUTING -p tcp -m tcp --dport 50000 -m statistic --mode nth --every 2 -j REDIRECT --to-ports 10002 -d 192.168.1.99
iptables -A PREROUTING -p tcp -m tcp --dport 50000 -j REDIRECT --to-ports 10003 -d 192.168.1.99
Load balancing is doable (if that's what the OP was asking), but you have to count the packets also (--packet n).so it may be possible to use 3 different IPs for each of the round robin matching for a Load-Balancing scenario?
Load balancing is doable (if that's what the OP was asking), but you have to count the packets also (--packet n)
-m state --state NEW
iptables -A PREROUTING -p tcp -m tcp --dport 12345 -m statistic --mode nth --every 3 -j REDIRECT --to-ports 12345 -d 192.168.1.45
iptables -A PREROUTING -p tcp -m tcp --dport 12345 -m statistic --mode nth --every 2 -j REDIRECT --to-ports 12345 -d 192.168.1.46
I don't mind a script option. The concept is to run multiple docker containers and rather than having a single node (internal machines) as the failure point to have multiple nodes serving the public IP and hosting the site.
So the concept would be?
#!/bin/sh
NODES="45 46 47 48" # List of Web server nodes
PORT_EXTERNAL="8080" # Public External Port
PORT_INTERNAL="80" # Internal Port
LAN_PREFIX=$(nvram get lan_ipaddr | cut -d'.' -f1-3)
INDEX=1
for NODE in $NODES
do
iptables -t nat -D VSERVER -p tcp --dport $PORT_EXTERNAL -m state --state NEW -m statistic --mode nth --every $INDEX --packet 0 -j DNAT --to-destination ${LAN_PREFIX}.${NODE}:$PORT_INTERNAL 2>/dev/null
iptables -t nat -I VSERVER -p tcp --dport $PORT_EXTERNAL -m state --state NEW -m statistic --mode nth --every $INDEX --packet 0 -j DNAT --to-destination ${LAN_PREFIX}.${NODE}:$PORT_INTERNAL
INDEX=$((INDEX+1))
done
iptables -nvL PREROUTING --line -t nat | grep -E "^num|Chain PREROUTING|VSERVER"
echo
iptables -nvL VSERVER --line -t nat | grep -E "^num|VSERVER|nth"
@Martineau Just curious whether you've got your script to run without syntax errors? I tried using the statistic module but it always returned an error because it was not included in my firmware (John's Fork). John kindly built a custom firmware with it included and it then accepted the commands as expected. John said that he thought Merlin's firmware also lacked the statistic module. Did you find that to be the case?
./PortForwardLoadBalancing.sh -h
#============================================================================== © 2018 Martineau, v01.01
#
# Configure Port Forward round-robin Load-balancing rules
#
# PortForwardLoadBalancing [--help|-h]
# [--check] [--flush] [nodes={"IP [IP"...]}] [extport{='port'}] [intport{='port'}] [nocurl]
# PortForwardLoadBalancing
# Create the round-robin rules for the defined Web servers (default Ports External=8080,Internal=80)
# PortForwardLoadBalancing --check
# Create the round-robin rules for the defined Web servers ONLY if the Web server is PING/CURL available
# PortForwardLoadBalancing --flush
# Flush ALL round-robin rules
# PortForwardLoadBalancing --nodes="99 100 101"
# Create the round-robin rules for Web servers .99,.100 and .101 (i.e. override $NODE variable)
# PortForwardLoadBalancing --extport=12345
# Create the round-robin rules using External (Public) port 12345
./PortForwardLoadBalancing.sh
v1.01 © 2018 Martineau, Port Forwarding round-robin Load-Balancing requested.....
ALL round-robin Port Forwarding Load-Balancing rules flushed.....
Creating round-robin Port Forwarding Load-Balancing rules..... (Nodes=45 46 47 48 131)
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
7 2938 278K VSERVER all -- * * 0.0.0.0/0 xxx.xxx.xxx.xxx
Chain VSERVER (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 5 to:10.88.8.131:80
2 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 4 to:10.88.8.48:80
3 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 3 to:10.88.8.47:80
4 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 2 to:10.88.8.46:80
5 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 1 to:10.88.8.45:80
Port Forwarding round-robin Load-Balancing completed.....
./PortForwardLoadBalancing.sh --check
v1.01 © 2018 Martineau, Port Forwarding round-robin Load-Balancing requested.....
Checking Web server(s).....
10.88.8.45 not available
10.88.8.46 not available
10.88.8.47 not available
10.88.8.48 not available
10.88.8.131 available
ALL round-robin Port Forwarding Load-Balancing rules flushed.....
Creating round-robin Port Forwarding Load-Balancing rules..... (Nodes= 131)
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
7 2944 279K VSERVER all -- * * 0.0.0.0/0 xxx.xxx.xxx.xxx
Chain VSERVER (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 1 to:10.88.8.131:80
Port Forwarding round-robin Load-Balancing completed.....
./PortForwardLoadBalancing.sh --flush
v1.01 © 2018 Martineau, Port Forwarding round-robin Load-Balancing requested.....
ALL round-robin Port Forwarding Load-Balancing rules flushed.....
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
7 2945 279K VSERVER all -- * * 0.0.0.0/0 xxx.xxx.xxx.xxx
Chain VSERVER (1 references)
num pkts bytes target prot opt in out source destination
Port Forwarding round-robin Load-Balancing completed.....
./PortForwardLoadBalancing.sh --extport=12345 --intport=81
v1.01 © 2018 Martineau, Port Forwarding round-robin Load-Balancing requested.....
ALL round-robin Port Forwarding Load-Balancing rules flushed.....
Creating round-robin Port Forwarding Load-Balancing rules..... (Nodes=45 46 47 48 131)
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
7 2945 279K VSERVER all -- * * 0.0.0.0/0 xxx.xxx.xxx.xxx
Chain VSERVER (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:12345 state NEW statistic mode nth every 5 to:10.88.8.131:81
2 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:12345 state NEW statistic mode nth every 4 to:10.88.8.48:81
3 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:12345 state NEW statistic mode nth every 3 to:10.88.8.47:81
4 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:12345 state NEW statistic mode nth every 2 to:10.88.8.46:81
5 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:12345 state NEW statistic mode nth every 1 to:10.88.8.45:81
Port Forwarding round-robin Load-Balancing completed.....
I double checked...and according to the config files it's not there in Merlin as well. I don't understand how @Martineau got it working unless he's running a custom build.John said that he thought Merlin's firmware also lacked the statistic module. Did you find that to be the case?
I double checked...and according to the config files it's not there in Merlin as well. .
No idea either .... I assumed it was finally included sometime in the 382.xx/384.xx builds as Asus overhaul their wonky Dual-WAN LB/FO code etc.?I don't understand how @Martineau got it working unless he's running a custom build.
./PortForwardLoadBalancing.sh --status
v1.01 © 2018 Martineau, Port Forwarding round-robin Load-Balancing requested.....
Rule status:
Chain PREROUTING (policy ACCEPT 18749 packets, 4911K bytes)
num pkts bytes target prot opt in out source destination
7 4324 353K VSERVER all -- * * 0.0.0.0/0 xxx.xxx.xxx.xxx
Chain VSERVER (1 references)
num pkts bytes target prot opt in out source destination
1 74 3280 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB0Begin"
2 74 3280 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB5"
3 2 104 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 5 packet 4 to:10.88.8.131:80
4 72 3176 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB4"
5 2 104 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 4 packet 3 to:10.88.8.48:80
6 70 3072 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB3"
7 3 156 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 3 packet 2 to:10.88.8.47:80
8 67 2916 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB2"
9 3 156 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 2 packet 1 to:10.88.8.46:80
10 64 2760 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 7 level 4 prefix "PFLB1"
11 3 156 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 state NEW statistic mode nth every 1 to:10.88.8.45:80
Thread starter | Title | Forum | Replies | Date |
---|---|---|---|---|
B | Single guest network where devices can interact | Asuswrt-Merlin | 7 | |
G | wifi devices get disconnected from router/aimesh single iphoneXS/15 pro triggers this when coming home | Asuswrt-Merlin | 15 |
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!