You are not logged in.

#1 2014-07-27 22:57:02

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,697
Website

Netctl with wired and wireless profiles... how to prioritize them?

My goal is to have netctl connect to either my WIRED interface or my WIRELESS interface depending on whether or not I have a LAN cable plugged in.  The WIRED interface should take priority.  If the WIRED interface is unplugged, netctl should then connect to the WIRELESS interface automatically.  If for whatever reason, I plug back in the WIRED interface, the WIRELESS interface should go down and the WIRED interface should again come back to life.

If I understand this wiki article correctly, I need to use both netctl-auto and netctl-ifplugd to accomplish this.  After enabling both services and defining both profiles, netctl does not prioritize them, but does connect to both simultaneously (i.e. two different IP addresses, one for the wired and one for the wireless).

1) Am I incorrect in my implementation?
2) If yes, how can accomplish my goal?

Thanks!

Associated bug report: https://bugs.archlinux.org/task/41359
--------------
I have both of these enabled:
netctl-auto@wlp4s0.service
netctl-ifplugd@enp0s10.service

Wired profile:

# cat /etc/netctl/dhcp 
Description='A basic dhcp ethernet connection'
Interface=enp0s10
Connection=ethernet
IP=dhcp
ExecUpPost='/usr/bin/ethtool -s enp0s10 wol g'
ExecDownPre='/usr/bin/pkill sshd'

Wireless profile:

# cat /etc/netctl/wireless 
Description='A simple WPA encrypted wireless connection'
Interface=wlp4s0
Connection=wireless
Security=wpa
IP=dhcp
ESSID='mysiddgoeshere'
Key='mykeygoeshere'
ExecDownPre='/usr/bin/pkill sshd'

Last edited by graysky (2014-07-28 07:37:25)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2014-07-28 07:58:33

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: Netctl with wired and wireless profiles... how to prioritize them?

Hey graysky, here I am ;-)
Okay so we start over again, let me first answer the last question from the previous one: yes, I did set up netctl the way you did, only names are different.
I have enabled netctl-auto@wlan0.service and netctl-ifplugd@eth0.service
If I plug ethernet cable in, eth0 is brought up and wlan is brought down. ssh is killed with signal -15
If I unplug ethernet cable, eth0 is down, wlan0 is brought up, ssh killed with signal -15

My netctl profiles:

sudo cat /etc/netctl/eth0
Description='A basic dhcp ethernet connection'
Interface=eth0
Connection=ethernet
IP=dhcp
ExecUpPost='sudo ifconfig wlan0 down|| true'
ExecDownPre='sudo ifconfig wlan0 up|| true'
sudo cat /etc/netctl/wlan0
Description='A simple WPA encrypted wireless connection using a static IP'
Interface=wlan0
Connection=wireless
Security=wpa
ESSID='some-name'
Key='some-key'
IP=dhcp
ExecDownPre='pkill -15 ssh|| true'
ExecUpPost='pkill -15 ssh|| true'

edit;graysky, if you bring sshd down, don't you need to bring it back up?
I have no daemon running on my laptop, so I used ssh for that, and that's working.

Last edited by qinohe (2014-07-28 08:22:40)

Offline

#3 2014-07-28 17:31:56

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: Netctl with wired and wireless profiles... how to prioritize them?

I have meant to investigate GraySky's issue but failed to get very far with it.  I'm very happy to see it addressed by two experts though.  smile

@Qinohe, I do have one question:  is the use of "sudo" required to do bring up and down the interfaces?  I ask because I'm fairly sure that only root can do these things and I can't imagine another way around that issue without using sudo.

Apologies to graysky, I don't mean to hijack your thread.  It seemed silly to start a new one.

Edit: fixed GraySky to graysky.

Last edited by MoonSwan (2014-07-28 17:32:43)

Offline

#4 2014-07-28 18:46:22

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: Netctl with wired and wireless profiles... how to prioritize them?

MoonSwan wrote:

@Qinohe, I do have one question:  is the use of "sudo" required to do bring up and down the interfaces?  I ask because I'm fairly sure that only root can do these things and I can't imagine another way around that issue without using sudo.

