Changing the metric of an interface permanently

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












This is my routing table when I connect my Android phone via USB to my Raspberry and enable USB-tethering.



$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.42.129 0.0.0.0 UG 204 0 0 usb0
0.0.0.0 192.168.0.1 0.0.0.0 UG 303 0 0 wlan0
192.168.0.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.42.0 0.0.0.0 255.255.255.0 U 204 0 0 usb0


I want wlan0 to be the preferred interface.
So how can I change the metric of one the interfaces permanently?



Also how does Linux decide which metric value it will use for an interface?







share|improve this question




















  • See unix.stackexchange.com/questions/344974/…
    – multithr3at3d
    Dec 25 '17 at 22:24










  • Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
    – MatMis
    Dec 25 '17 at 22:44










  • Well what Linux distribution are you running? It is hard to answer without knowing.
    – multithr3at3d
    Dec 25 '17 at 23:21










  • Raspbian on Raspberry PI 3
    – MatMis
    Dec 25 '17 at 23:22














up vote
1
down vote

favorite
1












This is my routing table when I connect my Android phone via USB to my Raspberry and enable USB-tethering.



$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.42.129 0.0.0.0 UG 204 0 0 usb0
0.0.0.0 192.168.0.1 0.0.0.0 UG 303 0 0 wlan0
192.168.0.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.42.0 0.0.0.0 255.255.255.0 U 204 0 0 usb0


I want wlan0 to be the preferred interface.
So how can I change the metric of one the interfaces permanently?



Also how does Linux decide which metric value it will use for an interface?







share|improve this question




















  • See unix.stackexchange.com/questions/344974/…
    – multithr3at3d
    Dec 25 '17 at 22:24










  • Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
    – MatMis
    Dec 25 '17 at 22:44










  • Well what Linux distribution are you running? It is hard to answer without knowing.
    – multithr3at3d
    Dec 25 '17 at 23:21










  • Raspbian on Raspberry PI 3
    – MatMis
    Dec 25 '17 at 23:22












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





This is my routing table when I connect my Android phone via USB to my Raspberry and enable USB-tethering.



$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.42.129 0.0.0.0 UG 204 0 0 usb0
0.0.0.0 192.168.0.1 0.0.0.0 UG 303 0 0 wlan0
192.168.0.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.42.0 0.0.0.0 255.255.255.0 U 204 0 0 usb0


I want wlan0 to be the preferred interface.
So how can I change the metric of one the interfaces permanently?



Also how does Linux decide which metric value it will use for an interface?







share|improve this question












This is my routing table when I connect my Android phone via USB to my Raspberry and enable USB-tethering.



$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.42.129 0.0.0.0 UG 204 0 0 usb0
0.0.0.0 192.168.0.1 0.0.0.0 UG 303 0 0 wlan0
192.168.0.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.42.0 0.0.0.0 255.255.255.0 U 204 0 0 usb0


I want wlan0 to be the preferred interface.
So how can I change the metric of one the interfaces permanently?



Also how does Linux decide which metric value it will use for an interface?









share|improve this question











share|improve this question




share|improve this question










asked Dec 25 '17 at 22:20









MatMis

4917




4917











  • See unix.stackexchange.com/questions/344974/…
    – multithr3at3d
    Dec 25 '17 at 22:24










  • Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
    – MatMis
    Dec 25 '17 at 22:44










  • Well what Linux distribution are you running? It is hard to answer without knowing.
    – multithr3at3d
    Dec 25 '17 at 23:21










  • Raspbian on Raspberry PI 3
    – MatMis
    Dec 25 '17 at 23:22
















  • See unix.stackexchange.com/questions/344974/…
    – multithr3at3d
    Dec 25 '17 at 22:24










  • Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
    – MatMis
    Dec 25 '17 at 22:44










  • Well what Linux distribution are you running? It is hard to answer without knowing.
    – multithr3at3d
    Dec 25 '17 at 23:21










  • Raspbian on Raspberry PI 3
    – MatMis
    Dec 25 '17 at 23:22















See unix.stackexchange.com/questions/344974/…
– multithr3at3d
Dec 25 '17 at 22:24




See unix.stackexchange.com/questions/344974/…
– multithr3at3d
Dec 25 '17 at 22:24












Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
– MatMis
Dec 25 '17 at 22:44




Sorry, but these answers don't work. 1) I don't have nmcli. 2) /etc/dhcpd.conf does not exist. 3) /etc/NetworkManager/ does also not exist.
– MatMis
Dec 25 '17 at 22:44












Well what Linux distribution are you running? It is hard to answer without knowing.
– multithr3at3d
Dec 25 '17 at 23:21




Well what Linux distribution are you running? It is hard to answer without knowing.
– multithr3at3d
Dec 25 '17 at 23:21












