The easiest and the right way to do this is by editing /etc/network/interfaces
.
(If this file does not exist, you can create it.)
Here is a simple example of /etc/network/interfaces
:
auto lo eth0
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
metric 700
Restart networking using service networking restart
for the changes to take place.
Ref: Section 5.7.2. The ifmetric package of Debian Manual
The following sets the eth0 interface to be preferred over the wlan0 interface.
Install the ifmetric package.
Add an option line with "metric 0" just below the "iface eth0 inet dhcp" line in "/etc/network/interfaces".
Add an option line with "metric 1" just below the "iface wlan0 inet dhcp" line in "/etc/network/interfaces".
Extra Note:
auto <interface1> <interface2>
starts interfaces on start of the system.allow-hotplug <interface>
starts the interface on hotplug event.