Draadloze Netwerken
Menu

Ubuntu als AP


USING ubuntu ON LATITUDE AS A WIFI ACCESS POINT WITH HOSTAPD


use ubuntu 14.04 and do the following in ubuntu

PACKAGES

Make an ethernet connection
Update the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies:
sudo apt-get update
The first step is to install the required packages: 
sudo apt-get install dnsmasq hostapd

I'll go into a little detail about the two:

·         hostapd - This is the package that allows you to use the built in WiFi as an access point

·         dnsmasq - This is a combined DHCP and DNS server that's very easy to configure

If you want something a little more 'heavyweight', you can use the isc-dhcp-server and bind9 packages for DHCP and DNS respectively, but for our purposes, dnsmasq works just fine.

CONFIGURE YOUR INTERFACES

The first thing you'll need to do is to configure your wlan0 interface with a static IP.

First You must check if Network Manager is managing your network interface.

Open a terminal,

Press Ctrl+Alt+T

Run it:

sudo -i

nmcli dev status

The above command will list all existing network interfaces along with their state. If state is shown as unmanaged, this means Network Manager is not controlling a corresponding interface. If state displays any other values:

DEVICE TYPE STATE

wlan0 802-11-wireless (dis)connected

It implies that a given interface is managed by Network Manager.

To disable Network Manager for your wlan0, you can do the following.

Edit the Network Manager configuration file in /etc/NetworkManager, and set:

managed=false

In the terminal continue running:

nano /etc/NetworkManager/NetworkManager.conf

And write the following lines:

[ifupdown]

managed=false

Ctrl + O, save file. Ctrl + X, close nano.

Then in /etc/network/interfaces, add information about the interface you want to disable Network Manager for.

In the terminal continue running:

nano /etc/network/interfaces

And write the following lines:

# The loopback network interface

auto lo

iface lo inet loopback

 

# wlan0 not managed by Network Manager

allow-hotplug wlan0

iface wlan0 inet static

address 172.24.1.1

netmask 255.255.255.0

gateway 172.24.1.0
broadcast 172.24.1.255

Now Network Manager automatically ignore any interfaces specified in file:

/etc/network/interfaces

And stop managing them.

After rebooting, verify that Network Manager is successfully disabled for eth0:

sudo -i

nmcli dev status

 

 

DEVICE TYPE STATE

wlan0 802-11-wireless unmanaged

exit

CONFIGURE HOSTAPD

Next, we need to configure hostapd. Create a new configuration file with sudo nano /etc/hostapd/hostapd.conf with the following contents:

# This is the name of the WiFi interface we configured above

interface=wlan0

# Use the nl80211 driver with the brcmfmac driver

driver=nl80211

# This is the name of the network

ssid=AP-jevoornaam

# Use the 2.4GHz band

hw_mode=g

# Use channel 6

channel=6

# Enable 802.11n

ieee80211n=1

# Enable WMM

wmm_enabled=1

# Enable 40MHz channels with 20ns guard interval

ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

# Accept all MAC addresses

macaddr_acl=0

# Use WPA authentication

auth_algs=1

# Require clients to know the network name

ignore_broadcast_ssid=0

# Use WPA2

wpa=2

# Use a pre-shared key

wpa_key_mgmt=WPA-PSK

# The network passphrase

wpa_passphrase=ubuntu123

# Use AES, instead of TKIP

rsn_pairwise=CCMP

We can check if it's working at this stage by running sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf. If it's all gone well thus far, you should be able to see to the network AP-jevoornaam! If you try connecting to it, you will see some output, but you won't receive and IP address until we set up dnsmasq in the next step. Use Ctrl+C to stop it.

We aren't quite done yet, because we also need to tell hostapd where to look for the config file when it starts up on boot. Open up the default configuration file with sudo nano /etc/default/hostapd and find the line #DAEMON_CONF="" and replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf".

CONFIGURE DNSMASQ

The shipped dnsmasq config file contains a wealth of information on how to use it, but the majority of it is largely redundant for our purposes. I'd advise moving it (rather than deleting it), and creating a new one with

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

sudo nano /etc/dnsmasq.conf

Paste the following into the new file:

interface=wlan0 # Use interface wlan0

listen-address=172.24.1.1 # Explicitly specify the address to listen on

bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere

server=8.8.8.8 # Forward DNS requests to Google DNS

domain-needed # Don't forward short names

bogus-priv # Never forward addresses in the non-routed address spaces.

dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time

SET UP IPV4 FORWARDING

One of the last things that we need to do before we send traffic anywhere is to enable packet forwarding.

To do this, open up the sysctl.conf file with sudo nano /etc/sysctl.conf, and remove the # from the beginning of the line containing net.ipv4.ip_forward=1. This will enable it on the next reboot, but because we are impatient, activate it immediately with : 
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

We also need to share our internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0interface. We can do this using the following commands:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT

sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

However, we need these rules to be applied every time we reboot the LT, so run sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" to save the rules to the file /etc/iptables.ipv4.nat. Now we need to run this after each reboot, so open the rc.local file with sudo nano /etc/rc.local and just above the line exit 0, add the following line:

iptables-restore < /etc/iptables.ipv4.nat

WE'RE ALMOST THERE!

Now we just need to start our services:

sudo service hostapd start

sudo service dnsmasq start

And that's it! You should now be able to connect to the internet through Ubuntu, via the on-board WiFi!

To double check we have got everything configured correctly, reboot with sudo reboot.

 

Create a free web site with Weebly
  • Draadloze Netwerken
  • Linux als AP
    • Raspberry Pi als Wireless Router
    • Raspberry PI 3 als AP
    • Ubuntu als AP
  • Netwerk problemen
  • RF and Antenna Basics
  • Wifi Analyse
  • Draadloze Netwerken
  • Linux als AP
    • Raspberry Pi als Wireless Router
    • Raspberry PI 3 als AP
    • Ubuntu als AP
  • Netwerk problemen
  • RF and Antenna Basics
  • Wifi Analyse