Raspbian on Raspberry PI 3
– MatMis
Dec 25 '17 at 23:22




Raspbian on Raspberry PI 3
– MatMis
Dec 25 '17 at 23:22










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










One of the solutions is to configure settings in /etc/network/interfaces adding default route with a predefined metric:



auto lo
iface lo inet loopback

# Primary interface
auto wlan0
iface wlan0 inet static
address 192.168.0.100
netmask 255.255.255.0
dns-nameservers 192.168.0.1 8.8.8.8
post-up /sbin/ip route add default via 192.168.0.1 dev wlan0 metric 10
post-down /sbin/ip route del default via 192.168.0.1 dev wlan0 metric 10
wpa-ssid <your_SSID>
wpa-psk <your_PSK>


Maybe, you need to add another Wi-Fi options specific to your settings.




Another solution is to change the metric in the /etc/dhcpcd.conf.
According to the dhcpcd manual metric can be assigned to the interface:




metric
Metrics are used to prefer an interface over another one, lowest
wins. dhcpcd will supply a default metric of 200 +
if_nametoindex(3). An extra 100 will be added for wireless
interfaces.



Add these lines to /etc/dhcpcd.conf:



interface wlan0
metric 200

interface usb0
metric 300


And restart dhcpcd and networking services.






share|improve this answer






















  • my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
    – MatMis
    Dec 25 '17 at 23:35










  • Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
    – Gnat
    Dec 25 '17 at 23:40










  • /etc/network/interfaces.d is empty.
    – MatMis
    Dec 25 '17 at 23:44










  • I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
    – MatMis
    Dec 25 '17 at 23:56











  • Can you provide the output of the file /etc/dhcpcd.conf ?
    – Gnat
    Dec 26 '17 at 0:02










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f413031%2fchanging-the-metric-of-an-interface-permanently%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










One of the solutions is to configure settings in /etc/network/interfaces adding default route with a predefined metric:



auto lo
iface lo inet loopback

# Primary interface
auto wlan0
iface wlan0 inet static
address 192.168.0.100
netmask 255.255.255.0
dns-nameservers 192.168.0.1 8.8.8.8
post-up /sbin/ip route add default via 192.168.0.1 dev wlan0 metric 10
post-down /sbin/ip route del default via 192.168.0.1 dev wlan0 metric 10
wpa-ssid <your_SSID>
wpa-psk <your_PSK>


Maybe, you need to add another Wi-Fi options specific to your settings.




Another solution is to change the metric in the /etc/dhcpcd.conf.
According to the dhcpcd manual metric can be assigned to the interface:




metric
Metrics are used to prefer an interface over another one, lowest
wins. dhcpcd will supply a default metric of 200 +
if_nametoindex(3). An extra 100 will be added for wireless
interfaces.



Add these lines to /etc/dhcpcd.conf:



interface wlan0
metric 200

interface usb0
metric 300


And restart dhcpcd and networking services.






share|improve this answer






















  • my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
    – MatMis
    Dec 25 '17 at 23:35










  • Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
    – Gnat
    Dec 25 '17 at 23:40










  • /etc/network/interfaces.d is empty.
    – MatMis
    Dec 25 '17 at 23:44










  • I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
    – MatMis
    Dec 25 '17 at 23:56











  • Can you provide the output of the file /etc/dhcpcd.conf ?
    – Gnat
    Dec 26 '17 at 0:02














up vote
5
down vote



accepted










One of the solutions is to configure settings in /etc/network/interfaces adding default route with a predefined metric:



auto lo
iface lo inet loopback

# Primary interface
auto wlan0
iface wlan0 inet static
address 192.168.0.100
netmask 255.255.255.0
dns-nameservers 192.168.0.1 8.8.8.8
post-up /sbin/ip route add default via 192.168.0.1 dev wlan0 metric 10
post-down /sbin/ip route del default via 192.168.0.1 dev wlan0 metric 10
wpa-ssid <your_SSID>
wpa-psk <your_PSK>


Maybe, you need to add another Wi-Fi options specific to your settings.




Another solution is to change the metric in the /etc/dhcpcd.conf.
According to the dhcpcd manual metric can be assigned to the interface:




metric
Metrics are used to prefer an interface over another one, lowest
wins. dhcpcd will supply a default metric of 200 +
if_nametoindex(3). An extra 100 will be added for wireless
interfaces.



Add these lines to /etc/dhcpcd.conf:



interface wlan0
metric 200

interface usb0
metric 300


And restart dhcpcd and networking services.






