4

I'm building wifi-router (hostapd, dnsmasq) on Raspberry pi 3 (Raspberrian Stretch). Wlan0 configured as static IP adapter for hostapd. It works fine for eth0 -> wlan0 direction. In this case, wpa_supplicant is empty.

But I cannot share internet from another wifi adapter wlan1 -> wlan0. In this case, wpa_supplicant has network settings and wlan0 connects to the source network.

I had no such problem on raspbian jessie.

How to force wlan0 to not automatically connect to wifi networks?


if wpa_supplicant contains password ifconfig returns following output:

root@raspi3:/home/pi/vrouter# wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.53  netmask 255.0.0.0  broadcast 192.255.255.255
        inet6 fe80::69cb:7b25:d42b:e33f  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:53:2d:1d  txqueuelen 1000  (Ethernet)
        RX packets 266  bytes 50171 (48.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 47  bytes 7212 (7.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

if wpa_supplicant contains no passwords ifconfig returns proper wlan0 setting:

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.1  netmask 255.0.0.0  broadcast 10.255.255.255
        inet6 fe80::e460:9b98:5dea:599d  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:53:4d:fd  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 4966 (4.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="my_internet"
    psk="qwerty123"
    key_mgmt=WPA-PSK
}

interfaces contains only one line:

source-directory /etc/network/interfaces.d

dhcpcd.conf:

hostname
clientid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

interface wlan0
static ip_address=10.0.0.1/8
static routers=10.0.0.1 

dnsmasq.conf:

no-resolv

interface=wlan0
except-interface=wlan1
except-interface=wlan2
except-interface=wlan3
except-interface=eth0

dhcp-range=10.0.0.3,10.0.0.20,12h

server=8.8.8.8
server=8.8.4.4
log-facility=/var/log/dnsmasq.log
log-queries

hostapd.conf:

interface=wlan0
driver=nl80211
ssid=Raspberry3
channel=6
country_code=US
ieee80211d=1
ieee80211n=1
wmm_enabled=1
hw_mode=g
#auth
wpa=2
wpa_passphrase=Myau1Kot
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP 
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0
ignore_broadcast_ssid=0

# control
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2

ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

1 Answers1

4

You should be able to achieve your objectives by a combination of the following 2 settings (extract from How to set up networking/WiFi ]

Prevent dhcpcd from configuring an interface

This is often done to enable the Pi to act as an Access Point (which needs to be configured using other files), while allowing normal DHCP configuration on other interfaces.

Add denyinterfaces wlan0 to the end of the file (but above any other added interface lines).

Use different wpa_supplicant files

It is possible to configure dhcpcd to use different wpa_supplicant.conf files for a specific wireless interface.

Create a file named wpa_supplicant-"$interface".conf in /etc/wpa_supplicant/ e.g. wpa_supplicant-wlan0.conf will only be used by wlan0

/etc/wpa_supplicant/wpa_supplicant.conf will be used for any other wireless interfaces.

Milliways
  • 54,718
  • 26
  • 92
  • 182