Setting up a wifi hotspot with brctl and hostapd

15,993

Solution 1

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.

Solution 2

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
Share:
15,993

Related videos on Youtube

Gilberto T.
Author by

Gilberto T.

Updated on September 18, 2022

Comments

  • Gilberto T.
    Gilberto T. over 1 year

    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?

    • Gilberto T.
      Gilberto T. about 10 years
      I prefer to set it manually by console but post your config here, thx.
    • ceving
      ceving over 6 years
      A bridge is something, which has two ends. Adding just one interface to the bridge makes a bridge stopping in the middle of the river.
  • Thalys
    Thalys about 10 years
    assuming he uses network manager. I also seem to think he may need to include wlan0 in the bridge wouldn't he?
  • MariusMatutiae
    MariusMatutiae about 10 years
    @JourneymanGeek No he wouldn't: the configuration file for hostapd mmust contain an instruction, bridge=br0, which will create the bridge for him. And of course, the same conf file will contain an instruction interface=wlan0. But it already does, because the OP claims the hostap service is correctly started , and clients can connect.
  • Gilberto T.
    Gilberto T. about 10 years
    I've tried. In this case "dhclient br0" does not work.
  • MariusMatutiae
    MariusMatutiae about 10 years
    @GilbertoT. What do you mean by it does not work? You do not get a DHCP offer?
  • Gilberto T.
    Gilberto T. about 10 years
    I don't use "country_code=" "macaddr_acl=". The rest of the configuration file is similar.
  • MariusMatutiae
    MariusMatutiae about 10 years
    @GilbertoT. It sounds like an initialization problem. Perhaps you should have started with a clean slate.
  • Gilberto T.
    Gilberto T. about 10 years
    @MariusMatutiae I've put down all interfaces and I've tried but br0 still does not get a DHCP offer. And after step 3 (above), if I type ifconfig I don't see br0. Is it normal?
  • MariusMatutiae
    MariusMatutiae about 10 years
    @GilbertoT. No it is not. It seems to imply your hostapd did not create a br0 interface for you, while mine did. Then do create the bridge first (brctl addbr br0), then try starting hostapd, then you add the eth0 interface. Pls let me know how it goes
  • Gilberto T.
    Gilberto T. about 10 years
    @MariusMatutiae It still does not work. :/ If I shutdown hostapd, br0 gets the IP from DHCP.
  • MariusMatutiae
    MariusMatutiae about 10 years
    @GilbertoT. Looks like a bug. I would suggest to you to reinstall bridge-utils and hostapd packages.
  • Gilberto T.
    Gilberto T. about 10 years
    @MariusMatutiae I'll try and then I'll tell you.
  • Gilberto T.
    Gilberto T. about 10 years
    It still doesn't work.