Keeping interface names while swapping radio cards

I’m looking for a way to retain the interface name when I have to swap out a bad radio card.

The first time I did it, I noticed that the interface came up as some generic name, and every other part of the configuration that referenced the old interface was “(unknown)”. When I renamed the generic name to the previous interface name, it didn’t affect the other portions of the configuration, and I had to rename all of them one by one.

The next time, I thought I would be clever, and just before shutting down the router I changed the MAC address of the bad interface to the MAC address of the card I was about to insert, thinking I could fool the router into believing nothing had happened. It didn’t work.

How does everybody else solve this problem? Don’t tell me everybody hand-corrects the entire configuration after replacing a radio card?

Yup. Sadly I can’t see any way to keep the config.

I don’t have that issue with radio cards, but with short lived VLAN interfaces. You bring it back with the exact same configuration (you can even copy/paste the previous config, and these are virtual!) and all references are dead. Probably because on generation/insert a new unique key is generated in the background.

I don’t see any way in RouterOS to work around that.

im almost done with a script that will wrap up the interface in a dummy bridge, let you swap the card, and then unwraps the config back to the physical interface. Lame I know. Is routeros using udev?

since its been a year or more since I’ve worked on it, I am going to share it here and hopefully someone can finish it for me. Once done we can make a wiki page for it. Probably 2 scripts, one for before and one for after.

# Written by Sam Norris
# Allows swapping of interfaces without the hassle of reconfiguring everything.
# --- BEFORE ---
#0.  Make a backup : )
#1.  Find all real interfaces
#2.  Add new bridge interfaces
#3.  Add real interface into corresponding bridge interface
#4.  Reconfigure IP addresses
#5.  Reconfigure Firewall Filters
#6.  Reconfigure NAT Translations
#7.  Reconfigure Mangle Rules
# --- BEFORE ---

# Make a backup
/system backup save name="before-interface-swap"

# Now loop thru each real interface
:foreach realinterface in=[/interface ethernet find] do={

	# Process some vars for speed.
	:local OldName [/interface ethernet get $realinterface name]
	:local NewName ("$OldName" . "-temp")

	# Add an empty bridge for each real interface we find.
	/interface bridge add name="$NewName" comment=[/interface ethernet get $realinterface mac-address]
	
	# Add the interface to its temporary bridge.
	/interface bridge port add interface="$OldName" bridge="$NewName"

	# Change the IP ADDRESSES from the real interface to the temporary bridge.
	:foreach ipaddr in=[/ip address find interface="$OldName" dynamic=no] do={
		/ip address set $ipaddr interface="$NewName"
	}

	# -- FIREWALL FILTERS --
	:foreach rule in=[/ip firewall filter find in-interface=$realinterface] do={
		/ip firewall filter set $rule in-interface="$NewName"
	}
	:foreach rule in=[/ip firewall filter find out-interface=$realinterface] do={
		/ip firewall filter set $rule out-interface="$NewName"
	}

	# -- NAT TRANSLATIONS --
	:foreach rule in=[/ip firewall nat find in-interface=$realinterface] do={
		/ip firewall nat set $rule in-interface="$NewName"
	}
	:foreach rule in=[/ip firewall nat find out-interface=$realinterface] do={
		/ip firewall nat set $rule out-interface="$NewName"
	}

	# -- MANGLE RULES --
	:foreach rule in=[/ip firewall mangle find in-interface=$realinterface] do={
		/ip firewall mangle set $rule in-interface="$NewName"
	}
	:foreach rule in=[/ip firewall mangle find out-interface=$realinterface] do={
		/ip firewall mangle set $rule out-interface="$NewName"
	}

	# -- QUEUES --
	:foreach queue in=[/queue tree find parent="$OldName"] do={
		/queue tree set $queue parent="$NewName"
	}
	:foreach queue in=[/queue simple find interface="$OldName"] do={
		/queue simple set $queue interface="$NewName"
	}

	# -- DHCP SERVERS --
	:foreach rule in=[/ip dhcp-server find interface="$OldName"] do={
		/ip dhcp-server set $rule interface="$NewName"
	}

}

# --- AFTER ---
#1.  Find all bridge interfaces

does comment-$MAC$ exist in system now?

if so,
	set name on interface to original
	change interface name to original ?  (strip-temp) ?
	reconfigure rules
	remove bridge ports
	remove bridges


if not, leave in bridge ?