You are not logged in.
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|downor
$ sudo networkctl up|down interfaceBoth 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
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
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
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
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?
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 foreverThanks a lot again. Best regards.
Offline
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
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
Thanks a lot for the answers. I've changed the subject of the post accordingly (I suppose).
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|downor
$ sudo networkctl up|down interfaceor
$ sudo ifconfig interface up|downThanks again for your time, hope this have some unique answer, !
Kind regards.
Offline
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
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
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.
Offline
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
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
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
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-intefacewhen 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
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
Wiki for the win.
Offline