What's new

keeping net-lan settings static

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

kpnobvious

New Around Here
Hi,
With each voxel release i need to update some settings in net-lan, basically for custom DNS. Is there any way to script these after an upgrade? I don't have a USB drive mounted, but can.
 
You can use the /mnt/sda1/autorun/scripts/post-mount.sh script to run whatever you want each time the drive is mounted (hence at each reboot as well as long as the drive is connected).

Best practice is to insert a line calling your own script in post-mount.sh
For example /mnt/sda1/set-custom-net-lan-settings.sh
 
Hi,
With each voxel release i need to update some settings in net-lan, basically for custom DNS. Is there any way to script these after an upgrade? I don't have a USB drive mounted, but can.
I do something similar setting RP4 as lan dns instead of router itself. I wrote a script for this. Script is copied automatically to /opt/lan_dns/ dir on router after firmware update through /autorun/scripts/post-mount.sh. This is the only script that I run manually after firmware update. I use same script sometimes to switch back dns to router as well.

You can modify it to be completely automated by removing input cmd and make it as one way change of switching dns from router to some other dns server. Also change post-mount.sh to copy and then execute it.

Voxel readme has instructions for creating usb.

USB Files Location:
/autorun/scripts/post-mount.sh
/scripts/change_lan_dns.sh

• Make sure you replace the ip with your desired dns ip in the script
• "change_lan_dns.sh" script:
Bash:
#!/bin/sh

lanDnsFile=''
routerDns=''
piDns=''
routerIsDNS=-1
piIsDNS=-1

findLanDns () {
  lanDnsFile='/etc/init.d/net-lan'
  routerDns='option dns $($CONFIG get lan_ipaddr)'
  piDns='option dns 10.1.1.2'
  dnsFuncArg='option dns'
  grep -q "$routerDns" "$lanDnsFile"
  routerIsDNS=$?
  grep -q "$piDns" "$lanDnsFile"
  piIsDNS=$?
  grep -q "$dnsFuncArg" "$lanDnsFile"
  isFuncArg=$?
}

changeLanDns () {
  local currentDns="$1"
  local newDns="$2"
  sed -i '1,/'"$currentDns"'/s/'"$currentDns"'.*/'"$newDns"'/' "$lanDnsFile"
}

echo -e "\n \xC2\xBB Select An Option To Set As LAN DNS Server [1|2|3]"
echo -e " 1 \xE2\xAE\x9E RP4"
echo -e " 2 \xE2\xAE\x9E R7800"
echo -e " 3 \xE2\xAE\x9E Exit"
read -p " " argument;
findLanDns

case $argument in
  1)
    if [ $routerIsDNS -eq 0 ]; then
      changeLanDns "$routerDns" "$piDns"
      echo -e " \xC2\xBB |RP4| Set As New Lan Dns Server \xC2\xBB Reboot Router\n"
    elif [ $piIsDNS -eq 0 ]; then
      echo -e " \xC2\xBB RP4 Is Already Lan Dns Server\n"
    elif [ $isFuncArg -eq 0 ]; then
      changeLanDns "$dnsFuncArg" "$piDns"
      echo -e " \xC2\xBB |RP4| Set As New Lan Dns Server \xC2\xBB Reboot Router\n"
    else
      echo -e " \xC2\xBB Issue in |/etc/init.d/net-lan| \xC2\xBB Unable To Set |option dns ...|\n"
    fi
    ;;
  2)
    if [ $piIsDNS -eq 0 ]; then
      changeLanDns "$piDns" "$routerDns"
      echo -e " \xC2\xBB |R7800| Set As New Lan Dns Server \xC2\xBB Reboot Router\n"
    elif [ $routerIsDNS -eq 0 ]; then
      echo -e " \xC2\xBB R7800 Is Already Lan Dns Server\n"
    elif [ $isFuncArg -eq 0 ]; then
      changeLanDns "$dnsFuncArg" "$routerDns"
      echo -e " \xC2\xBB |R7800| Set As New Lan Dns Server \xC2\xBB Reboot Router\n"
    else
      echo -e " \xC2\xBB Issue in |/etc/init.d/net-lan| \xC2\xBB Unable To Set |option dns ...|\n"
    fi
    ;;
  3)
    echo -e " \xC2\xBB Nothing Changed \xC2\xBB Exiting ...\n"
    exit 1
    ;;
  *)
    echo -e " \xC2\xBB Invalid Option \xC2\xBB Exiting ...\n"
    exit 1
esac

• Excerpt from "post-mount.sh" for copying script:
Bash:
# Copy Lan DNS Server Script
if [[ -f /tmp/mnt/$1/scripts/change_lan_dns.sh -a ! -d /opt/lan_dns ]]; then
    mkdir -p /opt/lan_dns
    cp -p -f /tmp/mnt/$1/scripts/change_lan_dns.sh /opt/lan_dns
    chmod 0755 /opt/lan_dns/change_lan_dns.sh
fi

This is how it looks like when run manually:
lan-dns-script.png
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top