You are not logged in.

#1 2021-03-10 10:34:39

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Proper way to UP|DOWN an interface with systemd-networkd ?

Hi, after reading [0,1] and using systemd-networkd as network manager I'm finding myself unable to determine which way of enabling/disabling an interface should I use/would be the proper one:

$ sudo ip link set interface up|down

or

$ sudo networkctl up|down interface

Both seems to work fine and produce the same result.
Any hint?
Thanks a lot in advance.

[0] https://wiki.archlinux.org/index.php/Ne … figuration
[1] https://wiki.archlinux.org/index.php/Systemd-networkd

EDIT: previous title was `ip link set interface up|down` or `networkctl up|down interface` ?, changed in accordance to [3].

[3] https://bbs.archlinux.org/viewtopic.php … 1#p1962381

Last edited by riveravaldez (2021-03-17 22:25:13)

Offline

#2 2021-03-10 10:57:11

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,606
Website

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Both commands can be used to manage the respective interfaces.
However, if you use a network configuration and management service such as systemd-networkd, there should rarely be a need to manage the device manually in such a way.
Instead you should configure the network interfaces appropriately in /etc/systemd/network/.


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#3 2021-03-10 11:09:51

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Hi, schard, thanks a lot for your answer.

Do you mean using the /etc/systemd/network/20-wired.network and /etc/systemd/network/25-wireless.network files?

How can I enable/disable each interface in that way?

Offline

#4 2021-03-11 12:46:11

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

You don't enable an interface (it's already enabled by the kernel), you just configure it by creating aforementioned configuration files. The wiki page you've posted the link to has examples for the most common uses. If you want to completely disable a network interface you have to blacklist the corresponding kernel module.
Can you show the output of

$ ip a

?

Offline

#5 2021-03-17 17:04:14

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

finoderi wrote:

You don't enable an interface (it's already enabled by the kernel), you just configure it by creating aforementioned configuration files. The wiki page you've posted the link to has examples for the most common uses. If you want to completely disable a network interface you have to blacklist the corresponding kernel module.

Thanks a lot for your answer, finoderi.

Maybe I'm using the words wrongly. What's the meaning and function of the up|down options when applied to an interface?
I understand that's not enabling|disabling the interface, so, what is it?

finoderi wrote:

Can you show the output of

$ ip a

?

Yes, of course:

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp6s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 14:fe:b5:b8:11:13 brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether ac:72:89:0b:a1:2b brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.3/24 brd 192.168.0.255 scope global wlp3s0
       valid_lft forever preferred_lft forever
    inet6 fe80::ae72:89ff:fe0b:a12b/64 scope link 
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:f1:9d:7c 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

Thanks a lot again. Best regards.

Offline

#6 2021-03-17 19:18:25

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

riveravaldez wrote:

What's the meaning and function of the up|down options when applied to an interface?
I understand that's not enabling|disabling the interface, so, what is it?

Will it be in UP or DOWN state ) For the sake of simplicity we could say that yes, it's enabling or disabling an interface. But in order to connect to any network, you need to configure an interface after bringing it up. It should have IP addresses, gateway and routes configured. And these parameters are usually managed by network managers. And systemd-networkd is one of them.

Offline

#7 2021-03-17 19:55:20

u666sa
Member
Registered: 2020-08-01
Posts: 70

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

I usually do sudo ifconfig wlan0 down
then you change mac or some other trickery, and
sudo ifconfig wlan0 up

works the same and easy to mermorize

Offline

#8 2021-03-17 22:33:58

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Thanks a lot for the answers. I've changed the subject of the post accordingly (I suppose).

finoderi wrote:
riveravaldez wrote:

What's the meaning and function of the up|down options when applied to an interface?
I understand that's not enabling|disabling the interface, so, what is it?

Will it be in UP or DOWN state ) For the sake of simplicity we could say that yes, it's enabling or disabling an interface. (...)

