Linux – Create WiFi Access Point on Single Interface

dhcphostapdhotspotlinuxwireless-access-point

I am trying to create a WiFi hotspot or an access point on my Linux laptop. I am using Opensuse Kde 12.3.

I found out a software called hostapd which lets you create hotspot but it requires two interfaces. One connected to the internet and the other on which you want to create the access point (tutorial here) . The problem I have is that I don't have Ethernet connection. The wlan interface is being used to connect to the internet.

Is there any way to create the hotspot on the same interface that is connected to the Internet (like the software connectify does on Windows)? I was thinking of creating a virtual interface (like the one airmon-ng creates to monitor wifi) and use it as the second interface. Is this possible?

UPDATE

Here's what i have been able to do up till now :

1) Create 2 interfaces ( one as station and the other as an access point )

  iw phy phy0 interface add mySta type station
  iw phy phy0 interface add myAcc type __ap

2) Give them seperate Mac ID

ifconfig myAcc hw ether A4:17:FE:6E:00:53
ifconfig myAcc 192.168.27.1 up

3) start hostapd on the myAcc interface

4) start dnsmasq to provide ip address to the connecting devices

All of this works. Devices are able to connect to this network and obtain Ip Address.
The next step is to provide ip masquerading

iptables --table nat --append POSTROUTING --out-interface mySta -j MASQUERADE
iptables --append FORWARD --in-interface myAcc -j ACCEPT

But the mySta interface now fails to connect to the internet. It is able to obtain the Essid but it cannot obtain the ip address.

The command dhclient mySta doesn't show any message and after some time gives the error :

ls: cannot access /var/run/netconfig//mySta/: No such file or directory

Can someone figure out how to obtain the ip address ?

Best Answer

For anyone else facing this problem, the problem was with mac address. I started the access point interface, gave it a mac address. Then after running hostapd, added the station interface, gave it a different mac address and connected it to the network and gave the station's ip address as the default gateway of the clients through dnsmasq.

Now everything is working properly.

As pointed out by Diblo Dk, you could use virtual and dummy interfaces but hostapd wasn't working with them. I don't know why.

Here are the steps :

  1. turn off network manager service as it interferes with virtual interfaces
  2. turn down wlan0 using ifconfig wlan0 down
  3. create access point interface using iw command (type __ap), assign it a different mac and ip address
  4. turn on hostapd at this access interface
  5. use dnsmasq to assign the connecting clients at this interface, ip addresses and give the default gateway as the ip of the station interface to be created
  6. turn on dnsmasq at the access interface. Now the client will be able to connect to the access point and obtain ip addresses.
  7. create new interface (type station) assign it separate mac address and connect it to the network by assigning essid and using dhclient to obtain ip address.
  8. if necessary perform ip masquerading through iptables command
Related Question