Networking – Ubuntu Laptop as a wireless hotspot on bridge mode

bridgenetworkingwireless-networking

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

Best Answer

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.

Related Question