3

How can I use wifi connections as an access point while at the same time connecting to an existing wifi network ?

My experiment:

sudo iw dev wlan0 interface add uap0 type __ap
service dnsmasq restart
sysctl net.ipv4.ip_forward=1
sudo hostapd /etc/hostapd/hostapd.conf

Output:

Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.uap0: -95 (Operation not supported)
uap0: Could not connect to kernel driver
Using interface uap0 with hwaddr b8:27:a1:0f:00:00 and ssid "TESTAP"
Failed to set beacon parameters
uap0: Could not connect to kernel driver
Interface initialization failed
uap0: interface state UNINITIALIZED->DISABLED
uap0: AP-DISABLED
uap0: Unable to setup interface.
uap0: interface state DISABLED->DISABLED
uap0: AP-DISABLED
hostapd_free_hapd_data: Interface uap0 wasn't started
nl80211: deinit ifname=uap0 disabled_11b_rates=0

/etc/hostapd/hostapd.conf:

interface=uap0
ssid=TESTAP
hw_mode=g
channel=10
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=123456789a
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
a.gulcan
  • 53
  • 1
  • 4
  • IIRC from posts I have seen it can work, but you have to use the same channel for client and AP. And I think people mentioned that performance was not great. See e.g. https://www.raspberrypi.org/forums/viewtopic.php?t=138730#p936518 (topic runs over several pages) – Dirk Aug 25 '18 at 13:30
  • `pi@raspberrypi:~ $ iw wlan0 info Interface wlan0 ifindex 3 wdev 0x1 addr b8:27:eb:ff:00:00 type managed wiphy 0 channel 4 (2427 MHz), width: 20 MHz, center1: 2427 MHz txpower 31.00 dBm` `pi@raspberrypi:~ $ iw uap0 info Interface uap0 ifindex 4 wdev 0x3 addr b8:27:eb:ff:00:00 type AP wiphy 0 channel 4 (2427 MHz), width: 20 MHz, center1: 2427 MHz txpower 31.00 dBm` I did same channel but i got same error – a.gulcan Aug 25 '18 at 17:58

1 Answers1

4

You have to do three steps:

  1. create a virtual interface ap0 for the access point
  2. start access point daemon hostapd using interface ap0
  3. start wpa_supplicant for wifi client using interface wlan0

You have to do it exactly in this order otherwise the setup will fail. I have seen many attempts to achieve this including restarting services in order with special conditions. I prefer to use systemd because you can define dependencies when services have to start. So you can configure it in a clean order. How to do this in detail you can look at Access point as WiFi repeater, optional with bridge.

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • Thanks It's worked. But My iptables rules don't work on hotspot. Can u help me? [how-does-iptables-rules-table-work-with-hotspo](https://raspberrypi.stackexchange.com/questions/88506/how-does-iptables-rules-table-work-with-hotspot) – a.gulcan Aug 26 '18 at 13:29
  • @a.gulcan Sorry I'm not so familiar with iptables. But iptables is a firewall and usually used to restrict connections. If you want a firewall then from your working access point you can restrict it step by step. – Ingo Aug 26 '18 at 16:41
  • I can't reset hostapd.service. is there a way to solve this problem? except reboot – a.gulcan Feb 01 '19 at 06:59
  • @a.gulcan What do you mean with *reset hostapd*? I have updated the link in my answer. If you follow it you can stop, start and restart **hostapd**. Please read the section **Conclusion**. – Ingo Feb 01 '19 at 09:45