cilix-lab / ubuntu-wrt

Ubuntu Focal for Linksys WRT3200ACM router
21 stars 3 forks source link

Interface numbering without DSA #2

Closed Redferne closed 7 years ago

Redferne commented 7 years ago

Hi,

Is there a solid way of swapping eth0/1 in the no switch config? I really want eth0 as WAN and eth1 as part of the br0 bridge. Please advice 😯

cilix-lab commented 7 years ago

You can achieve what you want by using udev rules. Simple create the file "/etc/udev/rules.d/70-persistent-net.rules" and add some rules to rename interfaces as you'd like. For instance:

# /etc/udev/rules.d/70-persistent-net.rules  
SUBSYSTEM=="net", ATTR{ifindex}=="3", NAME="eth0"  
SUBSYSTEM=="net", ATTR{ifindex}=="2", NAME="eth1"  
SUBSYSTEM=="net", ATTR{ifindex}=="5", NAME="wlan0"  
SUBSYSTEM=="net", ATTR{ifindex}=="6", NAME="wlan1"  
SUBSYSTEM=="net", ATTR{ifindex}=="4", NAME="mlan0"  

That will find each interface by index and name it as defined. Notice the rules use "==" to match the attribute and "=" to set it.
You can find each interface name running cat /sys/class/net/<interface>/ifindex, replacing "\<interface>" for the one you want to get. E.g. cat /sys/class/net/eth0/ifindex will return 2 in my setup.
I think those rules will do what you want, though I've found that if you setup vlans or other stuff, indexes might get screwed up because they are assigned on boot.
Remember to fix all config files and swap eth0/1, if not, network interfaces will probably fail.

Redferne commented 7 years ago

Thanks! Must have tried 10+ combination of which none worked (no network at all). Finally realized I had some weird script in /lib/udev/write_net_rules which probably foiled all my attempts. Had already caved in and given up and rewritten all scripts (Came from McDebian)... :cry: All good now :+1: