I am editting/extending my firewall bash script on ubuntu dedicated server.
The code below is just an excerpt. The purpose below is to reroute/open for some IPs my (http, ftp, telnet and ssh) ports for/to 3 boxes.
The problem is that I want to use variables in a variable.
So --dport ${i}_${j}_port_ext is correctly replaced by f.i. --dport box0_http_port_ext but is not seen as a variable (of course). Actually, what I want should be --dport $box0_http_port_ext (mind the $ at the beginning)
I tried several things f.i. --dport ${${i}_${j}_port_ext} or --dport $(${i}_${j}_port_ext) but that is not good.
box0_http_port_ext="8080"
box0_ftp_port_ext="21"
box0_telnet_port_ext="23"
box0_ssh_port_ext="22"
#
allow_box0_http_port_ip="1.2.3.4 99.98.97.96 55.56.57.58"
allow_box0_ftp_port_ip="1.2.3.4 55.56.57.58"
allow_box0_telnet_port_ip="55.56.57.58"
allow_box0_ssh_port_ip="1.2.3.4"
#
for i in box0 box1 box2
do
for j in http ftp telnet ssh
do
for ips in $allow_${i}_${j}_port_ip
do
$IPTABLES -t nat -A PREROUTING -p tcp -i $LAN_IFACE -s $ips --dport ${i}_${j}_port_ext -j DNAT --to-destination ${i}_ip:${i}_${j}_port_int
done
done
done
Please do not look at the code because it is an excerpt and thus not complete.
The question is: how to code --dport $box0_http_port_ext by making use of $i for box0 and $j for http. Keeping in mind that $i also can be box1/box2 and $j also can be replaced by ftp/telnet/ssh.