debian - Setting up a wifi hotspot with brctl and hostapd

07
2014-07
  • Gilberto T.

    I am trying to set up a wifi hotspot using brctl and hostapd on Debian GNU/Linux but it seems it does not work. The steps I follow are the following:

    echo 1 > /proc/sys/net/ipv4/ip_forward
    brctl addbr br0
    brctl addif br0 eth0
    dhclient br0
    

    Until now it works and I am able to surf the web using the wired connection. Then, I launch hostapd. It adds wlan0 to the bridge and the wired conncetion stops to work: I am not able to surf the web and the smartphone (with Android) is able to authenticate with the hotspot but does not get an IP address and says "Limited conncetion".

    I have read several guides and howtos but I cannot find a solution. Any suggestion?

  • Answers
  • MariusMatutiae

    There are a few key points to consider:

    1. You must disable network manager:

      sudo service network-manager stop
      
    2. You must start hostapd before the bridge:

      sudo hostapd -B /etc/hostapd/hostapd.conf
      
    3. Now you just add eth0 to an existing bridge:

      sudo brctl addif br0 eth0
      
    4. and you put your bridge onto the network:

      sudo dhclient br0
      
    5. Now you have to check that your routing table is working:

      sudo add -net 0.0.0.0/0 gw IP_address_of_your_router dev br0
      sudo del -net 0.0.0.0/0 gw IP_address_of_your_router dev eth0
      
    6. Now you add nameservers to /etc/resolv.conf: as sudo,

      echo nameserver 8.8.8.8 >> /etc/resolv.conf
      echo nameserver 8.8.4.4 >> /etc/resolv.conf
      

    Mine works as above: I am writing through it just now.

  • Journeyman Geek

    I ended up choosing another way to doing the same thing, based off the guide here - using /hosts/networks is probably better if you need an always on hostapd AP, but probably less use otherwise.

    Here's my /etc/networks file - I've set wlan0 as manual , and bridged eth0.

    # wireless wlan0
    allow-hotplug wlan0
    iface wlan0 inet manual
    
    # eth0 connected to the ISP router
    allow-hotplug eth0
    iface eth0 inet manual
    #iface eth0 inet6 auto
    # Setup bridge
    iface br0 inet static
        bridge_ports wlan0 eth0
        address 192.168.1.127
        netmask 255.255.255.0
        network 192.168.1.0
        gateway 192.168.1.1
        dns-nameservers 192.168.1.1
    

    Your hostapd.conf might also be of interest there - this is a stripped down version of mine, since I chose to edit the 'stock' one. I suspect its pretty likely your problem might be there.

    ### Wireless network name ###
    interface=wlan0
    ### Set your bridge name ###
    bridge=br0
    driver=nl80211
    
    ###CHANGE ANYTHING BELOW THIS TO SUIT!###
    
    ### (IN == INDIA, UK == United Kingdom, US == United Stats and so on ) ###
    country_code=SG
    hw_mode=g
    channel=6
    wpa=2
    ## Key management algorithms ##
    wpa_key_mgmt=WPA-PSK
    
    ## Set cipher suites (encryption algorithms) ##
    ## TKIP = Temporal Key Integrity Protocol
    ## CCMP = AES in Counter mode with CBC-MAC
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    
    ## Shared Key Authentication ##
    auth_algs=1
    
    ## Accept all MAC address ###
    macaddr_acl=0
    

  • Related Question

    networking - Ubuntu Laptop as a wireless hotspot on bridge mode
  • nixnotwin

    I have a wired router to which my ubuntu laptop connects via ethernet. The wierless NIC of the laptop acts as a wireless hotspot on master mode. I use hostapd fo this. I have bridged eth0 and wlan0, so my wireless clients that connect to my laptop over wifi get ip from the wired router via dhcp, so the devices get registered at the wired router ( and the laptop is just an access point). I use the following commands to get my laptop+accesspoint working:

    sudo brctl addbr br0
    sudo brctl addif br0 eth0
    sudo hostapd /etc/hostapd/hostapd.conf &
    sudo dhclient -d br0 & 
    sudo ifconfig wlan0 192.168.1.15 netmask 255.255.255.0 up
    sudo brctl addif br0 wlan0
    

    These commands enable me to access internet on my wireless clients and also on the laptop which is acting as wireless accesspoint. But if I reboot the wired router (without rebooting the laptop that is acting as accesspoint), Internet access on the laptop+accesspoint gets lost, but on wireless clients it works fine. Even I have not been able to figure out a command which will reset the laptop interfaces to default settings, so everytime the router reboots, I have to reboot the laptop too to get into default settings so that I can re-enter the above mentioned commands. My first question is How can I have my bridge+accesspoint up and running even-though the router reboots? And is there a command to set the interfaces to a default state? (ifdown -a doesn't work, after issuing the command the bridge still remained).


  • Related Answers
  • BillThor

    You need to edit /etc/network/interfaces to add the correct configuration. Something like the following should do.

    # The primary network interface
    auto  br0
    iface br0 inet dhcp  
        pre-up brctl addbr br0
        post-up brtcl addif br0 eth0
        pre-down brctl delif br0 eth0
        post-down brctl delbr br0
    
    iface eth0 manual
    
    #auto wlan0
    iface wlan0 inet static
        address 192.168.1.15
        netmask 255.255.255.255.0
        post-up addif br0 wlan0
        post-up hostapd /etc/hostapd/hostapd.conf &
        wireless-channel 3
        wireless-essid mysid
        wireless-mode managed
        wireless-rate 54M auto
        wpa-ap-scan 2
        wpa-bssid mysid xx:xx:xx:xx:xx:xx
        wpa-eapol_version 1
        wpa-group TKIP
        wpa-key-mgmt WPA-PSK
        wpa-pairwise TKIP
        wpa-proto WPA
        wpa-psk mykey
        wpa-scan-ssid 1
        wpa-ssid mysid
    

    There are options for /etc/network/interfaces to setup the wireless configuration using the wireless- prefix. The supplicant program uses the wpa- prefix. The values above were grabbed from a client. The hostapd program may take care some or all these settings.

    The DHCP client will be started automatically by the above configuration. man interfaces will display the documentation for the configuration file.