Hi Everyone,
My laptop has both Ethernet and wireless cards, managed by the em(4) and iwn(4) drivers, the latter being associated with wlan0. Normally Ethernet is not connected, and I'm using wifi only. Sometimes I need to transfer a large file on my subnetwork, and for this I'd like to plug in an Ethernet cable, switch to Ethernet, do the transfer and switch back to wifi. So I shut down wlan0, bring up em0, obtain an IP for it, remove the old default route from the routing table, and add the new route:
# ifconfig wlan0 down
# ifconfig em0 up
# dhclient em0
# route delete default
# route add default 192.168.1.1
After this my wired connection works. The problem happens when I try to switch back using the same steps, swapping em0 for wlan0. This time the routing table stubbornly insists on keeping em0 for the default destination, even after I bring the interface down (it still has an IP address!)
What's the right way of doing this? I find it strange that route won't let us select an interface when adding routes. What happens when, like in this case, there are two interfaces, both having an IP address?
My laptop has both Ethernet and wireless cards, managed by the em(4) and iwn(4) drivers, the latter being associated with wlan0. Normally Ethernet is not connected, and I'm using wifi only. Sometimes I need to transfer a large file on my subnetwork, and for this I'd like to plug in an Ethernet cable, switch to Ethernet, do the transfer and switch back to wifi. So I shut down wlan0, bring up em0, obtain an IP for it, remove the old default route from the routing table, and add the new route:
# ifconfig wlan0 down
# ifconfig em0 up
# dhclient em0
# route delete default
# route add default 192.168.1.1
After this my wired connection works. The problem happens when I try to switch back using the same steps, swapping em0 for wlan0. This time the routing table stubbornly insists on keeping em0 for the default destination, even after I bring the interface down (it still has an IP address!)
What's the right way of doing this? I find it strange that route won't let us select an interface when adding routes. What happens when, like in this case, there are two interfaces, both having an IP address?