How to Enable WiFi Direct on Linux: A Complete Guide

Modern Linux operating systems have a very powerful network stack, but some features, such as WiFi Direct, often remain hidden or require manual configuration. Unlike Windows or Android, where this technology is built into the default user interface, in the open source world, administrators often have to work with configuration files and the command line. This provides flexibility, but requires an understanding of how it works. wpa_supplicant and wireless network drivers.

The main difficulty is that not all wireless adapters support P2P (Peer-to-Peer) mode, which is necessary for direct device connections. Even if the hardware supports the standard, drivers may block the functionality or require specific patches. Before setting up, you need to ensure that your equipment is physically capable of operating in both access point and client modes simultaneously, or switching between them.

In this article we will look at the activation process. WiFi Direct from A to Z. We will cover checking hardware compatibility, daemon setup wpa_supplicant, creating groups, and connecting third-party devices. Security issues and file transfers through the created tunnel will also be discussed.

Checking hardware and driver compatibility

The first step is to diagnose your wireless interface. Don't jump into the configuration files until you've verified that your network card supports the mode. P2PFor this purpose, a utility is used. iw, which is a modern standard for managing wireless devices in Linux, replacing the outdated iwconfig.

Run the command iw list and carefully examine the output. You need to find the "valid interface combinations" section or just look for the line that mentions P2P-client And P2P-GOIf your device's capabilities don't include P2P, you won't be able to enable WiFi Direct programmatically—you'll need to replace the adapter.

It's also important to check the interface status. It shouldn't be blocked by rfkill. Users often forget that a hard block can prevent changes to the card's operating modes.

  • 📡 Launch iw list | grep -A 10"valid interface combinations" to find P2P support.
  • 🔒 Use rfkill listto ensure that there are no blockages on the wireless module.
  • 💻 Check your chipset model, as some older Atheros or Broadcom cards may require proprietary drivers.

If the test is successful, you can proceed to installing the necessary software. The standard tool for managing WPA connections is the package wpa_supplicant.

⚠️ Note: Some proprietary drivers (especially for Realtek) may declare P2P support in iw list, but may not work reliably in Group Owner mode. Always test the connection before making critical data transfers.

Installing and Preparing wpa_supplicant

To implement WiFi Direct functionality in Linux, a daemon is used wpa_supplicantIt's installed by default in most distributions, but P2P may require a special build or certain compiler flags. Make sure the program version is no older than 2.0, as P2P support has been significantly improved in recent releases.

On Debian/Ubuntu systems, installation is done via the package manager. You may also need the package wpasupplicant with DBus support for integration with graphical shells, although we will consider the manual configuration method for maximum compatibility.

sudo apt update

sudo apt install wpasupplicant

After installation, you need to create a configuration file. The standard path is /etc/wpa_supplicant/wpa_supplicant.conf, but for P2P, it's better to create a separate profile so as not to disturb your regular WiFi settings. Create a file /etc/wpa_supplicant/p2p.conf.

Basic control parameters need to be added to this file. The key point is specifying the control interface and enabling P2P functionality.

  • 📝 Add a line ctrl_interface=/var/run/wpa_supplicant to control the demon.
  • ⚙️ Enable the directive p2p_disabled=0, if it is present and set to 1.
  • 🔌 Specify device_name=LinuxPC to identify the device on the network.

Now you need to stop the default network manager (NetworkManager or systemd-networkd), as they may conflict for interface control. This is a critical step that is often overlooked by beginners.

⚠️ Warning: Disabling NetworkManager may disrupt your current internet connection. Perform these steps locally or ensure you have SSH or console access.

Setting up the P2P configuration file

The most important part of the process is filling out the configuration file correctly. This is where you determine how your device will behave on the network: whether it will search for other devices or wait for a connection. The file syntax is strict, and any error will cause the daemon to fail to start.

Open the file created earlier /etc/wpa_supplicant/p2p.conf in a text editor. In addition to the basic settings, we need to define frequency ranges. Linux allows flexible control of this parameter, which is useful if a certain range is noisy in your environment.

Add the following lines to the configuration:

ctrl_interface=/var/run/wpa_supplicant