MoonSwan, it depends where the file is located or if you have access to that file as a 'normal' user. lets asume the profiles are in '/etc/netctl', than you don't need sudo.
Bit of a bad habit I guess wink

Offline

#5 2014-07-28 19:31:14

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,697
Website

Re: Netctl with wired and wireless profiles... how to prioritize them?

@qinohe - Can you reboot your system with the network card connected?  Wait 2 min or so, then post the output of `ip addr`... for me you can clearly see both connected hmm  Are you certain that your's are not?  I don't understand the inconsistency between your system and my system since we are using the same netctl services.

EDIT: Yes, this seems to be it.  For me booting with the cable DISCONNECTED has just the wireless up, but booting with the cable CONNECTED has both interfaces up.  I suspect this is a bug.

Fresh boot with cable DISCONNECTED.  I ssh'ed into the wireless IP address.  Note that the wired network 'enp0s10' is DOWN and wireless 'wlp4s0' is UP:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s10: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 01:2a:34:12:a9:b7 brd ff:ff:ff:ff:ff:ff
3: wlp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 01:12:42:29:21:ad brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.233/24 brd 10.1.1.255 scope global wlp4s0
       valid_lft forever preferred_lft forever

Now I plug the cable in and my ssh session that was connected via the wireless IP address is frozen.
I can ssh into the wired IP address.
I can no longer ssh into the wireless IP address BUT as you see, the interface is still UP.  It should be DOWN I think.

% ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 01:2a:34:12:a9:b7 brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.105/24 brd 10.1.1.255 scope global enp0s10
       valid_lft forever preferred_lft forever
3: wlp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 01:12:42:29:21:ad brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.233/24 brd 10.1.1.255 scope global wlp4s0
       valid_lft forever preferred_lft forever

If I reverse things, and reboot the machine with the cable CONNECTED, both interfaces are up and I can ssh into either IP address (wired or wireless).
As you can see, both interfaces are UP.
This should not be the case I think.
The wired interface should have priority over the wireless.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 01:2a:34:12:a9:b7 brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.105/24 brd 10.1.1.255 scope global enp0s10
       valid_lft forever preferred_lft forever
3: wlp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 01:12:42:29:21:ad brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.233/24 brd 10.1.1.255 scope global wlp4s0
       valid_lft forever preferred_lft forever

Last edited by graysky (2014-07-28 20:00:00)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#6 2014-07-28 22:27:48

Tarqi
Member
From: Ixtlan
Registered: 2012-11-27
Posts: 179
Website

Re: Netctl with wired and wireless profiles... how to prioritize them?

Sorry for kicking in here, just a question: What exactly is your goal? If you just want to have a working connection without user intervention, checkout bonding. Inspired by this thread, I played with it and it works as expected, including uninterrupted SSH sessions. However, I just tested the client side, but I think this will also work on serverside (probably much better, because there is no interface up/down and ip change for the service).

Edit: Typos

Last edited by Tarqi (2014-07-28 22:33:36)


Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse

Offline

#7 2014-07-28 22:52:23

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: Netctl with wired and wireless profiles... how to prioritize them?

graysky, okay I booted with ethernet cable attached, waited 3 min. here is the output of ip addr:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether f4:6d:04:fd:a9:ba brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.8/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 74:2f:68:7f:e9:95 brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 72:58:18:03:09:c2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever

Now I unplug ethernet, here is the output

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether f4:6d:04:fd:a9:ba brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 74:2f:68:7f:e9:95 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.7/24 brd 192.168.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 72:58:18:03:09:c2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever

You can see, it really seems to work... Though it probably doesn't matter, I run mainline kernel.

I do agree, something is definitely different over at yours, can't lay a finger on it, yet.
If you need to more info, feel free to ask ;-)

edit; is there any other service keeping hold of wireless?, this could be an explanation.

Last edited by qinohe (2014-07-28 23:10:01)

Offline

#8 2014-07-29 03:31:27

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: Netctl with wired and wireless profiles... how to prioritize them?

