After read http://vonger.cn/?p=1880,
I believe there is a more elegant way to disable unused ethernet ports.
The kernel driver of rt305x switch has implemented the featrure, so we can disable ports via `swconfig`:
First we can probe switches:
- Code: Select all
root@OpenWrt:~# swconfig list
Found: switch0 - rt305x
Show attributes of switch0:
- Code: Select all
root@OpenWrt:~# swconfig dev switch0 show
Port 0:
disable: 0
....
Port 1:
disable: 0
....
Disable ports:
- Code: Select all
root@OpenWrt:~# swconfig dev switch0 port 0 set disable 1
root@OpenWrt:~# swconfig dev switch0 port 1 set disable 1
root@OpenWrt:~# swconfig dev switch0 port 2 set disable 1
root@OpenWrt:~# swconfig dev switch0 port 3 set disable 1
root@OpenWrt:~# swconfig dev switch0 set apply
Show attributes again:
- Code: Select all
root@OpenWrt:~# swconfig dev switch0 show
Port 0:
disable: 1
....
Port 1:
disable: 1
....
We can see port0~3 have been disabled.
This way is more reliable because the kernel driver knows the status of switch ports.
Note that the configuration will restrore to the enabled mode when type `/etc/init.d/network restart`,
to make the configuration persist, add the following line to `/etc/config/network`:
- Code: Select all
config switch_port
option device 'switch0'
option port '0'
option disable '1'
config switch_port
option device 'switch0'
option port '1'
option disable '1'
config switch_port
option device 'switch0'
option port '2'
option disable '1'
config switch_port
option device 'switch0'
option port '3'
option disable '1'