ubuntu - Setting up Access Point using Wifi adapter in linux

04
2013-08
  • peterfra

    My router broke so I am trying to setup something temporarily to share internet connection from my main pc (internet comes from modem connected directly to ethernet card) to other devices via an ad hoc network, for that I have a wifi adapter that uses the zd1211rw driver (i also have the alfa rtl8187 but that adapter is not working at all on ubuntu 12.04).

    The problem that I am having is that I can't connect to the wifi AP I create, it just stays "acquiring network address" and never finish connecting.

    My main computer OS is Ubuntu 12.04, this is what I am doing. First I put the wifi adapter on monitor mode with:

    airmon-ng start wlan2
    

    This creates a mon0 interface, then I use:

    airbase-ng -e MyNetName -c 11 -v mon0
    

    From here I can already see the MyNetName network using my laptop (with windows), but if I try to connect it stays at "acquiring network address". The tutorials I followed continue with these commands:

    ifconfig at0 up
    ifconfig at0 192.168.1.254 netmask 255.255.255.0
    route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
    
    iptables --flush
    iptables --table nat --flush
    iptables --delete-chain
    iptables --table nat --delete-chain
    iptables -P FORWARD ACCEPT
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    echo > '/var/lib/dhcp/dhcpd.leases'
    

    Then I start the dhcp server with

    dhcpd -d -f -cf /etc/dhcp/dhcpd.conf at0
    

    The dhcpd.conf file looks like this:

    ddns-update-style interim; <- also tried ad-hoc instead of interim
    default-lease-time 600;
    max-lease-time 7200;
    authoritative;
    subnet 192.168.1.0 netmask 255.255.255.0 {
      option subnet-mask 255.255.255.0;
      option broadcast-address 198.168.1.255;
      option routers 192.168.1.254;
      option domain-name-servers 8.8.8.8;
      range 192.168.1.1 192.168.1.253;
    }
    

    The output looks like:

    Internet Systems Consortium DHCP Server 4.1-ESV-R4
    Copyright 2004-2011 Internet Systems Consortium.
    All rights reserved.
    For info, please visit https://www.isc.org/software/dhcp/
    Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
    Wrote 0 leases to leases file.
    Listening on LPF/at0/00:02:72:69:28:c8/192.168.2.128/25
    Sending on   LPF/at0/00:02:72:69:28:c8/192.168.2.128/25
    Sending on   Socket/fallback/fallback-net
    Can't create PID file /var/run/dhcpd.pid: Permission denied.
    

    The last command:

    echo "1" > /proc/sys/net/ipv4/ip_forward
    

    The airbase-ng command output looks like this:

    11:34:03  Created tap interface at0
    11:34:03  Trying to set MTU on at0 to 1500
    11:34:03  Trying to set MTU on mon0 to 1800
    11:34:03  Access Point with BSSID 00:02:72:69:28:C8 started.
    11:34:10  Client 70:F3:95:B3:27:76 associated (unencrypted) to ESSID: "MyNetName"
    11:34:13  Client 70:F3:95:B3:27:76 reassociated (unencrypted) to ESSID: "MyNetName"
    11:34:17  Client 70:F3:95:B3:27:76 reassociated (unencrypted) to ESSID: "MyNetName"
    11:34:21  Client 70:F3:95:B3:27:76 reassociated (unencrypted) to ESSID: "MyNetName"
    

    So my problem is that I cannot get an internal ip on the laptop that is trying to connect, the windows wifi manager thing just stays at "acquiring network address", airbase reacts by showing more of those reassociated messages while the laptop tries to connect. Another problem is that after running iptables --flush the internet in the main PC stops working, but I want to deal with that once I am able to fully connect to MyNetName.

    Does anyone have an idea what am I doing wrong?

  • Answers
  • gnp

    I've never seen this setup using airbase-ng... maybe you could try out hostapd to solve the constant reassociation issue.

    Also, this route doesn't make much sense:

    route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
    

    Try without it.

    Finally, you could try installing tcpdump and monitoring network traffic on at0 while client is supossedly trying to acquire dhcp. Maybe the dhcp request isn't even getting through.

  • user1990426

    You could try using isc-dhcp-server. I've currently got a very similar setup to you with that being the only difference.

    Install it -> change /etc/default/isc-dhcp-server to serve on at0 interface -> start it using

    service isc-dhcp-server start

    This will still use your dhcpd.conf file.


  • Related Question

    wireless networking - Difference between wifi router and access point?
  • OverTheRainbow

    I see both terms used, and I was wondering what the difference is between a wifi router, and a wifi access point. Does the latter only create a LAN, with no way to connect the wifi box with a second network?

    Thank you.


  • Related Answers
  • mateusza

    Access Point is just a bridge between wired and wireless networks. It only operates in 1st and 2nd layer. It doesn't perform any 3rd-layer operations (routing, NAT-ing, IP filtering...)

  • heavyd

    For the most part the two are used interchangeably, however, technically there is a difference and for the most part consumers only use WiFi Routers.

    A WiFi router is a WiFi access point with a built in router. The router allows you to connect multiple computers to the network using a single IP address, typically provided by your ISP.

    A WiFi access point is typically used only in enterprise networks where they have a larger router which routes their entire network and the access point only acts as a gateway between the wired and wireless networks.

  • Xeeshawn

    The access point acts as an ethernet switch, has one Ethernet port and allows WiFi stations to access the same LAN the access point is in.

    The router will typically have 4 ethernet ports, 1 special ethernet port called "internet" and will allow creating a new subnet for the Wifi, with DHCP, acting as the default gateway for this subnet