Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Modified yesterday
Viewed 27 times
1

I want my Linux laptop to connect to ethernet automatically when the ethernet cable is plugged in. Right now, if the laptop is connected to wifi, it will stay connected to wifi even after the ethernet cable is plugged in.

Here is the output of nmcli -f NAME,UUID,AUTOCONNECT,AUTOCONNECT-PRIORITY c:

NAME                 UUID                                  AUTOCONNECT  AUTOCONNECT-PRIORITY 
MySpectrumWifid2-5G  d0358859-15c5-43a5-a617-617e9735bd5e  yes          0                    
enp0s31f6            08db2aad-a10f-4068-93f1-4fe7f8c902b2  yes          10                   
lo                   01eb66ee-0146-4b4e-94a4-ea5372417450  no           0                    

By using ip route get, I can confirm it still uses the wifi even when the cable is plugged in.

I can force the connection to change by adding low-metric routes using ip route add, but they go away when I unplug the cable.

New contributor
nph is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • Please show the NM status and the routing table after the cable is connected?
    grawity
    –  grawity
    2025-10-13 07:23:45 +00:00
    Commented yesterday
  • This Q&A looks like what you're after.
    vidarlo
    –  vidarlo
    2025-10-13 07:36:03 +00:00
    Commented yesterday
  • @grawity The NM status stays the same after connecting. After disconnecting, the routes involving the ethernet connection are automatically deleted from the routing table. After connecting again, they don't come back, and no other changes are made.
    nph
    –  nph
    2025-10-13 10:07:44 +00:00
    Commented yesterday
  • @grawity It seems all I really need to do is automatically run nmcli c up enp0s31f6 whenever the ethernet cable is plugged in.
    nph
    –  nph
    2025-10-13 10:11:01 +00:00
    Commented yesterday
  • In that case please show nmcli con show enp0s31f6 or /etc/NetworkManager/system-connections/enp0s31f6?
    grawity
    –  grawity
    2025-10-13 10:11:05 +00:00
    Commented yesterday

1 Answer 1

1

I've written a bash script to help with this: https://github.com/waltinator/net-o-matic It watches the connection, and when the connection drops, does a user-specified thing to try to reconnect or do something else.

You could adapt it to watch for UP events, and ...

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.