driver=nl80211

device_name=MyLinuxPC

device_type=10-0050F204-5

config_methods=display pbc

p2p_listen_channel=1

p2p_oper_channel=6

Parameter device_type Encodes the device type. In this example, the code is for a portable media player, but you can choose a different code depending on how you want to represent the device on the network. The parameter config_methods defines the pairing methods: pbc (Push Button Config) or entering a PIN code.

It is also worth paying attention to the parameter p2p_no_group_ifaceIf this setting is enabled, the group will be created on the existing interface, which can be convenient, but not all drivers support it. For now, it's best to leave the default behavior.

  • 🎯 Install p2p_oper_channel=6 (or another free channel) for stable operation.
  • 🔐 Use config_methods=display pbc for maximum compatibility with Android and Windows.
  • 📶 Make sure that driver=nl80211, as this is the modern Linux driver standard.

After saving the file, don't rush to launch the service. Check the syntax with the command wpa_supplicant -c /etc/wpa_supplicant/p2p.conf in test mode, if such an option is available, or simply monitor the logs during startup.

Decoding Device Type codes

The code consists of a category prefix, an OUI (organization identifier), and a subcategory. For example, 1-0050F204-5 represents the "Portable" category (1), the Wi-Fi Alliance OUI (0050F204), and the "Handheld" subcategory (5). This helps devices understand who they're connecting to and select the appropriate interface.

Starting the service and searching for devices

Once the configuration is ready, you can start the daemon. We'll use the interactive interface. wpa_cli, which allows you to manage the connection in real time. This is much more convenient than editing files and restarting services every time an error occurs.

Launch wpa_supplicant in the background, specifying the path to our config and the interface name (usually wlan0 or wlp2s0):

sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/p2p.conf -D nl80211 -B

Flag -B means running in the background. Now launch the management client:

sudo wpa_cli -i wlan0 -p /var/run/wpa_supplicant

Inside the interactive shell wpa_cli the first command should be p2p_findIt starts scanning the surrounding area for other devices ready to connect via WiFi Direct. The process can take 10 to 30 seconds.

In logs or in response to a command p2p_peers You'll see a list of found devices with their MAC addresses and names. If the list is empty, check if WiFi Direct is enabled on the receiving device (e.g., a smartphone or printer).

  • 🔍 Team p2p_find starts searching for neighbors.
  • 👥 Team p2p_peers displays a list of detected devices.
  • ℹ️ Team status will show the current state of the P2P machine.

If devices are found but a connection fails, try increasing the search time or changing the channel. Sometimes interference on Channel 6 can interfere with detection.

📊 What device do you most often connect to Linux?
Android smartphone
Printer
Smart TV
Another Linux PC

Pairing and creating a group

Once the target device is detected, a connection must be initiated. In WiFi Direct terminology, one device becomes Group Owner (GO), and the other is the client. GO acts as an access point, distributing IP addresses.

IN wpa_cli use the command p2p_connect [MAC address] pbc, if the Push Button method is selected, or p2p_connect [MAC address] display for a PIN code. If you select the PIN method, the system will generate a code that you will need to enter on the second device.

After a successful handshake, the daemons will automatically create a virtual interface and start the DHCP server. Your device will receive an IP address in the subnet, usually a range 192.168.172.x.

You can check the success of the connection with the command ip addr. You should see a new interface (often prefixed with p2p-) with the assigned IP. Now an L2/L3 communication channel is established between the devices.

  • 🔗 Team p2p_connect initiates a connection with the selected peer.
  • 🔢 For the PIN method, use p2p_pin [PIN code] or p2p_pin random.
  • ✅ Status COMPLETED in the conclusion status means the successful creation of the group.

It is important to understand that after creating a group, regular WiFi (infrastructure mode) on this interface may stop working if the card does not support simultaneous operation in several modes (MCC - Multi Channel Concurrency).

⚠️ Note: When creating a group, your Linux PC may become a gateway for the connected device. Make sure your system has a firewall (iptables/nftables) configured to prevent closed ports from being accessible from the outside.

Transferring files and using the connection

