I've just upgraded from 1.12 to 1.13, and wrote a little script to convert the static DHCP entries as they are now in a different format - thought I'd share it in case it's of use.
Here's what to do:
* Create a temp directory somewhere, doesn't have to be on the router, but does need BASH support.
* Create the below script in that temp directory.
* From the source router (1.12), copy /etc/hosts and /etc/ethers to the temp directory as the filenames "hosts" and "ethers"
* Open a terminal in the temp directory, chmod +x the script (name it what you like).
* On the target router (1.13), open an SSH shell.
* Make a backup of /etc/config/dhcp just in case.
Code: Select all
cd /etc/config
cp dhcp dhcp.backup
vi /etc/config/dhcp
(I use vi for editing, you may have something else)
* Go to the end of the file (SHIFT G). If there are any static hosts already defined on the 1.13 router, you will see an entry like:
config host 'static_host_3'
* You will need to modify the "count=1" line in the script line 25, to the next number. In my example, you would modify it to:
Code: Select all
count=4
* It will create output.txt in the temp directory. Open this file in an editor and copy all the lines from 'static_host_1' to the highest static host number, to the clipboard.
* On the target 1.13 router, edit /etc/config/dhcp and paste those copied lines into the file, and save it.
* In the target 1.13 router web interface, refresh the DHCP page under Connection and you should see the static hosts listed under "Static IPs".
* If it's all gone downhill, restore your backup file on the target 1.13 router:
Code: Select all
cd /etc/config
mv dhcp dhcp.broken && mv dhcp.backup dhcp
Code: Select all
#!/bin/bash
ethers_file="ethers"
hosts_file="hosts"
output_file="output.txt"
# Read MAC address and IP address from /etc/ethers
declare -A mac_ip_map
while read -r line; do
mac=$(echo "$line" | awk '{print $1}')
ip=$(echo "$line" | awk '{print $2}')
mac_ip_map["$mac"]="$ip"
done < "$ethers_file"
# Read IP address and hostname from /etc/hosts
declare -A ip_name_map
while read -r line; do
ip=$(echo "$line" | awk '{print $1}')
name=$(echo "$line" | awk '{print $2}')
ip_name_map["$ip"]="$name"
done < "$hosts_file"
# Generate output file with hostname, MAC, and IP address
echo -n "" > "$output_file"
count=1
for mac in "${!mac_ip_map[@]}"; do
ip="${mac_ip_map[$mac]}"
name="${ip_name_map[$ip]}"
if [ -n "$name" ]; then
output="config host 'static_host_$count'\n"
output+=" option name '$name'\n"
output+=" option mac '$mac'\n"
output+=" option ip '$ip'\n\n"
echo -e "$output" >> "$output_file"
((count++))
fi
done