I am attempting to use my pi to share an internet connection on wifi with the ethernet port.  I am able to get it to work by running these commands in terminal:

    sudo service dhcpcd restart
    sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
    sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
    sudo iptables -A FORWARD -i wlan1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A FORWARD -i eth0 -o wlan1 -j ACCEPT
    sudo service dnsmasq start

That part I have figured out.  What I have not figured out is how to run these commands on restart of the pi.  I have tried putting them in the rc.local file as some online suggestions but does not work on boot up.  These commands do run on starting a new terminal server session.

I have tried the ideas on this page, https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/ and https://raspberrytips.com/autostart-a-program-on-boot/ but have not been successful.  Some suggestion refer to running a program or a script file or a service.  I do not know how to take these commands and turn them into a script file, program or service.  

I know the code does what I want it to.  You help to get it running on boot up would be a big help.  thanks