I read this tutorial, however I am considering a method to load balancing for Internet connection by applying iptables rule on 2 interfaces. The following is my iptables rule.#!/bin/shIPT=/sbin/iptablesLAN='ens38'WAN='ens33'OPT='ens37'LAN_NET=192.168.100.0/24$IPT -F$IPT -X$IPT -t nat -F$IPT -P INPUT DROP$IPT -P OUTPUT DROP$IPT -P FORWARD DROP$IPT -A FORWARD -i $LAN -o $WAN -j ACCEPT$IPT -A FORWARD -i $LAN -o $OPT -j ACCEPT$IPT -A FORWARD -i $WAN -o $LAN -j ACCEPT$IPT -A FORWARD -i $OPT -o $LAN -j ACCEPT$IPT -t nat -A POSTROUTING -o $WAN -j MASQUERADE$IPT -t nat -A POSTROUTING -o $OPT -j MASQUERADE# Load balancing rules (Split 50/50 between fwmark 1/2)$IPT -t mangle -N balance1$IPT -t mangle -A balance1 -m connmark ! --mark 0 -j RETURN$IPT -t mangle -A balance1 -m state --state ESTABLISHED,RELATED -j RETURN$IPT -t mangle -A balance1 -m statistic --mode nth --every 2 --packet 0 -j CONNMARK --set-mark 1$IPT -t mangle -A balance1 -m statistic --mode nth --every 2 --packet 1 -j CONNMARK --set-mark 2# Check to see if we have already marked a packet$IPT -t mangle -A PREROUTING  -m state --state ESTABLISHED,RELATED -j CONNMARK --restore-mark$IPT -t mangle -A OUTPUT      -m state --state ESTABLISHED,RELATED -j CONNMARK --restore-mark# Mark incoming connections to return on the interface they came in on$IPT -t mangle -A PREROUTING          -i $WAN                     -m state --state NEW  -j CONNMARK --set-mark 1$IPT -t mangle -A PREROUTING          -i $OPT                     -m state --state NEW  -j CONNMARK --set-mark 2# New outgoing packets$IPT -t mangle -A PREROUTING  -i $LAN          -p tcp --dport 80 -m state --state NEW  -j balance1$IPT -t mangle -A PREROUTING  -i $LAN          -p tcp --dport 443 -m state --state NEW  -j balance1# $IPT -t mangle -A OUTPUT                       -p tcp --dport  80 -m state --state NEW  -j balance1# Choose our route and save the mark$IPT -t mangle -A PREROUTING  -m connmark --mark 1 -j MARK --set-mark 1$IPT -t mangle -A PREROUTING  -m connmark --mark 2 -j MARK --set-mark 2$IPT -t mangle -A PREROUTING  -m state --state NEW -m connmark ! --mark 0  -j CONNMARK --save-markecho 1 > /proc/sys/net/ipv4/ip_forwardI defined 2 table wan and opt in /etc/iproute2/rt_tables like the following:[root@R1 ~]# cat /etc/iproute2/rt_tables ## reserved values#255 local254 main253 default0   unspec## local#1   wan2   optThis is the script that I add route for iproute:LAN_DEV='ens38'WAN_DEV='ens33'OPT_DEV='ens37'WAN_GW=192.168.84.2OPT_GW=192.168.0.1LAN_NET=192.168.100.0/24ip rule add fwmark 1 table wanip rule add fwmark 2 table opt# Add default route for table wan and optip route add default via $WAN_GW dev $WAN_DEV table wanip route add default via $OPT_GW dev $OPT_DEV table opt# Add LAN route for table wan and optip route add $LAN_NET dev $LAN_DEV table optip route add $LAN_NET dev $LAN_DEV table wanAs I understood from this guide, restore-mark and save-mark  restore and save the packet mark from the connection mark. So the rules apply for every packet in a connection. For example: I have a connection A. iptables rules count every 4 packets in connection A and mark it 1,2,1,2.How can I mark a connection separately in case I have many connections. For example: I have 3 connections A,B,C and I want to count and mark them like: 1,2,3.Actually, this rule uses route from WAN (ens33) only. When the packet come in to router. It not route to OPT (ens37) which I can not explain.
How can I mark a flow with iptables?
linux;iptables