Creating WiFi Access point on a single interface in Linux

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

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


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
         ...

http://forums.opensuse.org/english/get-technical-help-here/network-internet/461132-os-11-4-network-manager-default-connection-can-handle-virtual-interfaces.html#post2350426