So, considering also u666sa answer I'm having right now three ways to up|down an interface, but still trying to understand which one (if any of these) would be the proper/right/best one. Maybe it doesn't matter or it's the same with anyone?

$ sudo ip link set interface up|down

or

$ sudo networkctl up|down interface

or

$ sudo ifconfig interface up|down

Thanks again for your time, hope this have some unique answer, !

Kind regards.

Offline

#9 2021-03-17 23:41:05

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

riveravaldez wrote:

or

$ sudo ifconfig interface up|down

net-tools was deprecated in favour of iproute2 a good while ago. So

ip link set whatever up

is all you need.
And using networkctl is pretty backwards way to manage connections. I wouldn't use it. For instance you won't be able to re-enable wireguard connection after you disabled it with networkctl.

Last edited by finoderi (2021-03-17 23:41:55)

Offline

#10 2021-03-18 00:07:40

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

I don't know what are you trying to accomplish exactly.
The proper way to configure network connection with systemd-networkd is to configure a network interface as described in the wiki, enable systemd-networkd service and leave it be.
Systemd-networkd doesn't have proper real time tools to disable/enable connections. It's all or nothing kind of approach. You either have network connection up and running or you don't have a network interface configured at all.

Offline

#11 2021-03-18 00:12:34

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

All of the above commands have exactly the same results. Why do you want to enable/disable interfaces?

The preferred method depends on your answer.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#12 2021-03-21 20:46:20

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Thanks a lot for the answers and explanations.

In general, I would like to be able (in a laptop, where usually one have both Ethernet and Wi-Fi interfaces available) to up|down interfaces at will so to choose which one is active/in use with the security (and simplicity) of knowing that it's the only one active/up.

More specifically, to be able to properly put down/off the Wi-Fi interface when I establish a wired connection so there's no chance of overlapping and to avoid unnecessary battery drain.

Thanks a lot for any advice or indication.

Offline

#13 2021-03-22 12:31:48

Ferdinand
Member
From: Norway
Registered: 2020-01-02
Posts: 338

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

riveravaldez wrote:

More specifically, to be able to properly put down/off the Wi-Fi interface when I establish a wired connection so there's no chance of overlapping

NetworkManager may be an alternative for that: https://wiki.archlinux.org/index.php/Ne … plugged_in

Offline

#14 2021-03-22 20:50:36

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Ferdinand wrote:
riveravaldez wrote:

More specifically, to be able to properly put down/off the Wi-Fi interface when I establish a wired connection so there's no chance of overlapping

NetworkManager may be an alternative for that: https://wiki.archlinux.org/index.php/Ne … plugged_in

Thanks a lot for your recommendation, Ferdinand, but I'm trying to avoid NetworkManager and rely simply in systemd-networkd + wpa_supplicant.
Maybe if it's impossible to do this with that setup then I could consider making the switch to NetworkManager (but my experience with it hasn't been the best imaginable).
Thanks anyway!

Offline

#15 2021-03-24 20:24:09

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

riveravaldez wrote:

Thanks a lot for your recommendation, Ferdinand, but I'm trying to avoid NetworkManager and rely simply in systemd-networkd + wpa_supplicant.

You can just

#systemctl stop wpa_supplicant@name-of-your-wifi-inteface

when you don't need it and restart it when you do. Ethernet interface won't be active until it's connected to some wired network.

Offline

#16 2021-03-24 22:40:00

riveravaldez
Member
Registered: 2016-11-18
Posts: 30

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Thanks a lot, finoderi.

Will that also turn-off the Wi-Fi card (in order to save battery)?, or should I do that independently (maybe with rfkill or something similar)?

Sorry to ask this much...

Offline

#17 2021-03-25 00:30:57

finoderi
Member
Registered: 2020-06-12
Posts: 76

Re: Proper way to UP|DOWN an interface with systemd-networkd ?

Wiki for the win.

Offline

Board footer

Powered by FluxBB