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.

5
  • Please show the NM status and the routing table after the cable is connected? Commented Oct 13 at 7:23
  • This Q&A looks like what you're after. Commented Oct 13 at 7:36
  • @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. Commented Oct 13 at 10:07
  • @grawity It seems all I really need to do is automatically run nmcli c up enp0s31f6 whenever the ethernet cable is plugged in. Commented Oct 13 at 10:11
  • In that case please show nmcli con show enp0s31f6 or /etc/NetworkManager/system-connections/enp0s31f6? Commented Oct 13 at 10:11

1 Answer 1

2

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.