# How can I switch between Wireless and Wired on a laptop?

## Gladuin

Hello,

My laptop has two networking interfaces, Wired (enp8s0) and Wireless (wlp9s0). I got those both to work but the problem is that when I plug in my ethernet cable, wlp9s0 is still up so I have two IP adresses. My question is, How can I bring wlp9s0 down when I plug in my ethernet cable?

Thanks for the help!

----------

## Anon-E-moose

I've set mine up so neither comes up automatically.

then I have aliases for bringing wpa up and down, and the ethernet up and down.

I don't have the laptop turned on at the moment, when I do later I'll see exactly how I've set it up.

----------

## John R. Graham

See sys-apps/ifplugd. Does exactly what you're asking for and works like a charm.  :Smile: 

(Just pay no attention to the name of the author.  :Wink:  )

- John

----------

## UberLord

Why not go one better and have both up? That way, wireless takes over instantly when the ethernet is unplugged.

You also get the option of sharing the same IP address on both interfaces if you're so inclined.

https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD

----------

## Anon-E-moose

 *UberLord wrote:*   

> Why not go one better and have both up? That way, wireless takes over instantly when the ethernet is unplugged.
> 
> You also get the option of sharing the same IP address on both interfaces if you're so inclined.
> 
> https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD

 

Sweet!!! I didn't know it could share the IP. 

Thanks.

----------

## John R. Graham

 *UberLord wrote:*   

> Why not go one better and have both up? That way, wireless takes over instantly when the ethernet is unplugged.

 Well, personally, I don't want my WiFi radio on if I'm not using it.

- John

----------

## UberLord

Well, that's why you have a nice toggle for wireless on/off (assuming a decent laptop).

But that's a hardware thing - software side you just set all go.

If you want a software switch you still set all go but just bring up or down the wireles interface:

ifconfig wlan0 down

ifconfig wan0 up

You could even script that as a dhcpcd exit hook if you wanted something portable across a variety of OS's

Simplez  :Smile: 

----------

## Gladuin

 *John R. Graham wrote:*   

> See sys-apps/ifplugd. Does exactly what you're asking for and works like a charm. 
> 
> (Just pay no attention to the name of the author.  )
> 
> - John

 

Well I know about ifplugd and I searched around on how to use it but I still really dont know how   :Sad: 

----------

## Gladuin

 *Anon-E-moose wrote:*   

> I've set mine up so neither comes up automatically.
> 
> then I have aliases for bringing wpa up and down, and the ethernet up and down.
> 
> I don't have the laptop turned on at the moment, when I do later I'll see exactly how I've set it up.

 

Please do

----------

## Anon-E-moose

I do not have net.eth0, net.wlan0 or wpa_supplicant set to boot as services.

```
acer-linux:/home/me 1001) rc-update -v

...

             net.eth0 |

               net.lo | boot

            net.wlan0 |

             netmount |

...

       wpa_supplicant |

```

I then have these aliases in my .bashrc file

```

# network stuff

alias eth-up="sudo /etc/init.d/net.eth0 start"

alias eth-down="sudo /etc/init.d/net.eth0 stop"

alias wpa-up="sudo /etc/init.d/net.wlan0 start"

alias wpa-down="sudo /etc/init.d/net.wlan0 stop"

```

Because there are times that I simply don't want the network up or don't care if it's up.

"man rc-update" for how to add/remove services from boot

rc-update del net.eth0 as root for example

"man sudo" for adding user to be able to execute /etc/init.d scripts for example.

This is a little more complicated for just adding the ability for a user to use specific commands but not that difficult, and you can set it up so you don't need a password for that particular section. (not really recommended in general, but mine is a single use computer and I know what I'm doing)

----------

## Gladuin

I have come up with something myself.

I disabled all interfaces from starting up and I removed wpa_supplicant from boot. I only left dhcpcd to start on boot because then the IP adresses get assigned automatically when I bring an interface up. 

I also made these scripts:

for starting my wireless interface

for starting my wired interface

If I can improve something on them, please tell me   :Wink: 

----------

## steveL

 *UberLord wrote:*   

> Well, that's why you have a nice toggle for wireless on/off (assuming a decent laptop).
> 
> But that's a hardware thing - software side you just set all go.
> 
> If you want a software switch you still set all go but just bring up or down the wireless interface:
> ...

 Indeed :) Just to add that acpid handles the toggle-switch on the laptop, and has done so reliably for at least fifteen years, that I know about.

----------

