How can I make ethernet take precedence over wifi on Ubuntu 18.04? The Next CEO of Stack OverflowUsing ip addr instead of ifconfig reports “RTNETLINK answers: File exists” on DebianHow to determine eth0 gateway address when it is not the default gateway?Linux server able to wget but not able to pingUse a virtual machines network adapter as hosts default network adapterConnect two Networks on same computerModify routing table route outbound packets (except ssh) through WiFi interfaceDirect connection Centos7 (loadbalance) to QNAP (trunk)Avoid setting a default route for a DHCP managed interfaceHow to route traffic from ethernet to a tun device (create a VPNed ethernet port)Configuring Linux Mint as a Gateway
MessageLevel in QGIS3
What connection does MS Office have to Netscape Navigator?
Workaholic Formal/Informal
What is the result of assigning to std::vector<T>::begin()?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Received an invoice from my ex-employer billing me for training; how to handle?
How to count occurrences of text in a file?
At which OSI layer a user-generated data resides?
Sending manuscript to multiple publishers
Why does standard notation not preserve intervals (visually)
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Why do airplanes bank sharply to the right after air-to-air refueling?
What's the best way to handle refactoring a big file?
If the heap is initialized for security, then why is the stack uninitialized?
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Non-deterministic sum of floats
How to make a variable always equal to the result of some calculations?
How to solve a differential equation with a term to a power?
Make solar eclipses exceedingly rare, but still have new moons
Can we say or write : "No, it'sn't"?
Is HostGator storing my password in plaintext?
Is it possible to search for a directory/file combination?
Different harmonic changes implied by a simple descending scale
How can I make ethernet take precedence over wifi on Ubuntu 18.04?
The Next CEO of Stack OverflowUsing ip addr instead of ifconfig reports “RTNETLINK answers: File exists” on DebianHow to determine eth0 gateway address when it is not the default gateway?Linux server able to wget but not able to pingUse a virtual machines network adapter as hosts default network adapterConnect two Networks on same computerModify routing table route outbound packets (except ssh) through WiFi interfaceDirect connection Centos7 (loadbalance) to QNAP (trunk)Avoid setting a default route for a DHCP managed interfaceHow to route traffic from ethernet to a tun device (create a VPNed ethernet port)Configuring Linux Mint as a Gateway
Goal
Let ethernet take precedence over wireless when ethernet cable is plugged in
Method
After having done a fair amount of Googling and reading I've come to a point where I believe what I should be doing is something along the lines of
nmcli connection modify [id-of-ethernet-interface] ipv4.route-metric 200
nmcli connection modify [id-of-ethernet-interface] ipv6.route-metric 200
where 200 is a lower value than the wireless metric, to have the ethernet take precedence over the wireless.
Results
What perplexes me is the reports I get from route -n after I have executed the above commands and rebooted (for good measure), and the fact that this doesn't seem to amount to reaching my goal
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 123.456.89.1 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The numbers add up with regards to my command execution, but for the lines that say
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The first line has 20 prefixed before the 200 value I set. This keeps being consistently applied based on what I run; If I change the value for the metric through nmcli to say 500, route -n will report 20500. Why does this happen? It sure doesn't look right, since I stated I wanted either 200 or 500, not 20200 and 20500.
The second line has a metric value that I have no idea where it comes from, and I can't seem to affect it at all. If anyone can shed light on this, I'm grateful.
It doesn't look like these commands end up in anything tangible, other than affecting the metrics; I cannot tell that that ethernet is taking precedence, so I assume it is not.
Other findings
What I have found curious, and seem to be working to some extent, is the use of $ sudo ifmetric enp0s31f6 200. This does two to three things;
- It affects the metric of the interface (
route -nreports all lines with the Ifaceenp0s31f6to have the value 200) - It affects the UI in Ubuntu (In the upper right corner I will see a visual switch between ethernet and wireless icons switching, depending on the metric values I provide in the
ifmetriccommand) - It sometimes throws a
NETLINK: Error: File existserror at me. Subsequent executions of the same command may or may not result in this error
Some system info
- EliteBook 850 G5
- Ubuntu 18.04
- Ubuntu install made through letting the installer use the entire disc, enabled encryption, enabled 3rd party downloads for drivers, etc.
Update #1
$ nmcli c show
NAME UUID TYPE DEVICE
Wired connection 2 [n/a] ethernet enp0s31f6
WiFi1 [n/a] wifi wlp1s0
$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 [n/a] 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 [n/a] 0.0.0.0 UG 20200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
[n/a] 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
ubuntu networking
migrated from serverfault.com Jan 16 at 15:55
This question came from our site for system and network administrators.
add a comment |
Goal
Let ethernet take precedence over wireless when ethernet cable is plugged in
Method
After having done a fair amount of Googling and reading I've come to a point where I believe what I should be doing is something along the lines of
nmcli connection modify [id-of-ethernet-interface] ipv4.route-metric 200
nmcli connection modify [id-of-ethernet-interface] ipv6.route-metric 200
where 200 is a lower value than the wireless metric, to have the ethernet take precedence over the wireless.
Results
What perplexes me is the reports I get from route -n after I have executed the above commands and rebooted (for good measure), and the fact that this doesn't seem to amount to reaching my goal
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 123.456.89.1 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The numbers add up with regards to my command execution, but for the lines that say
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The first line has 20 prefixed before the 200 value I set. This keeps being consistently applied based on what I run; If I change the value for the metric through nmcli to say 500, route -n will report 20500. Why does this happen? It sure doesn't look right, since I stated I wanted either 200 or 500, not 20200 and 20500.
The second line has a metric value that I have no idea where it comes from, and I can't seem to affect it at all. If anyone can shed light on this, I'm grateful.
It doesn't look like these commands end up in anything tangible, other than affecting the metrics; I cannot tell that that ethernet is taking precedence, so I assume it is not.
Other findings
What I have found curious, and seem to be working to some extent, is the use of $ sudo ifmetric enp0s31f6 200. This does two to three things;
- It affects the metric of the interface (
route -nreports all lines with the Ifaceenp0s31f6to have the value 200) - It affects the UI in Ubuntu (In the upper right corner I will see a visual switch between ethernet and wireless icons switching, depending on the metric values I provide in the
ifmetriccommand) - It sometimes throws a
NETLINK: Error: File existserror at me. Subsequent executions of the same command may or may not result in this error
Some system info
- EliteBook 850 G5
- Ubuntu 18.04
- Ubuntu install made through letting the installer use the entire disc, enabled encryption, enabled 3rd party downloads for drivers, etc.
Update #1
$ nmcli c show
NAME UUID TYPE DEVICE
Wired connection 2 [n/a] ethernet enp0s31f6
WiFi1 [n/a] wifi wlp1s0
$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 [n/a] 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 [n/a] 0.0.0.0 UG 20200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
[n/a] 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
ubuntu networking
migrated from serverfault.com Jan 16 at 15:55
This question came from our site for system and network administrators.
Ethernet should be preferred by default. Strange. Is the output ofnmcli c showthe same asroute -n's output?
– Tommiie
Jan 7 at 14:11
See my updated question.
– shellström
Jan 16 at 13:32
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37
add a comment |
Goal
Let ethernet take precedence over wireless when ethernet cable is plugged in
Method
After having done a fair amount of Googling and reading I've come to a point where I believe what I should be doing is something along the lines of
nmcli connection modify [id-of-ethernet-interface] ipv4.route-metric 200
nmcli connection modify [id-of-ethernet-interface] ipv6.route-metric 200
where 200 is a lower value than the wireless metric, to have the ethernet take precedence over the wireless.
Results
What perplexes me is the reports I get from route -n after I have executed the above commands and rebooted (for good measure), and the fact that this doesn't seem to amount to reaching my goal
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 123.456.89.1 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The numbers add up with regards to my command execution, but for the lines that say
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The first line has 20 prefixed before the 200 value I set. This keeps being consistently applied based on what I run; If I change the value for the metric through nmcli to say 500, route -n will report 20500. Why does this happen? It sure doesn't look right, since I stated I wanted either 200 or 500, not 20200 and 20500.
The second line has a metric value that I have no idea where it comes from, and I can't seem to affect it at all. If anyone can shed light on this, I'm grateful.
It doesn't look like these commands end up in anything tangible, other than affecting the metrics; I cannot tell that that ethernet is taking precedence, so I assume it is not.
Other findings
What I have found curious, and seem to be working to some extent, is the use of $ sudo ifmetric enp0s31f6 200. This does two to three things;
- It affects the metric of the interface (
route -nreports all lines with the Ifaceenp0s31f6to have the value 200) - It affects the UI in Ubuntu (In the upper right corner I will see a visual switch between ethernet and wireless icons switching, depending on the metric values I provide in the
ifmetriccommand) - It sometimes throws a
NETLINK: Error: File existserror at me. Subsequent executions of the same command may or may not result in this error
Some system info
- EliteBook 850 G5
- Ubuntu 18.04
- Ubuntu install made through letting the installer use the entire disc, enabled encryption, enabled 3rd party downloads for drivers, etc.
Update #1
$ nmcli c show
NAME UUID TYPE DEVICE
Wired connection 2 [n/a] ethernet enp0s31f6
WiFi1 [n/a] wifi wlp1s0
$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 [n/a] 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 [n/a] 0.0.0.0 UG 20200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
[n/a] 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
ubuntu networking
Goal
Let ethernet take precedence over wireless when ethernet cable is plugged in
Method
After having done a fair amount of Googling and reading I've come to a point where I believe what I should be doing is something along the lines of
nmcli connection modify [id-of-ethernet-interface] ipv4.route-metric 200
nmcli connection modify [id-of-ethernet-interface] ipv6.route-metric 200
where 200 is a lower value than the wireless metric, to have the ethernet take precedence over the wireless.
Results
What perplexes me is the reports I get from route -n after I have executed the above commands and rebooted (for good measure), and the fact that this doesn't seem to amount to reaching my goal
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 123.456.89.1 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
123.456.89.0 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The numbers add up with regards to my command execution, but for the lines that say
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6
654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The first line has 20 prefixed before the 200 value I set. This keeps being consistently applied based on what I run; If I change the value for the metric through nmcli to say 500, route -n will report 20500. Why does this happen? It sure doesn't look right, since I stated I wanted either 200 or 500, not 20200 and 20500.
The second line has a metric value that I have no idea where it comes from, and I can't seem to affect it at all. If anyone can shed light on this, I'm grateful.
It doesn't look like these commands end up in anything tangible, other than affecting the metrics; I cannot tell that that ethernet is taking precedence, so I assume it is not.
Other findings
What I have found curious, and seem to be working to some extent, is the use of $ sudo ifmetric enp0s31f6 200. This does two to three things;
- It affects the metric of the interface (
route -nreports all lines with the Ifaceenp0s31f6to have the value 200) - It affects the UI in Ubuntu (In the upper right corner I will see a visual switch between ethernet and wireless icons switching, depending on the metric values I provide in the
ifmetriccommand) - It sometimes throws a
NETLINK: Error: File existserror at me. Subsequent executions of the same command may or may not result in this error
Some system info
- EliteBook 850 G5
- Ubuntu 18.04
- Ubuntu install made through letting the installer use the entire disc, enabled encryption, enabled 3rd party downloads for drivers, etc.
Update #1
$ nmcli c show
NAME UUID TYPE DEVICE
Wired connection 2 [n/a] ethernet enp0s31f6
WiFi1 [n/a] wifi wlp1s0
$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 [n/a] 0.0.0.0 UG 600 0 0 wlp1s0
0.0.0.0 [n/a] 0.0.0.0 UG 20200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6
[n/a] 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0
[n/a] 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
ubuntu networking
ubuntu networking
asked Nov 29 '18 at 9:38
shellström
migrated from serverfault.com Jan 16 at 15:55
This question came from our site for system and network administrators.
migrated from serverfault.com Jan 16 at 15:55
This question came from our site for system and network administrators.
Ethernet should be preferred by default. Strange. Is the output ofnmcli c showthe same asroute -n's output?
– Tommiie
Jan 7 at 14:11
See my updated question.
– shellström
Jan 16 at 13:32
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37
add a comment |
Ethernet should be preferred by default. Strange. Is the output ofnmcli c showthe same asroute -n's output?
– Tommiie
Jan 7 at 14:11
See my updated question.
– shellström
Jan 16 at 13:32
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37
Ethernet should be preferred by default. Strange. Is the output of
nmcli c show the same as route -n's output?– Tommiie
Jan 7 at 14:11
Ethernet should be preferred by default. Strange. Is the output of
nmcli c show the same as route -n's output?– Tommiie
Jan 7 at 14:11
See my updated question.
– shellström
Jan 16 at 13:32
See my updated question.
– shellström
Jan 16 at 13:32
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37
add a comment |
1 Answer
1
active
oldest
votes
You have stacked problems here:
- Your cable LAN and wireless LAN are a bridge to the same subnet
123.456.89.0/24 - You will have two default gateways if you connect the same time at those networks(this can be solved with some advanced routing an
ip rules) - Those gateways have THE SAME ADDRESS, since you have a bridge between wifi and cabled connection.
Maybe you should rely on external scripts to auto deactivate wifi when ethernet is plugged in like this one:
- Automatically switch between WiFi and Ethernet
Create the script /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. Contents:
#!/usr/bin/env bash
name_tag="wifi-wired-exclusive"
syslog_tag="$name_tag"
skip_filename="/etc/NetworkManager/.$name_tag"
if [ -f "$skip_filename" ]; then
exit 0
fi
interface="$1"
iface_mode="$2"
iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2)
iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3)
logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode"
enable_wifi()
logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..."
nmcli radio wifi on
disable_wifi()
logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected."
nmcli radio wifi off
if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then
enable_wifi
elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then
disable_wifi
fi
To disable the script, just execute touch /etc/NetworkManager/.wifi-wired-exclusive
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494864%2fhow-can-i-make-ethernet-take-precedence-over-wifi-on-ubuntu-18-04%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have stacked problems here:
- Your cable LAN and wireless LAN are a bridge to the same subnet
123.456.89.0/24 - You will have two default gateways if you connect the same time at those networks(this can be solved with some advanced routing an
ip rules) - Those gateways have THE SAME ADDRESS, since you have a bridge between wifi and cabled connection.
Maybe you should rely on external scripts to auto deactivate wifi when ethernet is plugged in like this one:
- Automatically switch between WiFi and Ethernet
Create the script /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. Contents:
#!/usr/bin/env bash
name_tag="wifi-wired-exclusive"
syslog_tag="$name_tag"
skip_filename="/etc/NetworkManager/.$name_tag"
if [ -f "$skip_filename" ]; then
exit 0
fi
interface="$1"
iface_mode="$2"
iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2)
iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3)
logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode"
enable_wifi()
logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..."
nmcli radio wifi on
disable_wifi()
logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected."
nmcli radio wifi off
if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then
enable_wifi
elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then
disable_wifi
fi
To disable the script, just execute touch /etc/NetworkManager/.wifi-wired-exclusive
add a comment |
You have stacked problems here:
- Your cable LAN and wireless LAN are a bridge to the same subnet
123.456.89.0/24 - You will have two default gateways if you connect the same time at those networks(this can be solved with some advanced routing an
ip rules) - Those gateways have THE SAME ADDRESS, since you have a bridge between wifi and cabled connection.
Maybe you should rely on external scripts to auto deactivate wifi when ethernet is plugged in like this one:
- Automatically switch between WiFi and Ethernet
Create the script /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. Contents:
#!/usr/bin/env bash
name_tag="wifi-wired-exclusive"
syslog_tag="$name_tag"
skip_filename="/etc/NetworkManager/.$name_tag"
if [ -f "$skip_filename" ]; then
exit 0
fi
interface="$1"
iface_mode="$2"
iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2)
iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3)
logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode"
enable_wifi()
logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..."
nmcli radio wifi on
disable_wifi()
logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected."
nmcli radio wifi off
if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then
enable_wifi
elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then
disable_wifi
fi
To disable the script, just execute touch /etc/NetworkManager/.wifi-wired-exclusive
add a comment |
You have stacked problems here:
- Your cable LAN and wireless LAN are a bridge to the same subnet
123.456.89.0/24 - You will have two default gateways if you connect the same time at those networks(this can be solved with some advanced routing an
ip rules) - Those gateways have THE SAME ADDRESS, since you have a bridge between wifi and cabled connection.
Maybe you should rely on external scripts to auto deactivate wifi when ethernet is plugged in like this one:
- Automatically switch between WiFi and Ethernet
Create the script /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. Contents:
#!/usr/bin/env bash
name_tag="wifi-wired-exclusive"
syslog_tag="$name_tag"
skip_filename="/etc/NetworkManager/.$name_tag"
if [ -f "$skip_filename" ]; then
exit 0
fi
interface="$1"
iface_mode="$2"
iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2)
iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3)
logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode"
enable_wifi()
logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..."
nmcli radio wifi on
disable_wifi()
logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected."
nmcli radio wifi off
if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then
enable_wifi
elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then
disable_wifi
fi
To disable the script, just execute touch /etc/NetworkManager/.wifi-wired-exclusive
You have stacked problems here:
- Your cable LAN and wireless LAN are a bridge to the same subnet
123.456.89.0/24 - You will have two default gateways if you connect the same time at those networks(this can be solved with some advanced routing an
ip rules) - Those gateways have THE SAME ADDRESS, since you have a bridge between wifi and cabled connection.
Maybe you should rely on external scripts to auto deactivate wifi when ethernet is plugged in like this one:
- Automatically switch between WiFi and Ethernet
Create the script /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. Contents:
#!/usr/bin/env bash
name_tag="wifi-wired-exclusive"
syslog_tag="$name_tag"
skip_filename="/etc/NetworkManager/.$name_tag"
if [ -f "$skip_filename" ]; then
exit 0
fi
interface="$1"
iface_mode="$2"
iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2)
iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3)
logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode"
enable_wifi()
logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..."
nmcli radio wifi on
disable_wifi()
logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected."
nmcli radio wifi off
if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then
enable_wifi
elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then
disable_wifi
fi
To disable the script, just execute touch /etc/NetworkManager/.wifi-wired-exclusive
answered 2 days ago
nwildnernwildner
14.9k34481
14.9k34481
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494864%2fhow-can-i-make-ethernet-take-precedence-over-wifi-on-ubuntu-18-04%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Ethernet should be preferred by default. Strange. Is the output of
nmcli c showthe same asroute -n's output?– Tommiie
Jan 7 at 14:11
See my updated question.
– shellström
Jan 16 at 13:32
Please update your question with those result instead of dumping them in a comment.
– Tommiie
Jan 16 at 13:34
Yeah, I realised pretty fast, the dump into the comments weren't gonna work out. I'm making amendments to the edit. Give me 1 more minute, and you'll have the complete output. It's done.
– shellström
Jan 16 at 13:37