If anybody wants to take a look at this , I created a Linus shell program ( a draft early beta version ) of the addNatRules
This runs on a Linux system - not on a Mikrotik
At this time - I do not have any action=jump lines in my code ( so if it works , it might be slow )
If beta version appears to want to work, then I will re-work it to use action=jump lines in my code.
And add the ability to use larger GGN network ( example /21 ) and NAT to multiple live IP addresses ( some big stuff ).
And possibly the ability to save and modify configurations and auto telnet/ssh to a Mikrotik to auto update the configuration
That said - here is the shell program - please give it a look-see
North Idaho Tom Jones
Linux shell program
------------------- Cut below this line -------------------
#!/bin/sh
clear
echo "This is a Beta program --> addNatRules-Beta-Version024.sh created on January 11 2022 "
echo
echo "This program is by North Idaho Tom Jones "
echo
echo "This program is a script to build a CGN Nat configuration which can then be inserted into a Mikrotik NAT router"
echo
echo "This program is a Beta program. This is not a finished, completed or fully working program at this time."
echo
echo "Use this program and the output text at your own risk."
echo
echo
echo
echo -n "Push the ENTER button to continue :"
read dummy
i=0
StartPort=2000
EndPort=2099
clear
echo "What is the first number in your starting CGN-Nat block"
echo " Example - if you want to NAT 100.64.0.0/24 , then you would enter 100 ( then push the ENTER button "
echo -n " Input your first number : "
read n1
echo " OK - the first number is going to be $n1"
echo
echo
echo "Note: so far we have $n1"
echo
echo
echo "What is the second number in your starting CGN-Nat block"
echo " Example - if you want to NAT 100.64.0.0/24 , then you would enter 64 ( then push the ENTER button "
echo -n " Input your second number : "
read n2
echo " OK - the second is going to be $n2"
echo
echo
echo "Note: so far we have $n1.$n2."
echo
echo
echo "What is the third number in your starting CGN-Nat block"
echo " Example - if you want to NAT 100.64.0.0/24 , then you would enter 0 ( then push the ENTER button "
echo -n " Input your third number : "
read n3
echo " OK - the third is going to be $n3"
echo
echo
echo "Note: so far we have $n1.$n2.$n3"
echo
echo
echo "What is the fourth number in your starting CGN-Nat block"
echo " Example - if you want to NAT 100.64.0.0/24 , then you would enter 0 ( then push the ENTER button "
echo -n " Input your fourth number : "
read n4
echo " OK - the fourth second is going to be $n4"
echo
echo
echo "Note: so far we have $n1.$n2.$n3.$n4"
echo
echo "Push the ENTER button to continue"
read dummy
clear
echo "Note: so far we have $n1.$n2.$n3.$n4"
echo "Note: I will use $n1.$n2.$n3.$n4 as your starting CGN-NAT IP address"
echo "Push the ENTER button to continue"
read dummy
clear
echo i-n "What is the outside Live-IP address you will be CGN Natting to : "
read OutSideLiveIP
echo
echo "This program will use outside Live-IP address of $OutSideLiveIP"
echo "Push the ENTER button to continue"
read dummy
clear
echo " What is your Starting Port Number "
echo " Note: there are 65,536 ports ( 0 through 65,535 )"
echo " I would like to suggest a starting port number of 1000 or 2000 or 3000 "
echo
echo -n "Enter your Starting Port Number "
read StartPort
echo
echo "I will use a starting port number of : $StartPort "
echo
echo "Push the ENTER button to continue"
read dummy
clear
echo "How many ports do you want to use ?"
echo "Note: answers can be 100 or 1000 ( or some other valid number "
echo
echo -n "How many ports do you want to use for each Internal NATted to a live IP address : "
read PortsPerTranslation
echo
echo "OK - I will use $PortsPerTranslation per translation"
echo
echo
echo "Push the ENTER button to continue"
read dummy
clear
while [ $i -ne 256 ]
do
EndPort=$(($StartPort+$PortsPerTranslation-1))
echo "#"
echo "#$i Inside NAT IP address $n1.$n2.$n3.$i will translate to outside IP address $OutSideLiveIP using ports $StartPort-$EndPort"
echo "add action=src-nat chain=srcnat protocol=tcp src-address=$n1.$n2.$n3.$i to-addresses=$OutSideLiveIP to-ports=$StartPort-$EndPort"
echo "add action=src-nat chain=srcnat protocol=udp src-address=$n1.$n2.$n3.$i to-addresses=$OutSideLiveIP to-ports=$StartPort-$EndPort"
echo "add action=src-nat chain=srcnat src-address=$n1.$n2.$n3.$i to-addresses=$OutSideLiveIP to-ports=$StartPort-$EndPort"
i=$(($i+1))
StartPort=$(($StartPort+$PortsPerTranslation))
done
------------------- Cut above this line -------------------
Output: This is a Beta program --> addNatRules-Beta-Version024.sh created on January 11 2022
Push the ENTER button
Output: What is the first number in your starting CGN-Nat block
Enter: 100 then push the ENTER button
Output: What is the second number in your starting CGN-Nat block
Enter: 64 then push the ENTER button
Output: What is the third number in your starting CGN-Nat block
Enter: 0 then push the ENTER button
Output: What is the fourth number in your starting CGN-Nat block
Enter: 0 then push the ENTER button
Output: Note: so far we have 100.64.0.0
Enter: Push the ENTER button
Output: Note: so far we have 100.64.0.0
Enter: Push the ENTER button
Output: What is the outside Live-IP address you will be CGN Natting to :
- Here - you type in the full outside IP address you are going to NAT to that the outside world sees
- In my example , I will use: 23.162.144.120 (( this is the outside IP address of my btest server )).
Enter: Push the ENTER button
Output: This program will use outside Live-IP address of 23.162.144.120
Enter: Push the ENTER button
Output: What is your Starting Port Number
Enter: 1000 then push the ENTER button
Output: I will use a starting port number of : 1000
Enter: Push the ENTER button
Output: How many ports do you want to use for each Internal NATted to a live IP address :
Enter: 250 then push the ENTER button
Output: OK - I will use 250 per translation
Enter: Push the ENTER button
************* the program is now running and printing out the Mikrotik NAT444 configuration we want ******
This is the shell program output below:
#0 Inside NAT IP address 100.64.0.0 will translate to outside IP address 23.162.144.120 using ports 1000-1249
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.0 to-addresses=23.162.144.120 to-ports=1000-1249
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.0 to-addresses=23.162.144.120 to-ports=1000-1249
add action=src-nat chain=srcnat src-address=100.64.0.0 to-addresses=23.162.144.120 to-ports=1000-1249
#1 Inside NAT IP address 100.64.0.1 will translate to outside IP address 23.162.144.120 using ports 1250-1499
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.1 to-addresses=23.162.144.120 to-ports=1250-1499
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.1 to-addresses=23.162.144.120 to-ports=1250-1499
add action=src-nat chain=srcnat src-address=100.64.0.1 to-addresses=23.162.144.120 to-ports=1250-1499
#2 Inside NAT IP address 100.64.0.2 will translate to outside IP address 23.162.144.120 using ports 1500-1749
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.2 to-addresses=23.162.144.120 to-ports=1500-1749
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.2 to-addresses=23.162.144.120 to-ports=1500-1749
add action=src-nat chain=srcnat src-address=100.64.0.2 to-addresses=23.162.144.120 to-ports=1500-1749
#3 Inside NAT IP address 100.64.0.3 will translate to outside IP address 23.162.144.120 using ports 1750-1999
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.3 to-addresses=23.162.144.120 to-ports=1750-1999
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.3 to-addresses=23.162.144.120 to-ports=1750-1999
add action=src-nat chain=srcnat src-address=100.64.0.3 to-addresses=23.162.144.120 to-ports=1750-1999
#4 Inside NAT IP address 100.64.0.4 will translate to outside IP address 23.162.144.120 using ports 2000-2249
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.4 to-addresses=23.162.144.120 to-ports=2000-2249
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.4 to-addresses=23.162.144.120 to-ports=2000-2249
add action=src-nat chain=srcnat src-address=100.64.0.4 to-addresses=23.162.144.120 to-ports=2000-2249
--- through ----
#251 Inside NAT IP address 100.64.0.251 will translate to outside IP address 23.162.144.120 using ports 63750-63999
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.251 to-addresses=23.162.144.120 to-ports=63750-63999
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.251 to-addresses=23.162.144.120 to-ports=63750-63999
add action=src-nat chain=srcnat src-address=100.64.0.251 to-addresses=23.162.144.120 to-ports=63750-63999
#252 Inside NAT IP address 100.64.0.252 will translate to outside IP address 23.162.144.120 using ports 64000-64249
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.252 to-addresses=23.162.144.120 to-ports=64000-64249
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.252 to-addresses=23.162.144.120 to-ports=64000-64249
add action=src-nat chain=srcnat src-address=100.64.0.252 to-addresses=23.162.144.120 to-ports=64000-64249
#253 Inside NAT IP address 100.64.0.253 will translate to outside IP address 23.162.144.120 using ports 64250-64499
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.253 to-addresses=23.162.144.120 to-ports=64250-64499
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.253 to-addresses=23.162.144.120 to-ports=64250-64499
add action=src-nat chain=srcnat src-address=100.64.0.253 to-addresses=23.162.144.120 to-ports=64250-64499
#254 Inside NAT IP address 100.64.0.254 will translate to outside IP address 23.162.144.120 using ports 64500-64749
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.254 to-addresses=23.162.144.120 to-ports=64500-64749
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.254 to-addresses=23.162.144.120 to-ports=64500-64749
add action=src-nat chain=srcnat src-address=100.64.0.254 to-addresses=23.162.144.120 to-ports=64500-64749
#255 Inside NAT IP address 100.64.0.255 will translate to outside IP address 23.162.144.120 using ports 64750-64999
add action=src-nat chain=srcnat protocol=tcp src-address=100.64.0.255 to-addresses=23.162.144.120 to-ports=64750-64999
add action=src-nat chain=srcnat protocol=udp src-address=100.64.0.255 to-addresses=23.162.144.120 to-ports=64750-64999
add action=src-nat chain=srcnat src-address=100.64.0.255 to-addresses=23.162.144.120 to-ports=64750-64999