share|improve this answer






















  • my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
    – MatMis
    Dec 25 '17 at 23:35










  • Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
    – Gnat
    Dec 25 '17 at 23:40










  • /etc/network/interfaces.d is empty.
    – MatMis
    Dec 25 '17 at 23:44










  • I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
    – MatMis
    Dec 25 '17 at 23:56











  • Can you provide the output of the file /etc/dhcpcd.conf ?
    – Gnat
    Dec 26 '17 at 0:02












up vote
5
down vote



accepted







up vote
5
down vote



accepted






One of the solutions is to configure settings in /etc/network/interfaces adding default route with a predefined metric:



auto lo
iface lo inet loopback

# Primary interface
auto wlan0
iface wlan0 inet static
address 192.168.0.100
netmask 255.255.255.0
dns-nameservers 192.168.0.1 8.8.8.8
post-up /sbin/ip route add default via 192.168.0.1 dev wlan0 metric 10
post-down /sbin/ip route del default via 192.168.0.1 dev wlan0 metric 10
wpa-ssid <your_SSID>
wpa-psk <your_PSK>


Maybe, you need to add another Wi-Fi options specific to your settings.




Another solution is to change the metric in the /etc/dhcpcd.conf.
According to the dhcpcd manual metric can be assigned to the interface:




metric
Metrics are used to prefer an interface over another one, lowest
wins. dhcpcd will supply a default metric of 200 +
if_nametoindex(3). An extra 100 will be added for wireless
interfaces.



Add these lines to /etc/dhcpcd.conf:



interface wlan0
metric 200

interface usb0
metric 300


And restart dhcpcd and networking services.






share|improve this answer














One of the solutions is to configure settings in /etc/network/interfaces adding default route with a predefined metric:



auto lo
iface lo inet loopback

# Primary interface
auto wlan0
iface wlan0 inet static
address 192.168.0.100
netmask 255.255.255.0
dns-nameservers 192.168.0.1 8.8.8.8
post-up /sbin/ip route add default via 192.168.0.1 dev wlan0 metric 10
post-down /sbin/ip route del default via 192.168.0.1 dev wlan0 metric 10
wpa-ssid <your_SSID>
wpa-psk <your_PSK>


Maybe, you need to add another Wi-Fi options specific to your settings.




Another solution is to change the metric in the /etc/dhcpcd.conf.
According to the dhcpcd manual metric can be assigned to the interface:




metric
Metrics are used to prefer an interface over another one, lowest
wins. dhcpcd will supply a default metric of 200 +
if_nametoindex(3). An extra 100 will be added for wireless
interfaces.



Add these lines to /etc/dhcpcd.conf:



interface wlan0
metric 200

interface usb0
metric 300


And restart dhcpcd and networking services.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 26 '17 at 17:34









GAD3R

22.5k154894




22.5k154894










answered Dec 25 '17 at 23:31









Gnat

1315




1315











  • my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
    – MatMis
    Dec 25 '17 at 23:35










  • Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
    – Gnat
    Dec 25 '17 at 23:40










  • /etc/network/interfaces.d is empty.
    – MatMis
    Dec 25 '17 at 23:44










  • I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
    – MatMis
    Dec 25 '17 at 23:56











  • Can you provide the output of the file /etc/dhcpcd.conf ?
    – Gnat
    Dec 26 '17 at 0:02
















  • my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
    – MatMis
    Dec 25 '17 at 23:35










  • Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
    – Gnat
    Dec 25 '17 at 23:40










  • /etc/network/interfaces.d is empty.
    – MatMis
    Dec 25 '17 at 23:44










  • I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
    – MatMis
    Dec 25 '17 at 23:56











  • Can you provide the output of the file /etc/dhcpcd.conf ?
    – Gnat
    Dec 26 '17 at 0:02















my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
– MatMis
Dec 25 '17 at 23:35




my /etc/networking/interfaces looks like this, so can I still add them?: # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d
– MatMis
Dec 25 '17 at 23:35












Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
– Gnat
Dec 25 '17 at 23:40




Could you please show the content of the directory /etc/network/interfaces.d? If there are no interfaces, you can add that config.
– Gnat
Dec 25 '17 at 23:40












/etc/network/interfaces.d is empty.
– MatMis
Dec 25 '17 at 23:44




/etc/network/interfaces.d is empty.
– MatMis
Dec 25 '17 at 23:44












I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
– MatMis
Dec 25 '17 at 23:56





I don't want to have a fixed default gateway and I still want to use dhcp. Do you know any other solution?
– MatMis
Dec 25 '17 at 23:56













Can you provide the output of the file /etc/dhcpcd.conf ?
– Gnat
Dec 26 '17 at 0:02




Can you provide the output of the file /etc/dhcpcd.conf ?
– Gnat
Dec 26 '17 at 0:02












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f413031%2fchanging-the-metric-of-an-interface-permanently%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)