@qinohe, Thank you very much for answering my question.  smile

Last edited by MoonSwan (2014-07-29 03:31:45)

Offline

#9 2014-07-29 09:08:05

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,697
Website

Re: Netctl with wired and wireless profiles... how to prioritize them?

@Tarqi - see the first sentence of my first post smile. I will look into bonding, thanks for the suggestion.
@moon - does seem to work for you.  I have ufw running but that's the only thing that could keep it up I think.  My box is on 3.15.7.  Just curiously, if you continue switching from wired to wireless, do the states of the respective interfaces continue to alternate?  So at no time does your setup have both of them up, correct?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#10 2014-07-29 11:56:08

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: Netctl with wired and wireless profiles... how to prioritize them?

graysky wrote:

@moon - does seem to work for you.  I have ufw running but that's the only thing that could keep it up I think.  My box is on 3.15.7.  Just curiously, if you continue switching from wired to wireless, do the states of the respective interfaces continue to alternate?  So at no time does your setup have both of them up, correct?

I think that question is meant for me big_smile. I don't think ufw is the problem.
If I continue switching, the states are changed according to that switch for both wired and wireless.
note: I wait until the system has adapted to the switch. I mean, I wont try cable 'in-out-in-out-in ' in a 10 sec. period.
Correct, at no time the two interfaces in question are up.

Offline

#11 2014-07-29 16:00:44

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: Netctl with wired and wireless profiles... how to prioritize them?

Tarqi wrote:

Sorry for kicking in here, just a question: What exactly is your goal? If you just want to have a working connection without user intervention, checkout bonding. Inspired by this thread, I played with it and it works as expected, including uninterrupted SSH sessions. However, I just tested the client side, but I think this will also work on serverside (probably much better, because there is no interface up/down and ip change for the service).

Edit: Typos

This. Especially useful is the primary= option for the bonding module, which allows you to prioritize once slave interface over the other (e.g. wlan over eth). You don't even need netctl to accomplish this -- just networkd and wpa_supplicant.


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#12 2014-07-29 16:39:06

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: Netctl with wired and wireless profiles... how to prioritize them?

@graysky, yes, sorry, I was asking qinohe my own question in your thread.  But, to answer your own question, I do have both up simultaneously when both are "on" as it were. 

And the last time I looked at bonding the wiki was pretty badly written and the whole thing seemed overly-complex.  I tried it anyway but failed miserably (about a year ago).  If Leonid.I is accurate, however, I may try it again as it does seem to do what I want.  I hope it works for you too.  smile

Offline

#13 2014-07-29 20:33:43

Tarqi
Member
From: Ixtlan
Registered: 2012-11-27
Posts: 179
Website

Re: Netctl with wired and wireless profiles... how to prioritize them?

graysky wrote:

@Tarqi - see the first sentence of my first post smile.

I did, but I do not understand the reason. The following sentences are describing exactly what you can do with bonding as shown in the wiki. If it is really needed that the respectively other interface has to be down, this is certainly not a solution.

Leonid.I wrote:

This. Especially useful is the primary= option for the bonding module, which allows you to prioritize once slave interface over the other (e.g. wlan over eth). You don't even need netctl to accomplish this -- just networkd and wpa_supplicant.

The other one would be make more sense: If unplugged, fallback to wireless. The wiki is a bit confusing - you can can use netctl with a simple bonding profile and use ExecUpPost and ExecDownPre to handle wpa_supplicant. While networkd is nice, it is missing some features which might be needed sometimes.

Edit: Grammar (as far as i know it)

Last edited by Tarqi (2014-07-29 20:39:30)


Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse

Offline

#14 2014-07-29 20:38:49

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,697
Website

Re: Netctl with wired and wireless profiles... how to prioritize them?

From my own experience and what people have posted here, I can conclude that:

1) My hardware doesn't behave like other people's with the method I described in the 1st post.
2) I tried playing with bonding and think I have it working but again, I have two ip address and the wire and wireless connections are running at the same time. Here is the thread detailing that mess.  Thanks to all who contributed here!

Last edited by graysky (2014-07-29 20:48:53)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB