How to set device mode via networkd

networkingsystemd-networkd

How can I set mode to device (for example monitor/ap to wlan) via networkd deamon in .link file ???

Because I want to set bridge in .network of wlan device and I can't do it until I set it in specific mode.

##################################
# /etc/systemd/network/eth0.link # 
##################################
[Match]
MACAddress=xxxxxxxxxx

[Link]
Description=Top Ethernet Port
Type=ether
Name=eth0
#MACAddressPolicy=persistent 
MACAddress= rewrite mac 
WakeOnLan=off

#####################################
# /etc/systemd/network/eth0.network #
#####################################
[Match]
Name=eth0

[Address]
Address=192.168.0.101/24
Broadcast=192.168.0.101

[Network]
Bridge=br0

###################################
# /etc/systemd/network/br0.netdev #
###################################
[NetDev]
Name=br0
Kind=bridge
MACAddress=set mac

####################################
# /etc/systemd/network/br0.network #
####################################
[Match]
Name=br0

[Address]
Address=192.168.0.100/24
Broadcast=192.168.0.100

[Network]
Description=Default network through bridge
Gateway=192.168.0.1
DHCP=ip4
IPv6PrivacyExtensions=true
DNS=8.8.8.8
DNS=8.8.4.4

[DHCP]
UseDNS=false

[Bridge]

[Route]
#Gateway=192.168.0.1
#Destination=192.168.0.0/24
#Scope=link

###################################
# /etc/systemd/network/at0.link   #
###################################
[Match]
# See: udevadm info /sys/class/net/at0
Type=wlan
OriginalName=wlan0
#MACAddress=
Driver=ath9k

[Link]
Description=Top Wireless Lan Port
Name=at0
Type=wlan
MACAddress= rewrite mac
BitsPerSecond=100M
WakeOnLan=off

####################################
# /etc/systemd/network/at0.network #
####################################
[Match]
Name=at0

[Address]
Address=192.168.0.102/24
Broadcast=192.168.0.102

[Network]
Bridge=br0            <---- THIS FAILS 

#

$ networkctl 
IDX LINK             TYPE               OPERATIONAL SETUP     
  1 lo               loopback           carrier     configured
  2 eth0             ether              routable    configured
  3 at0              wlan               no-carrier  configured
  4 br0              ether              routable    configured


$ networkctl status 
●      State: routable
     Address: 192.168.0.101 on eth0
              192.168.0.102 on at0
              192.168.0.100 on br0
              fe80::cb4:a1ff:fea2:111 on eth0
              fe80::cb4:a1ff:fea2:110 on br0
     Gateway: 192.168.0.1 (Cisco SPVTG) on br0
         DNS: 8.8.4.4
              8.8.8.8

ps.

I know how create bridges and interfaces through networkd and how add interfaces to bridge – but what I don't know is how to change mode of particularly interface (wireless nic) to other mode without using wpa supplicant or iw / iw conf

from : https://wiki.archlinux.org/index.php/systemd-networkd

Wireless adapter

In order to connect to a wireless network with systemd-networkd, a
wireless adapter configured with another service such as
wpa_supplicant is required. In this example, the corresponding systemd
service file that needs to be enabled is
wpa_supplicant@wlp2s0.service.

But I don't want to connect! I want to make ad-hoc – ap

so I want to:

  • set for example mode to ap/monitor (promiscuous mode)
  • set wpa essid
  • set wpa key

seriously is there no way to set up an access point without:

  • wpa supplicant
  • hostapd

ps. I only found way to use wpa_supplicant as unit

# create wpa supplicant config for interface at0 
#
    $ nano / cat /etc/wpa_supplicant/wpa_supplicant_at0.conf 

    ctrl_interface=/var/run/wpa_supplicant
    eapol_version=1
    ap_scan=1
    fast_reauth=1
    network={
        ssid="..."
    #psk="..."
    }

# create unit
#
    $ nano /etc/systemd/system/wpa_supplicant@.service 

[Unit]
Description=WPA supplicant (%i)
After=systemd-networkd.service
Requires=systemd-networkd.service
Before=network-online.target
ConditionPathIsSymbolicLink=/sys/class/net/%i

[Service]
Type=forking
ExecStartPre=/sbin/ip link set %i up
ExecStart=/sbin/wpa_supplicant -s -i %i -D nl80211,wext -c/etc/wpa_supplicant/wpa_supplicant_%i.conf -B -P /run/wpa_supplicant.%i.pid
ExecStopPost=/sbin/ip addr flush %i
ExecStopPost=/sbin/ip link set %i down
PIDFile=/run/wpa_supplicant.%i.pid

[Install]
WantedBy=multi-user.target

# reload systemctl daemon 
#
   $ systemctl daemon-reload 

# enable supplicant on interface on boot 
# 
   $ systemctl enable wpa_supplicant@at0

ps2. I dug out this:

https://wiki.archlinux.org/index.php/Talk:Ad-hoc_networking

basics:

Network Topologies

There are two popular network topologies in 802.11 wireless networks. The first topology I discuss is Infrastructure BSS mode, which is the most popular. You encounter Infrastructure BSS wireless >networks in home wireless networks
and offices. Later I discuss the IBSS (Ad Hoc) mode. Note that IBSS is not Infrastructure BSS; IBSS is Independent BSS, which is an ad hoc network, discussed later in this section.

Infrastructure BSS

When working in Infrastructure BSS mode, there is a central device, called an Access Point (AP), and some client stations. Together they form a BSS (Basic Service Set). These client stations must first perform association and
authentication against the AP to be able to transmit packets via the AP. On many occasions, client stations perform scanning prior to authentication and association, in order to get details about the AP. Association is exclusive: a client can be associated with only one AP in a given moment. When a client associates with an AP successfully, it gets an AID (association id), which is a unique number (to this BSS) in the range 1–2007. An AP is in fact a wireless network device with some hardware additions (like Ethernet ports, LEDs, a button to reset to manufacturer defaults, and more). A management daemon runs on the AP device. An example of such software is the hostapd daemon. This
software handles some of the management tasks of the MLME layer, such as authentication and association requests.
It achieves this by registering itself to receive the relevant management frames via nl80211. The hostapd project is an open source project which enables several wireless network devices to operate as an AP.
Clients can communicate with other clients (or to stations in a different network which is bridged to the AP) by sending packets to the AP, which are relayed by the AP to their final destination. To cover a large area, you can
deploy multiple APs and connect them by wire. This type of deployment is called Extended Service Set (ESS). Within ESS deployment, there are two or more BSSs. Multicasts and broadcasts sent in one BSS, which may arrive on a
nearby BSS, are rejected in the nearby BSS stations (the bssid in the 802.11 header does not match). Within such a deployment, each AP usually uses a different channel to minimize interference.

IBSS, or Ad Hoc Mode

IBSS network is often formed without preplanning, for only as long as the WLAN is needed. An IBSS network is also called ad hoc network. Creating an IBSS is a simple procedure. You can set an IBSS by running from a command line this iw command (note that the 2412 parameter is for using channel 1):

 iw wlan0 ibss join AdHocNetworkName 2412

Or when using the iwconfig tool, with these two commands:

iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid AdHocNetworkrName

This triggers IBSS creation by calling the ieee80211_sta_create_ibss() method (net/mac80211/ibss.c). Then the ssid (AdHocNetworkName in this case) has to be distributed manually (or otherwise) to everyone who wants to
connect to the ad hoc network. When working with IBSS, you do not have an AP. The bssid of the IBSS is a random 48-bit address (based on calling the get_random_bytes() method). Power management in Ad Hoc mode is a bit
more complex than power management in Infrastructure BSS; it uses Announcement Traffic Indication Map (ATIM) messages. ATIM is not supported by mac802.11 and is not discussed in this chapter. The next section describes power save mode, which is one of the most important mechanisms of the mac80211
network stack…

Wireless Modes

You can set a wireless network interface to operate in several modes, depending on its intended use and the topology of the network in which it is deployed. In some cases, you can set the mode with the iwconfig command, and in some cases you must use a tool like hostapd for this. Note that not all devices support all modes. See www.linuxwireless.org/en/users/Drivers for a list of Linux drivers that support different modes. Alternatively, you can also check to which values the interface_modes field of the wiphy member (in the ieee80211_hw object) is
initialized in the driver code. The interface_modes are initialized to one or more modes of the nl80211_iftype enum, like NL80211_IFTYPE_STATION or NL80211_IFTYPE_ADHOC (see: include/uapi/linux/nl80211.h). The following
is a detailed description of these wireless modes:

  • AP mode: In this mode, the device acts as an AP (NL80211_IFTYPE_AP). The AP maintains and manages a list of associated stations. The network (BSS) name is the MAC address of the AP (bssid). There is also a human-readable name for the BSS, called the SSID.
  • Station infrastructure mode: A managed station in an infrastructure mode
    (NL80211_IFTYPE_STATION).
  • Monitor mode: All incoming packets are handed unfiltered in monitor mode
    (NL80211_IFTYPE_MONITOR). This is useful for sniffing. It is usually possible to transmit packets in monitor mode. This is termed packet injection; these packets are marked with a special flag (IEEE80211_TX_CTL_INJECTED).
  • Ad Hoc (IBSS) mode: A station in an ad hoc (IBSS) network (NL80211_IFTYPE_ADHOC). With
    Ad Hoc mode, there is no AP device in the network.
  • Wireless Distribution System (WDS) mode: A station in a WDS network (NL80211_IFTYPE_WDS).
  • Mesh mode: A station in a Mesh network (NL80211_IFTYPE_MESH_POINT), discussed in the “Mesh Networking (802.11s)” section later in this chapter.

source: https://books.google.pl/books?id=96V4AgAAQBAJ

Best Answer

According to Systemd-networkd you need to create a virtual bridge interface with ;

nano /etc/systemd/network/MyBridge.netdev

past the following content

[NetDev]
Name=br0
Kind=bridge

then restart systemd-networkd.service

to verify type ip a

Next step create a network profile for the Bridge with

 nano /etc/systemd/network/MyBridge.network

And past the following content:

[Match]
Name=br0

[Network]
DHCP=ipv4

Edit

To set an access point you can use create_ap github_create_ap

Installation

yaourt -S create_ap

For Others distro

git clone https://github.com/oblique/create_ap
cd create_ap
make install

Examples

No passphrase (open network):

 create_ap wlan0 eth0 MyAccessPoint

WPA + WPA2 passphrase:

 create_ap wlan0 eth0 MyAccessPoint MyPassPhrase

AP without Internet sharing:

 create_ap -n wlan0 MyAccessPoint MyPassPhrase

Bridged Internet sharing:

 create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase

Bridged Internet sharing (pre-configured bridge interface):

 create_ap -m bridge wlan0 br0 MyAccessPoint MyPassPhrase

Internet sharing from the same WiFi interface:

 create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase

Choose a different WiFi adapter driver

 create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase

No passphrase (open network) using pipe:

 echo -e "MyAccessPoint" | create_ap wlan0 eth0

WPA + WPA2 passphrase using pipe:

 echo -e "MyAccessPoint\nMyPassPhrase" | create_ap wlan0 eth0

Enable IEEE 802.11n

  create_ap --ieee80211n --ht_capab '[HT40+]' wlan0 eth0 MyAccessPoint MyPassPhrase

Client Isolation:

 create_ap --isolate-clients wlan0 eth0 MyAccessPoint MyPassPhrase

Systemd service

Using the persistent systemd service

Start service immediately:

systemctl start create_ap

Start on boot:

systemctl enable create_ap
Related Question