Creating WiFi Access point on a single interface in Linux
Solution 1
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 :
- turn off network manager service as it interferes with virtual interfaces
- turn down wlan0 using ifconfig wlan0 down
- create access point interface using iw command (type __ap), assign it a different mac and ip address
- turn on hostapd at this access interface
- 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
- turn on dnsmasq at the access interface. Now the client will be able to connect to the access point and obtain ip addresses.
- 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.
- if necessary perform ip masquerading through iptables command
Solution 2
Setup a dummy network
1 Open the console
su -
2 See if you have a dummy driver
modprobe -l | grep /net/dummy.ko
(!) If you do not have a dummy driver, go to "Create kernel module".
3 Load dummy driver
modprobe dummy
(!) Do not add it to startup if it fails.
4 Test dummy0 by putting it up
ifconfig dummy0 10.246.75.1 netmask 255.255.255.0 broadcast 10.246.75.255 up
ifconfig
It will give you a similar output.
dummy0 Link encap:Ethernet HWaddr 00:2D:32:3E:39:3B
inet addr:10.246.75.1 Bcast:10.246.75.255 Mask:255.255.255.0
...
5 Add dummy driver to startup
Edit kernel sys file.
nano /etc/sysconfig/kernel
and add "dummy" to MODULES_LOADED_ON_BOOT.
MODULES_LOADED_ON_BOOT = "..."
Ex. MODULES_LOADED_ON_BOOT = "vmcp dummy".
6 Configure the network settings for dummy0
Create ifcfg-dummy0 file.
nano /etc/sysconfig/network/ifcfg-dummy0
Add to ifcfg-dummy0 file:
# Configuration for dummy0
BOOTPROTO=static
# This line ensures that the interface will be brought up during boot.
STARTMODE=onboot
# dummy0 - This is the main IP address that will be used for most outbound connections.
# The address, netmask and gateway are all necessary. The metric is not necessary but
# ensures you always talk to the same gateway if you have multiple public IPs from
# different subnets.
IPADDR=10.246.75.1
NETMASK=255.255.255.0
BROADCAST=10.246.75.255
GATEWAY=10.246.75.1
Create kernel module
1 First installing the necessary things
Open YaST.
Navigate to Software
-> Software Management
.
Tick:
Development
[X] Base Development
[X] Linux Kernel Development
[X] C/C++ Development
2 Back to the console and navigate to the kernel source
cd /usr/src/linux
3 Import the current kernel configuration
zcat /proc/config.gz > .config
4 Open kernel menuconfig
make menuconfig
5 Add Dummy net driver support
Navigate to Device Drivers
-> Network device support
* Network core driver support
M Dummy net driver support
(!) If you have an asterisk next to "Network core driver support" you can skip step 7 and 9.
6 Compile the kernel
make -j(n+1)
Where (n+1) = number of CPU cores plus one used to speed up the compile. For four cores use make -j5.
7 Install the new kernel
make install
8 Install modules
make modules_install
9 Load the new kernel
reboot
Defining a VIPA (The part about loading module and ifcfg-dummy0): http://wiki.linuxvm.org/wiki/Defining_a_VIPA
Configure Static IPs:
https://www.linode.com/wiki/index.php/Configure_Static_IPs
openSUSE 12.3 and Installing New Linux Kernel Versions from kernel.org: http://forums.opensuse.org/blogs/jdmcdaniel3/opensuse-installing-new-linux-kernel-versions-134/
OpenSUSE 11.2 - How to compile a Kernel for Newbies: http://linuxtweaking.blogspot.dk/2010/04/opensuse-112-how-to-compile-kernel-for.html
Solution 3
Create virtual interface
Create ifcfg-wlan0:0 file
nano /etc/sysconfig/network/ifcfg-wlan0:0
Add to ifcfg-wlan0:0 file:
DEVICE=wlan0:0
# Configuration for wlan0:0
ONBOOT=yes
# This line ensures that the interface will be brought up during boot.
BOOTPROTO=static
# wlan0:0 - This is the main IP address that will be used for most outbound connections.
# The address, netmask and gateway are all necessary. The metric is not necessary but
# ensures you always talk to the same gateway if you have multiple public IPs from
# different subnets.
IPADDR=10.246.75.1
NETMASK=255.255.255.0
BROADCAST=10.246.75.255
GATEWAY=10.246.75.1
The commands to activate interface
ifup wlan0:0
Note: Shutting down the main interface also shuts down all its aliases too. Aliases can be shutdown independently of other interfaces.
Check if the interface works
ifconfig
It will give you a similar output.
wlan0:0 Link encap:Ethernet HWaddr 00:2D:32:3E:39:3B
inet addr:10.246.75.1 Bcast:10.246.75.255 Mask:255.255.255.0
...
Related videos on Youtube
adityap174
Updated on September 18, 2022Comments
-
adityap174 over 1 year
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. Thewlan
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 ?
-
Diblo Dk almost 11 yearsHave you tried with "Dummy net driver support" (Kernel driver) as module. I can not help you more than that because I do not know openSUSE. But I can see that there are errors reported from version 11 and higher when it is built with Yast. So be careful.
-
Diblo Dk almost 11 yearsI can of course help you, if it can be done in the same ways (Kernel config, network setup) as in Gentoo, Debian or Ubuntu.
-
adityap174 almost 11 yearsAny help will be appreciated. I am not using the Yast tools as such. The configurations were from a tutorial on Ubuntu. The file system and the configurations are almost the same.
-
Diblo Dk almost 11 yearsWhat is your kernel version?
-
adityap174 almost 11 yearsKernel: x86_64 Linux 3.7.10-1.16-desktop
-
Diblo Dk almost 11 yearsYou must remember to tell what problems you have solved self so the answer may be updated. :)
-
imz -- Ivan Zakharyaschev over 10 yearsSame question again: superuser.com/questions/639479/… And again: superuser.com/questions/649220/a-wifi-ap-with-a-single-nic/…
-
-
adityap174 almost 11 yearsThanks for such a detailed explanation. I tried this method. I was able to create dummy0 interface and start in on boot. But how do you make it a wireless interface ? iwconfig gives : dummy0 no wireless extensions. hostapd doesn't work with this. It gives error : nl80211 driver initialization failed
-
Diblo Dk almost 11 yearsYes, the problem is that you have an IP conflict. But it could be done with Pseudo module (Assign multiple IP addresses). Give me some time to look it up for your system.
-
adityap174 almost 11 yearseven this was not working with hostapd. It gave the same error : Could not open file /sys/class/net/dummy0/phy80211/name: No such file or directory with dummy0 and Could not open file /sys/class/net/wlan0:0/phy80211/name: No such file or directory with the virtual interface. Thanks for all your help. :) The problem was with mac address. I have upvoted your answers and i am posting the solution for others.
-
Diblo Dk almost 11 yearsto put it bluntly, WTF hostapd :)
-
Diblo Dk almost 11 yearsCan you update your answer with the exact steps you made. This is definitely an answer I'd like to save.
-
adityap174 almost 11 yearsupdated :) want more details ?
-
Diblo Dk almost 11 yearsCool way to get around the problem :)
-
fuechselein about 9 yearsWhat dongle / chipset were you using?
-
Veerendra over 6 years@adityap174 Hi, still I'm not sure how did you setup? Can you check my question unix.stackexchange.com/questions/411478/…