Set up autoconnect to hot-spot only when ethernet connection
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
7
down vote
favorite
I currently switch between the following two set-ups on a daily basis:
1) Being connected to the internet via a WiFi network.
2) Having my (Ubuntu 16.04) laptop connected to the internet via a wired connection, then sharing this connection with my other devices through the built-in hot-spot functionality of Ubuntu.
At the moment, switching from 1 to 2 requires me to manually go through the "connect to hidden network" dialogue in the Network Manager; similarly switching from 2 to 1 requires me to manually disconnect from the hotspot and connect to the WiFi network. It's not a lot of work, but I do it often enough that I would like to have it be automated.
It is not as simple as enabling autoconnect for the hotspot, since then it overrides the autoconnect functionality of other networks instead of connecting me to a WiFi network when I am not connected via a wired connection, and I end up with a hot-spot but no internet. So I need a solution which:
- connects me to the hot-spot whenever I am connected to the internet via a wired connection.
- disconnects me from the hot-spot when there is no ethernet connection.
- autoconnects me to one of the networks with autoconnect=true whenever they are available and there is no ethernet connection.
A full explanation on how to do this would be great, but a reference to a good (non-expert) manual for setting up these kinds of rules would also be very much appreciated.
networking wireless network-manager ethernet hot-spot
add a comment |Â
up vote
7
down vote
favorite
I currently switch between the following two set-ups on a daily basis:
1) Being connected to the internet via a WiFi network.
2) Having my (Ubuntu 16.04) laptop connected to the internet via a wired connection, then sharing this connection with my other devices through the built-in hot-spot functionality of Ubuntu.
At the moment, switching from 1 to 2 requires me to manually go through the "connect to hidden network" dialogue in the Network Manager; similarly switching from 2 to 1 requires me to manually disconnect from the hotspot and connect to the WiFi network. It's not a lot of work, but I do it often enough that I would like to have it be automated.
It is not as simple as enabling autoconnect for the hotspot, since then it overrides the autoconnect functionality of other networks instead of connecting me to a WiFi network when I am not connected via a wired connection, and I end up with a hot-spot but no internet. So I need a solution which:
- connects me to the hot-spot whenever I am connected to the internet via a wired connection.
- disconnects me from the hot-spot when there is no ethernet connection.
- autoconnects me to one of the networks with autoconnect=true whenever they are available and there is no ethernet connection.
A full explanation on how to do this would be great, but a reference to a good (non-expert) manual for setting up these kinds of rules would also be very much appreciated.
networking wireless network-manager ethernet hot-spot
1
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look intopost-up
of the/etc/network/interfaces
context, there is a great overview here.post-up
basically just calls commands, or scripts, after an interface comes up.
â Robert Riedl
Mar 9 at 8:07
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I currently switch between the following two set-ups on a daily basis:
1) Being connected to the internet via a WiFi network.
2) Having my (Ubuntu 16.04) laptop connected to the internet via a wired connection, then sharing this connection with my other devices through the built-in hot-spot functionality of Ubuntu.
At the moment, switching from 1 to 2 requires me to manually go through the "connect to hidden network" dialogue in the Network Manager; similarly switching from 2 to 1 requires me to manually disconnect from the hotspot and connect to the WiFi network. It's not a lot of work, but I do it often enough that I would like to have it be automated.
It is not as simple as enabling autoconnect for the hotspot, since then it overrides the autoconnect functionality of other networks instead of connecting me to a WiFi network when I am not connected via a wired connection, and I end up with a hot-spot but no internet. So I need a solution which:
- connects me to the hot-spot whenever I am connected to the internet via a wired connection.
- disconnects me from the hot-spot when there is no ethernet connection.
- autoconnects me to one of the networks with autoconnect=true whenever they are available and there is no ethernet connection.
A full explanation on how to do this would be great, but a reference to a good (non-expert) manual for setting up these kinds of rules would also be very much appreciated.
networking wireless network-manager ethernet hot-spot
I currently switch between the following two set-ups on a daily basis:
1) Being connected to the internet via a WiFi network.
2) Having my (Ubuntu 16.04) laptop connected to the internet via a wired connection, then sharing this connection with my other devices through the built-in hot-spot functionality of Ubuntu.
At the moment, switching from 1 to 2 requires me to manually go through the "connect to hidden network" dialogue in the Network Manager; similarly switching from 2 to 1 requires me to manually disconnect from the hotspot and connect to the WiFi network. It's not a lot of work, but I do it often enough that I would like to have it be automated.
It is not as simple as enabling autoconnect for the hotspot, since then it overrides the autoconnect functionality of other networks instead of connecting me to a WiFi network when I am not connected via a wired connection, and I end up with a hot-spot but no internet. So I need a solution which:
- connects me to the hot-spot whenever I am connected to the internet via a wired connection.
- disconnects me from the hot-spot when there is no ethernet connection.
- autoconnects me to one of the networks with autoconnect=true whenever they are available and there is no ethernet connection.
A full explanation on how to do this would be great, but a reference to a good (non-expert) manual for setting up these kinds of rules would also be very much appreciated.
networking wireless network-manager ethernet hot-spot
networking wireless network-manager ethernet hot-spot
edited Mar 9 at 12:16
asked Mar 4 at 12:57
Bib-lost
141112
141112
1
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look intopost-up
of the/etc/network/interfaces
context, there is a great overview here.post-up
basically just calls commands, or scripts, after an interface comes up.
â Robert Riedl
Mar 9 at 8:07
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18
add a comment |Â
1
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look intopost-up
of the/etc/network/interfaces
context, there is a great overview here.post-up
basically just calls commands, or scripts, after an interface comes up.
â Robert Riedl
Mar 9 at 8:07
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18
1
1
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look into
post-up
of the /etc/network/interfaces
context, there is a great overview here. post-up
basically just calls commands, or scripts, after an interface comes up.â Robert Riedl
Mar 9 at 8:07
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look into
post-up
of the /etc/network/interfaces
context, there is a great overview here. post-up
basically just calls commands, or scripts, after an interface comes up.â Robert Riedl
Mar 9 at 8:07
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
It's my understanding that when you plug in the Ethernet cable that trumps the wifi connection and the wifi connection drops automatically. In similar fashion, disconnecting the Ethernet cable auto connects to your preferred wifi (provided of course that you have the box checked to auto connect to that Wifi network on the general tab of network manager. Tested on a default install of Ubuntu 16.04.3
So if I'm understanding you correctly you just want to automatically start the hotspot service on your laptop when the Ethernet cable is connected and disable the service when the Ethernet cable is disconnected.
This should be fairly simple to do with a bash script and nmcli
'nmcli' is a powerful networknig tool that allows you to bring connections up and down at will and obtain tons of relevant information.
To find out what connections you will be scripting for simply run nmcli -t monitor| grep primary
when connected via wifi and plug in your Ethernet cable. The connections you are interested in bringing up and down with nmcli
will be those surrounded by '
s Example: 'Wired connection 1' the logic is that when 'Connection' is connected bring up the hotspot (you may find it necessary to use the command sleep
or utilize the -w
switch to make nmcli
in your script wait for a specified number of seconds for a command to complete before issuing the next.
Bringing a connection down is as simple as nmcli 'connection name' down
and bringing one up is nmcli 'connection name' up
Note: For full control via the script you may need to actually disable the automatically connect option at least for your wifi connection in Network manager as it will attempt to auto-connect whenever it's available and can interfere with what you are attempting to accomplish. Excerpt from man nmcli
:
There may be multiple connections that apply
to a device, but only one of them can be active on that device at any
given time. The additional connections can be used to allow quick
switching between different networks and configurations.
So once you've determined that your Ethernet is connected you can issue the commands to bring the wifi connection down Example: nmcli connection my-wifi down
and then the hotspot connection up Example: nmcli connection my-hotspot up
For more on how to automatically run scripts based on network connection see this. For more detail about 'nmcli' check the man page. And here's info on how to create a hotspot.
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down withnmcli connection my-wifi down
it never reconnects?
â Elder Geek
Mar 15 at 16:35
 |Â
show 4 more comments
up vote
0
down vote
Solution which did it for me (found with the help of Elder Geek).
I kept autoconnect on for all networks I want to automatically connect to, but off for the hot-spot. I then put the following script (with the right permissions as described on this Wiki page) in the folder /etc/NetworkManager/dispatcher.d
!/bin/bash
interf=$1
state=$2
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
nmcli connection up 'my-hotspot'
fi
if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
nmcli connection down 'my-hotspot'
fi
This works very well so far; automatic connection to the hotspot whenever the ethernet cable is plugged in or even when the computer boots or wakes with the ethernet cable plugged in. Automatic deconnection from hot-spot whenever ethernet cable is pulled out, followed by automatic connection to available WiFi networks.
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
It's my understanding that when you plug in the Ethernet cable that trumps the wifi connection and the wifi connection drops automatically. In similar fashion, disconnecting the Ethernet cable auto connects to your preferred wifi (provided of course that you have the box checked to auto connect to that Wifi network on the general tab of network manager. Tested on a default install of Ubuntu 16.04.3
So if I'm understanding you correctly you just want to automatically start the hotspot service on your laptop when the Ethernet cable is connected and disable the service when the Ethernet cable is disconnected.
This should be fairly simple to do with a bash script and nmcli
'nmcli' is a powerful networknig tool that allows you to bring connections up and down at will and obtain tons of relevant information.
To find out what connections you will be scripting for simply run nmcli -t monitor| grep primary
when connected via wifi and plug in your Ethernet cable. The connections you are interested in bringing up and down with nmcli
will be those surrounded by '
s Example: 'Wired connection 1' the logic is that when 'Connection' is connected bring up the hotspot (you may find it necessary to use the command sleep
or utilize the -w
switch to make nmcli
in your script wait for a specified number of seconds for a command to complete before issuing the next.
Bringing a connection down is as simple as nmcli 'connection name' down
and bringing one up is nmcli 'connection name' up
Note: For full control via the script you may need to actually disable the automatically connect option at least for your wifi connection in Network manager as it will attempt to auto-connect whenever it's available and can interfere with what you are attempting to accomplish. Excerpt from man nmcli
:
There may be multiple connections that apply
to a device, but only one of them can be active on that device at any
given time. The additional connections can be used to allow quick
switching between different networks and configurations.
So once you've determined that your Ethernet is connected you can issue the commands to bring the wifi connection down Example: nmcli connection my-wifi down
and then the hotspot connection up Example: nmcli connection my-hotspot up
For more on how to automatically run scripts based on network connection see this. For more detail about 'nmcli' check the man page. And here's info on how to create a hotspot.
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down withnmcli connection my-wifi down
it never reconnects?
â Elder Geek
Mar 15 at 16:35
 |Â
show 4 more comments
up vote
1
down vote
accepted
It's my understanding that when you plug in the Ethernet cable that trumps the wifi connection and the wifi connection drops automatically. In similar fashion, disconnecting the Ethernet cable auto connects to your preferred wifi (provided of course that you have the box checked to auto connect to that Wifi network on the general tab of network manager. Tested on a default install of Ubuntu 16.04.3
So if I'm understanding you correctly you just want to automatically start the hotspot service on your laptop when the Ethernet cable is connected and disable the service when the Ethernet cable is disconnected.
This should be fairly simple to do with a bash script and nmcli
'nmcli' is a powerful networknig tool that allows you to bring connections up and down at will and obtain tons of relevant information.
To find out what connections you will be scripting for simply run nmcli -t monitor| grep primary
when connected via wifi and plug in your Ethernet cable. The connections you are interested in bringing up and down with nmcli
will be those surrounded by '
s Example: 'Wired connection 1' the logic is that when 'Connection' is connected bring up the hotspot (you may find it necessary to use the command sleep
or utilize the -w
switch to make nmcli
in your script wait for a specified number of seconds for a command to complete before issuing the next.
Bringing a connection down is as simple as nmcli 'connection name' down
and bringing one up is nmcli 'connection name' up
Note: For full control via the script you may need to actually disable the automatically connect option at least for your wifi connection in Network manager as it will attempt to auto-connect whenever it's available and can interfere with what you are attempting to accomplish. Excerpt from man nmcli
:
There may be multiple connections that apply
to a device, but only one of them can be active on that device at any
given time. The additional connections can be used to allow quick
switching between different networks and configurations.
So once you've determined that your Ethernet is connected you can issue the commands to bring the wifi connection down Example: nmcli connection my-wifi down
and then the hotspot connection up Example: nmcli connection my-hotspot up
For more on how to automatically run scripts based on network connection see this. For more detail about 'nmcli' check the man page. And here's info on how to create a hotspot.
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down withnmcli connection my-wifi down
it never reconnects?
â Elder Geek
Mar 15 at 16:35
 |Â
show 4 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
It's my understanding that when you plug in the Ethernet cable that trumps the wifi connection and the wifi connection drops automatically. In similar fashion, disconnecting the Ethernet cable auto connects to your preferred wifi (provided of course that you have the box checked to auto connect to that Wifi network on the general tab of network manager. Tested on a default install of Ubuntu 16.04.3
So if I'm understanding you correctly you just want to automatically start the hotspot service on your laptop when the Ethernet cable is connected and disable the service when the Ethernet cable is disconnected.
This should be fairly simple to do with a bash script and nmcli
'nmcli' is a powerful networknig tool that allows you to bring connections up and down at will and obtain tons of relevant information.
To find out what connections you will be scripting for simply run nmcli -t monitor| grep primary
when connected via wifi and plug in your Ethernet cable. The connections you are interested in bringing up and down with nmcli
will be those surrounded by '
s Example: 'Wired connection 1' the logic is that when 'Connection' is connected bring up the hotspot (you may find it necessary to use the command sleep
or utilize the -w
switch to make nmcli
in your script wait for a specified number of seconds for a command to complete before issuing the next.
Bringing a connection down is as simple as nmcli 'connection name' down
and bringing one up is nmcli 'connection name' up
Note: For full control via the script you may need to actually disable the automatically connect option at least for your wifi connection in Network manager as it will attempt to auto-connect whenever it's available and can interfere with what you are attempting to accomplish. Excerpt from man nmcli
:
There may be multiple connections that apply
to a device, but only one of them can be active on that device at any
given time. The additional connections can be used to allow quick
switching between different networks and configurations.
So once you've determined that your Ethernet is connected you can issue the commands to bring the wifi connection down Example: nmcli connection my-wifi down
and then the hotspot connection up Example: nmcli connection my-hotspot up
For more on how to automatically run scripts based on network connection see this. For more detail about 'nmcli' check the man page. And here's info on how to create a hotspot.
It's my understanding that when you plug in the Ethernet cable that trumps the wifi connection and the wifi connection drops automatically. In similar fashion, disconnecting the Ethernet cable auto connects to your preferred wifi (provided of course that you have the box checked to auto connect to that Wifi network on the general tab of network manager. Tested on a default install of Ubuntu 16.04.3
So if I'm understanding you correctly you just want to automatically start the hotspot service on your laptop when the Ethernet cable is connected and disable the service when the Ethernet cable is disconnected.
This should be fairly simple to do with a bash script and nmcli
'nmcli' is a powerful networknig tool that allows you to bring connections up and down at will and obtain tons of relevant information.
To find out what connections you will be scripting for simply run nmcli -t monitor| grep primary
when connected via wifi and plug in your Ethernet cable. The connections you are interested in bringing up and down with nmcli
will be those surrounded by '
s Example: 'Wired connection 1' the logic is that when 'Connection' is connected bring up the hotspot (you may find it necessary to use the command sleep
or utilize the -w
switch to make nmcli
in your script wait for a specified number of seconds for a command to complete before issuing the next.
Bringing a connection down is as simple as nmcli 'connection name' down
and bringing one up is nmcli 'connection name' up
Note: For full control via the script you may need to actually disable the automatically connect option at least for your wifi connection in Network manager as it will attempt to auto-connect whenever it's available and can interfere with what you are attempting to accomplish. Excerpt from man nmcli
:
There may be multiple connections that apply
to a device, but only one of them can be active on that device at any
given time. The additional connections can be used to allow quick
switching between different networks and configurations.
So once you've determined that your Ethernet is connected you can issue the commands to bring the wifi connection down Example: nmcli connection my-wifi down
and then the hotspot connection up Example: nmcli connection my-hotspot up
For more on how to automatically run scripts based on network connection see this. For more detail about 'nmcli' check the man page. And here's info on how to create a hotspot.
edited Mar 16 at 14:15
answered Mar 13 at 21:11
![](https://i.stack.imgur.com/Cfz2Q.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Cfz2Q.jpg?s=32&g=1)
Elder Geek
25.4k949120
25.4k949120
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down withnmcli connection my-wifi down
it never reconnects?
â Elder Geek
Mar 15 at 16:35
 |Â
show 4 more comments
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down withnmcli connection my-wifi down
it never reconnects?
â Elder Geek
Mar 15 at 16:35
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
Thanks for the wiki reference, as a non-poweruser I find these easier to start with than the man pages. Will keep you posted
â Bib-lost
Mar 14 at 11:01
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
So far so good, but not completely satisfied with the disabling autoconnect part. I am looking through the man pages for nmcli, but would there be a command to 'scan for auto-connectable networks' on unplugging the ethernet cable?
â Bib-lost
Mar 14 at 15:52
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
@Bib-lost My tests indicate that leaving the wireless as auto-connectible results in it staying connected when the Ethernet cable is plugged in and automatically reconnecting if you manually bring it down. Are your results different than mine?
â Elder Geek
Mar 14 at 20:04
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
I have not been able yet to make scripts run on plugging in Ethernet cable (although I followed the steps in the Wiki) but just by testing in the console, if I manually order to disconnect from a connection (even if that is auto-connectable) it does not reconnect.
â Bib-lost
Mar 15 at 9:57
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down with
nmcli connection my-wifi down
it never reconnects?â Elder Geek
Mar 15 at 16:35
@Bib-lost Interesting.. I'll have to do further testing. Are you saying that if the wifi is set to autoconnect in Network Manager and you bring it down with
nmcli connection my-wifi down
it never reconnects?â Elder Geek
Mar 15 at 16:35
 |Â
show 4 more comments
up vote
0
down vote
Solution which did it for me (found with the help of Elder Geek).
I kept autoconnect on for all networks I want to automatically connect to, but off for the hot-spot. I then put the following script (with the right permissions as described on this Wiki page) in the folder /etc/NetworkManager/dispatcher.d
!/bin/bash
interf=$1
state=$2
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
nmcli connection up 'my-hotspot'
fi
if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
nmcli connection down 'my-hotspot'
fi
This works very well so far; automatic connection to the hotspot whenever the ethernet cable is plugged in or even when the computer boots or wakes with the ethernet cable plugged in. Automatic deconnection from hot-spot whenever ethernet cable is pulled out, followed by automatic connection to available WiFi networks.
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
add a comment |Â
up vote
0
down vote
Solution which did it for me (found with the help of Elder Geek).
I kept autoconnect on for all networks I want to automatically connect to, but off for the hot-spot. I then put the following script (with the right permissions as described on this Wiki page) in the folder /etc/NetworkManager/dispatcher.d
!/bin/bash
interf=$1
state=$2
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
nmcli connection up 'my-hotspot'
fi
if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
nmcli connection down 'my-hotspot'
fi
This works very well so far; automatic connection to the hotspot whenever the ethernet cable is plugged in or even when the computer boots or wakes with the ethernet cable plugged in. Automatic deconnection from hot-spot whenever ethernet cable is pulled out, followed by automatic connection to available WiFi networks.
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Solution which did it for me (found with the help of Elder Geek).
I kept autoconnect on for all networks I want to automatically connect to, but off for the hot-spot. I then put the following script (with the right permissions as described on this Wiki page) in the folder /etc/NetworkManager/dispatcher.d
!/bin/bash
interf=$1
state=$2
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
nmcli connection up 'my-hotspot'
fi
if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
nmcli connection down 'my-hotspot'
fi
This works very well so far; automatic connection to the hotspot whenever the ethernet cable is plugged in or even when the computer boots or wakes with the ethernet cable plugged in. Automatic deconnection from hot-spot whenever ethernet cable is pulled out, followed by automatic connection to available WiFi networks.
Solution which did it for me (found with the help of Elder Geek).
I kept autoconnect on for all networks I want to automatically connect to, but off for the hot-spot. I then put the following script (with the right permissions as described on this Wiki page) in the folder /etc/NetworkManager/dispatcher.d
!/bin/bash
interf=$1
state=$2
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
nmcli connection up 'my-hotspot'
fi
if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
nmcli connection down 'my-hotspot'
fi
This works very well so far; automatic connection to the hotspot whenever the ethernet cable is plugged in or even when the computer boots or wakes with the ethernet cable plugged in. Automatic deconnection from hot-spot whenever ethernet cable is pulled out, followed by automatic connection to available WiFi networks.
answered Mar 15 at 19:58
Bib-lost
141112
141112
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
add a comment |Â
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
I'm glad you got it sorted and found my answer useful! Cheers! As a new member you may not be aware of this.
â Elder Geek
Mar 15 at 23:48
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2faskubuntu.com%2fquestions%2f1011772%2fset-up-autoconnect-to-hot-spot-only-when-ethernet-connection%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
1
I'm not a 100% sure what you do, I guess you use network manager ? SO it's difficult to provide a manual. I would look into
post-up
of the/etc/network/interfaces
context, there is a great overview here.post-up
basically just calls commands, or scripts, after an interface comes up.â Robert Riedl
Mar 9 at 8:07
Looks like a good place to start. Will look into it, thanks.
â Bib-lost
Mar 9 at 12:18