Changing the metric of an interface permanently

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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?
networking routing
add a comment |Â
up vote
1
down vote
favorite
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?
networking routing
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
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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?
networking routing
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?
networking routing
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
add a comment |Â
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
add a comment |Â
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.
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
 |Â
show 6 more comments
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.
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
 |Â
show 6 more comments
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.
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
 |Â
show 6 more comments
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.
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.
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
 |Â
show 6 more comments
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
 |Â
show 6 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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