WiFi Direct itself is just a transport channel (Layer 2). It can't transfer files out of the box without additional software. Unlike AirDrop or Quick Share, in Linux you need to select an application-layer protocol.

The easiest and most reliable way is to use the protocol FTP or SFTPYou can run an FTP server on a Linux machine, and then a smartphone connected via WiFi Direct will be able to access it as a network drive.

An alternative is to use specialized utilities such as gsconnect (KDE Connect implementation for GNOME) or warpinator (from the creators of Linux Mint). These programs automatically detect devices on a local network created via WiFi Direct.

For fast transfer you can use netcat or scp, if there is SSH on both ends. For example, the command scp file.txt user@192.168.172.10:/home/user/ will instantly transfer the file.

  • 📂 Install vsftpd or python3 -m http.server for quick access to files.
  • 📱 Use applications like KDE Connect for easy syncing and transferring.
  • 🚀 For geeks: nc -l -p 1234 > received_file to receive files via raw TCP.

The transfer speed in WiFi Direct mode can reach 20-30 MB/s depending on the supported standards 802.11n/ac both devices and signal quality.

Troubleshooting and Error Table

Setting up WiFi Direct on Linux rarely goes smoothly the first time. Drivers can behave unpredictably, and versions wpa_supplicant may vary across different distributions. Below is a table of problems and their solutions.

If you encounter a problem that is not in the table, first check the system logs via journalctl -u wpa_supplicant or dmesg | grep firmwareFirmware errors are a common cause of interface crashes.

Error / Symptom Possible cause Solution
Interface busy The interface is busy with NetworkManager Stop NM: systemctl stop NetworkManager
P2P_FIND fails The driver does not support P2P or the channel is busy. Check iw list, change p2p_oper_channel
Connection timeout Mismatch of WPS methods (PIN vs PBC) Make sure the same method is selected on both devices
No IP address The DHCP server did not start. Check the launch dnsmasq or settings wpa_supplicant
Driver nl80211 error The driver is incompatible with the kernel version. Update the kernel or rebuild the driver module

A common problem is the interface getting stuck in a P2P state. To reset the state, it's sometimes necessary to completely unload and load the kernel module: rmmod And modprobe for your driver (for example, iwlwifi or rtl8821ce).

It's also worth remembering that some routers may conflict with active WiFi Direct if they operate on the same channel. In this case, switching the router to 5 GHz or changing the channel on the WiFi Direct interface may help.

☑️ Troubleshooting Checklist

Completed: 0 / 4

Frequently Asked Questions (FAQ)

Is it possible to use regular WiFi (Internet) and WiFi Direct at the same time?

It depends on your hardware. The technology is called MCC (Multi-Channel Concurrency). If your card and driver support the creation of virtual interfaces (iw phy shows valid interface combinations (If you're using different channels, then yes. Otherwise, turning on WiFi Direct will cut off internet access through the router.)

Does WiFi Direct work on all Linux distributions?

Yes, the principle of operation wpa_supplicant The same applies to all. However, in distributions with strict security policies (such as Fedora or RHEL), some modules may be disabled by default, or SELinux may block socket creation. In such cases, fine-tuning of security policies is required.

Is it safe to transfer files via WiFi Direct?

The connection is secured using the WPA2 protocol, with keys generated dynamically during each pairing (WPS). However, since this is a direct connection, ensure you are connecting to a trusted device and not to an attacker running a similarly named hotspot (Evil Twin attack). Always verify the PIN or physically confirm the connection.

Why doesn't wpa_cli see the p2p_find command?

Most likely a running copy wpa_supplicant was not initialized with the P2P option or the wrong control interface is being used. Make sure you are running wpa_cli with a flag -p /var/run/wpa_supplicant (the path may differ) and that P2P is enabled in the config.

Is it possible to share the Internet from Linux to a phone via WiFi Direct?

Technically, this is possible, but difficult to implement. WiFi Direct is designed for P2P, not NAT. You'll need to configure IP forwarding and NAT via iptables, as well as start the DHCP server manually. It's easier to use the "Access Point" (HostAP) mode, which is supported by most modern cards and is easier to configure via nmcli.