pavement

AccessPoint

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(EasyRsa)
m (Reverted edits by DavidYoung (talk) to last revision by 200.38.30.168)
 
(21 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
FreeBSD is very well suited to be used as an access point,because it has out of the box support of the master mode for a variety of cards such as ralink,atheros cards.
+
FreeBSD is very well suited for use as a wifi access point as it has 'master mode' support for a variety of wifi network cards, out of the box.  Some of these include ralink and Atheros cards.
Under GNU/Linux you have to:
+
 
*use a kernel that is not out yet(2.6.26-rc4)
+
There are many difficulties setting up a wireless network access point on linux.  Some of the problems(with non madwifi cards) include:
*patch the kernel with the patch named allow-ap-vlan-modes.patch from http://johannes.sipsolutions.net/patches/kernel/all/LATEST/
+
*You must use a kernel that is yet-to-be released (2.6.26-rc4).
*compile a recent libnl(i used libnl-1.1-r1 in gentoo) against the kernel
+
*You must patch the kernel. [http://johannes.sipsolutions.net/patches/kernel/all/LATEST/006-allow-ap-vlan-modes.patch Download Patch]
*in gentoo you need to copy nl80211.h from your kenrel directory to /usr/include/linux
+
*You must compile a recent libnl(I used libnl-1.1-r1, on Gentoo) against the custom kernel.
*then finally you need to compile a git version of hostapd...
+
*On Gentoo you need to copy nl80211.h from your kenrel directory to /usr/include/linux
you have to do all that only in order to have the wifi card working as access point(otherwise the setup is pretty similar to FreeBSD)
+
*Finally, you need to compile a git version of hostapd...
at the end i got a system that is working with broadcom not ralink ones(made my computer freeze)
+
 
under FreeBSD it's a lot more easy and more stable(we don't use git or patches)
+
All of the above steps must be completed for maximum support of various wireless network cards.  Most other sets are fairly similar to those on FreeBSD.
 +
 
 +
<i>On this Howto we will assume that your modem gives you a dhcp address,see [[AccessPoint using pppoe]] if you need to setup PPPOE</i>
  
 
==The hardware==
 
==The hardware==
i used:
+
For my setup, and the instructions included here, I used:
*2 realtech pci 10/100 cards,in FreeBSD they are recognized as rl0 and rl1(maybe there is the possibility to use interfaces aliasing but as i had 2 cards...)
+
*2 Realtech PCI 10/100 cards, on FreeBSD. These cards are recognized as rl0 and rl1. (Perhaps there is the possibility to use interfaces aliasing, but as i had 2 cards...)
*a ralink rt2500 pci card,in FreeBSD it's recognized as ral0
+
*1 Ralink rt2500 PCI card, on FreeBSD. This card is recognized as ral0.
 +
 
 +
== Installation and Configuration==
 +
* Install FreeBSD as usual.  This example uses FreeBSD 7.0.
 +
* Enable ssh logins during the installation, or add the following line to your /etc/rc.conf:
 +
<pre>sshd_enable="YES"</pre>
 +
* If you have a DHCP-enabled modem, you can add the following to your /etc/rc.conf:
 +
<pre>ifconfig_rl0="DHCP"</pre>
 +
<i>Note, make certain you replace rl0 with your wired network interface name.</i>
  
==The installation and configuration==
 
*install FreeBSD as usual(i used FreeBSD 7.0)
 
*enable ssh logins during the installation or add this in your /etc/rc.conf:
 
sshd_enable="YES"
 
*if you have got a dhcp modem you can use add the following in your /etc/rc.conf(remplacing ral0 by your wired card interface name)
 
ifconfig_rl0="DHCP"
 
otherwise we'll see pppoe later...
 
 
===Wireless===
 
===Wireless===
*then type the following command as root(remplacing ral0 by your wifi card interface name):
+
To configure the wireless card, the following commands need to be executed:
ifconfig ral0 inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4
+
<pre>ifconfig ral0 inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4</pre>
note that in the FreeBSD handbook inet is placed incorrectly,pay also attention to the channel 4...i tried it without it and it didn't work
+
Note that, in the [http://www.freebsd.org/handbook FreeBSD Handbook], inet is placed incorrectly.  Also, make certain to include a channel number. Without it, I was unable to get this working.
then try to associate with a client running an operating system such as *BSD or GNU/Linux and ping it:
+
 
if something goes wrong(ping doesn't work) simply type dmesg and look for message about your wifi card(such as associations messages)
+
Next, try to associate to the new AP from a client. If something goes wrong (i.e. ping doesn't work), look to dmesg for debugging output.  Specifically, look for association messages.
under GNU/Linux type as root(remplacing wlan0 by your wifi card interface name):
+
 
ifconfig wlan0 up
+
 
 +
Finally, if you can see the wireless network, and can ping it, simply add the following to /etc/rc.conf:
 +
<pre>ifconfig_ral0="inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4"</pre>
 +
 
 +
==== Useful Association Commands ====
 +
 
 +
Under GNU/Linux type as root(remplacing wlan0 by your wifi card interface name):
 +
<pre>ifconfig wlan0 up
 
  iwlist wlan0 scan
 
  iwlist wlan0 scan
 
  iwconfig wlan0 essid "freebsdap"
 
  iwconfig wlan0 essid "freebsdap"
 
  ifconfig wlan0 192.168.1.100 netmask 255.255.255.0
 
  ifconfig wlan0 192.168.1.100 netmask 255.255.255.0
  ping 192.168.1.1
+
  ping 192.168.1.1</pre>
under FreeBSD type as root(remplacing ral0 by your wifi card interface name):
+
Under FreeBSD type as root(remplacing ral0 by your wifi card interface name):
ifconfig ral0 up
+
<pre>ifconfig ral0 up
 
  ifconfig ral0 list scan
 
  ifconfig ral0 list scan
 
  ifconfig ral0 inet 192.168.1.100 netmask 255.255.255.0 ssid freebsdap
 
  ifconfig ral0 inet 192.168.1.100 netmask 255.255.255.0 ssid freebsdap
  ping 192.168.1.1
+
  ping 192.168.1.1</pre>
then if you can see the wireless and can ping it simply add the following to /etc/rc.conf:
+
 
ifconfig_ral0="inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4"
+
===DNS and DHCP===
===dns and dhcp===
+
Once the wireless AP is working, we can install DNS and DHCP servers. For simplicity, we will use dnsmasq.  As root, execute the following command:
your wireless is now working...so we can install a dns and dhcp server...
+
<pre>cd /usr/ports/dns/dnsmasq && make config && make install</pre>
for simplicity we will use dnsmasq
+
 
type the following as root:
+
On the configuration menu, deselect the followingn options:
cd /usr/ports/dns/dnsmasq
+
* ipv6
make config
+
* dbus
then unselect ipv6 unless you need it
+
 
and unselect dbus because we won't use it
+
Once installed, we need to configure dnsmasq:
then type the following as root:
+
 
make
+
Edit /usr/local/etc/dnsmasq.conf with your favorite editor and add the following:
make install
+
<pre># filter what we send upstream
then we will need to configure dnsmasq:
+
domain-needed
edit /usr/local/etc/dnsmasq.conf with your favorite editor and add the following:
+
bogus-priv
# filter what we send upstream
+
filterwin2k
domain-needed
+
localise-queries
bogus-priv
+
filterwin2k
+
localise-queries
+
 
   
 
   
# allow /etc/hosts and dhcp lookups via *.lan
+
# allow /etc/hosts and dhcp lookups via *.lan
local=/lan/
+
local=/lan/
domain=workgroup
+
domain=workgroup
expand-hosts
+
expand-hosts
#resolv-file=/tmp/resolv.conf.auto
+
#resolv-file=/tmp/resolv.conf.auto
 
   
 
   
dhcp-authoritative
+
dhcp-authoritative
#dhcp-leasefile=/tmp/dhcp.leases
+
#dhcp-leasefile=/tmp/dhcp.leases
 
   
 
   
# use /etc/ethers for static hosts; same format as --dhcp-host
+
# use /etc/ethers for static hosts; same format as --dhcp-host
# <hwaddr> <ipaddr>
+
# <hwaddr> <ipaddr>
read-ethers
+
read-ethers
 
   
 
   
# other useful options:
+
# other useful options:
# default route(s):
+
# default route(s):
dhcp-option=3,192.168.1.1
+
dhcp-option=3,192.168.1.1
#    dns server(s):
+
#    dns server(s):
dhcp-option=6,192.168.1.1
+
dhcp-option=6,192.168.1.1
  
dhcp-range=192.168.1.100,192.168.1.255,255.255.255.0,12h
+
dhcp-range=192.168.1.100,192.168.1.255,255.255.255.0,12h</pre>
the file don't need to be explained but read-ethers...
+
read ethers permit you to assign static ip to certain mac address
+
so edit /etc/ethers with entries like this:
+
00:14:85:11:EF:02 192.168.1.106
+
and in order to give a dns name to this entry edit /etc/hosts and add an entry like this:
+
192.168.1.106 Ralink
+
  
then in order to start your dnsmasq server at boot you need to add the following to /etc/rc.conf:
+
The option, read-ethers, permits you to assign statics IPs to certain MAC addresses.  Edit /etc/ethers with entries as follows:
dnsmasq_enable="YES"
+
<pre>00:14:85:11:EF:02 192.168.1.106</pre>
  
you can now test the wifi connection with any graphical tool(like NetworkManager in GNU/linux or even test it with a windows computer)
+
In order to give a DNS name to this entry, edit /etc/hosts and add an entry like this:
you can even try to ping a website...but you will only get his ip and no response...that's because we didn't set up the NAT yet...
+
<pre>192.168.1.106 Ralink</pre>
 +
 
 +
To start your dnsmasq server at boot, add the following to /etc/rc.conf:
 +
<pre>dnsmasq_enable="YES"</pre>
 +
 
 +
You can now test the wifi connection with any graphical tool (like NetworkManager in GNU/linux or even test it with a windows computer) you can even try to ping a website... but you will only get his ip and no response...that's because we didn't set up the NAT yet...
  
 
==Nat and firewall==
 
==Nat and firewall==
Line 161: Line 167:
  
 
====OpenVpn configuration====
 
====OpenVpn configuration====
We will first install all in test-mode that is to say not runnning at the boot,not running as daemon etc...
+
We will first install all in test-mode that is to say not runnning ... \n
we will run theses commands:
+
ifconfig tap0 destroy
+
ifconfig bridge0 destroy
+
ifconfig tun0 destroy
+
ifconfig bridge0 create
+
ifconfig tap0 create
+
#remplace ral0 by your card interface name
+
ifconfig bridge0 addm ral0 addm tap0 up
+
ifconfig br0 192.168.1.1
+
then here's my server configuration for openvpn:
+
ca /usr/local/etc/openvpn/keys/ca.crt
+
cert /usr/local/etc/openvpn/keys/server.crt
+
key /usr/local/etc/openvpn/keys/server.key
+
dh /usr/local/etc/openvpn/keys/dh1024.pem
+
dev tap
+
# replace 10.0.0.1 with the VPN IP
+
server-bridge 10.0.0.1 255.255.255.0 10.0.0.2 10.0.0.250
+
keepalive 10 120
+
client-to-client
+
verb 3
+
duplicate-cn
+
and here's my client configuration(ubuntu GNU/Linux):
+
remote 192.168.1.1
+
client
+
dev tap
+
nobind
+
tls-client
+
ca /home/ubu/ca.crt
+
cert /home/ubu/ubu.crt
+
key /home/ubu/ubu.key
+
pull
+
verb 4
+
remote-cert-tls server
+
#auth-user-pass
+
in order to make it work do this on the server:
+
/usr/loca/sbin/openvpn server.conf
+
ifconfig tap0 10.0.0.1
+
on the client:
+
openvpn client.conf
+
route del default
+
route add default gw 10.0.0.1 tap0
+
+
if you put wireshark on the client's wireless interface you'll see only udp packet from and to the openvpn port...so it works...
+
 
+
[[Category:FreeBSD for Servers]]
+

Latest revision as of 16:30, 25 August 2012

Contents

[edit] Introduction

FreeBSD is very well suited for use as a wifi access point as it has 'master mode' support for a variety of wifi network cards, out of the box. Some of these include ralink and Atheros cards.

There are many difficulties setting up a wireless network access point on linux. Some of the problems(with non madwifi cards) include:

  • You must use a kernel that is yet-to-be released (2.6.26-rc4).
  • You must patch the kernel. Download Patch
  • You must compile a recent libnl(I used libnl-1.1-r1, on Gentoo) against the custom kernel.
  • On Gentoo you need to copy nl80211.h from your kenrel directory to /usr/include/linux
  • Finally, you need to compile a git version of hostapd...

All of the above steps must be completed for maximum support of various wireless network cards. Most other sets are fairly similar to those on FreeBSD.

On this Howto we will assume that your modem gives you a dhcp address,see AccessPoint using pppoe if you need to setup PPPOE

[edit] The hardware

For my setup, and the instructions included here, I used:

  • 2 Realtech PCI 10/100 cards, on FreeBSD. These cards are recognized as rl0 and rl1. (Perhaps there is the possibility to use interfaces aliasing, but as i had 2 cards...)
  • 1 Ralink rt2500 PCI card, on FreeBSD. This card is recognized as ral0.

[edit] Installation and Configuration

  • Install FreeBSD as usual. This example uses FreeBSD 7.0.
  • Enable ssh logins during the installation, or add the following line to your /etc/rc.conf:
sshd_enable="YES"
  • If you have a DHCP-enabled modem, you can add the following to your /etc/rc.conf:
ifconfig_rl0="DHCP"

Note, make certain you replace rl0 with your wired network interface name.

[edit] Wireless

To configure the wireless card, the following commands need to be executed:

ifconfig ral0 inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4

Note that, in the FreeBSD Handbook, inet is placed incorrectly. Also, make certain to include a channel number. Without it, I was unable to get this working.

Next, try to associate to the new AP from a client. If something goes wrong (i.e. ping doesn't work), look to dmesg for debugging output. Specifically, look for association messages.


Finally, if you can see the wireless network, and can ping it, simply add the following to /etc/rc.conf:

ifconfig_ral0="inet 192.168.1.1 netmask 255.255.255.0 ssid freebsdap mediaopt hostap channel 4"

[edit] Useful Association Commands

Under GNU/Linux type as root(remplacing wlan0 by your wifi card interface name):

ifconfig wlan0 up
 iwlist wlan0 scan
 iwconfig wlan0 essid "freebsdap"
 ifconfig wlan0 192.168.1.100 netmask 255.255.255.0
 ping 192.168.1.1

Under FreeBSD type as root(remplacing ral0 by your wifi card interface name):

ifconfig ral0 up
 ifconfig ral0 list scan
 ifconfig ral0 inet 192.168.1.100 netmask 255.255.255.0 ssid freebsdap
 ping 192.168.1.1

[edit] DNS and DHCP

Once the wireless AP is working, we can install DNS and DHCP servers. For simplicity, we will use dnsmasq. As root, execute the following command:

cd /usr/ports/dns/dnsmasq && make config && make install

On the configuration menu, deselect the followingn options:

  • ipv6
  • dbus

Once installed, we need to configure dnsmasq:

Edit /usr/local/etc/dnsmasq.conf with your favorite editor and add the following:

# filter what we send upstream
domain-needed
bogus-priv
filterwin2k
localise-queries
 
# allow /etc/hosts and dhcp lookups via *.lan
local=/lan/
domain=workgroup
expand-hosts
#resolv-file=/tmp/resolv.conf.auto
 
dhcp-authoritative
#dhcp-leasefile=/tmp/dhcp.leases
 
# use /etc/ethers for static hosts; same format as --dhcp-host
# <hwaddr> <ipaddr>
read-ethers
 
# other useful options:
# default route(s):
dhcp-option=3,192.168.1.1
#    dns server(s):
dhcp-option=6,192.168.1.1

dhcp-range=192.168.1.100,192.168.1.255,255.255.255.0,12h

The option, read-ethers, permits you to assign statics IPs to certain MAC addresses. Edit /etc/ethers with entries as follows:

00:14:85:11:EF:02 192.168.1.106

In order to give a DNS name to this entry, edit /etc/hosts and add an entry like this:

192.168.1.106 Ralink

To start your dnsmasq server at boot, add the following to /etc/rc.conf:

dnsmasq_enable="YES"

You can now test the wifi connection with any graphical tool (like NetworkManager in GNU/linux or even test it with a windows computer) you can even try to ping a website... but you will only get his ip and no response...that's because we didn't set up the NAT yet...

[edit] Nat and firewall

in order to set the nat we will add this to /etc/rc.conf:(remplacing ral0 by your wired card(that is connected to the internet) interface name)::

gateway_enable="YES"
firewall_enable="YES"
firewall_type="OPEN"
natd_enable="YES"
natd_interface="rl0"
natd_flags=""

if you wish to redirect ports add this to natd_flags="" in /etc/rc.conf:

-redirect_port tcp 192.168.0.6:80 80

now normally the access point should work...

[edit] OpenVPN

[edit] Introduction

now that we have wireless we could choose between theses choices:

  • having a full open wireless(not great for security)
  • having a wpa wireless(not compatible with all drivers,devices doesn't always work),no guests...
  • having an open wireless while encrypting the data sent to to wireless access point...yes that is possible...with the help of openvpn

i chose the third possibility.

[edit] installation

here the commands to run in order to install openvpn:

cd /usr/ports/security/openvpn
make
make install

[edit] configuration

[edit] EasyRsa

install bash:

cd /usr/ports/shells/bash
make
make install
ln -s /usr/local/bin/bash /bin/bash 

run theses commands:

cp -r /usr/local/share/doc/openvpn/easy-rsa/2.0/ /root/easy-rsa-2.0

here we will copy it in order not to have our keys erased by an update... then we will need bash run:

/bin/bash
cd /root/easy-rsa-2.0

then we will make the certificates: modify the vars script in order to suit your needs,then run:

source ./vars
./clean all
./build-ca ca

then we will build the server key:

./build-key-server server

then we will build the clients key:

./build-key client1
./build-key client2

then we genreate diffie helman parameters:

./build-dh

in order to build a new client just do:

source ./vars
./build-key client2

then copy the keys at the keys location:

cp -r keys /usr/local/etc/openvpn/keys

alternatively you can do the following:

mkdir /usr/local/etc/openvpn/keys/
cd /root/easy-rsa-2.0/keys
cp ca.crt /usr/local/etc/openvpn/keys/ca.crt
cp server.crt /usr/local/etc/openvpn/keys/server.crt
cp server.key /usr/local/etc/openvpn/keys/server.key
cp dh1024.pem /usr/local/etc/openvpn/keys/dh1024.pem

[edit] OpenVpn configuration

We will first install all in test-mode that is to say not runnning ... \n

Personal tools