View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Wireless networking

From LQWiki

(Redirected from Wireless)
Jump to: navigation, search

This covers how to get wireless networks to work under Linux, and the various applications that go along with them.

Contents

Start

You should start by means of your distribution - most probably, it works out of the box. Make sure you enabled WLAN on your laptop (there is mostly a button for it). Put it next to your WLAN router. Install your WLAN card as a network card, it will be called eth1,wlan0 or so. Use iwconfig to find out how it is called. You should be able to scan for wireless networks then, e.g. by

$ iwlist wlan0 scanning
wlan0     Scan completed :
          Cell 01 - Address: 00:0F:C9:01:F5:F4
                    ESSID:"foo"
                    Mode:Managed
                    Channel:10
                    Encryption key:off
                    Bit Rates:0 kb/s

$

If you get a Command not found error, install the Wireless tools and try again.
If you do not get a list like the above, see the next section Wireless configuration.
If it works, you can continue with the section Connect to an Accesspoint.

Wireless Configuration

The following provides the general steps required to get wireless networking enabled on your Linux machine.

Find out your wifi card's chipset

In order to get your card working you will have to determine its chipset. There is one, generic, way for PCI and PCMCIA cards, and one for USB cards:

  • The generic way
If this command does not succeed, this can mean that you have an old kernel that does not recognize your card as a WLAN card. In this case, you cannot use it. Anyway, to find out its type use hwinfo --pci or hwinfo --pcmcia.
  • Methods for USB cards
    • Run hwinfo --usb.
This will give you information about the chipset and tell you a Driver activation command (like "modprobe rt73usb").

Hopefully you now have a chipset name but...

Which driver to load and how?

To find out which driver you have to load, use

hwinfo --wlan|grep -i driver

See below for additional relevant information on given chipsets or drivers.

Open Source

Proprietary

Note that building a kernel module requires the kernel sources. Download your driver sources in .tar.gz format and compile from source.

Connect to an Accesspoint

This chapter covers how to connect to an unencrypted or WEP encrypted accesspoint. For WPA encryption, have a look here. The example interface will be called wlan0.

To set up the interface, start by:

 $ ifconfig wlan0 up

If you want, you could scan for an accesspoint first:

 $ iwlist wlan0 scanning

You will then see the available accesspoints, their ESSID's, the frequency, etc. To associate with an accesspoint (for example "test"), run:

 $ iwconfig wlan0 essid test

Most drivers will automatically find the right channel in a minute. You should now be able to see something like this when you run iwconfig:

 $ iwconfig
 lo        no wireless extensions

 wlan0     IEEE 802.11b  ESSID:"test"  
           Mode:Managed  Frequency:2.437 GHz  Access Point: 00:00:00:00:00:00   
           Bit Rate:11 Mb/s   Tx-Power=15 dBm   
           Retry limit:8   RTS thr=1536 B   Fragment thr=1536 B   
           Encryption key: off
           Power Management:off
           Link Quality=0/0  Signal level=0/255  Noise level=0/0
           Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
           Tx excessive retries:0  Invalid misc:0   Missed beacon:0

This means that everything has been installed properly.

Using WEP encryption

If the accesspoint uses WEP, you set the encryption like so:

 $ iwconfig wlan0 key s:"the_ascii_key"

Or you can use a hexadecimal key:

 $ iwconfig wlan0 key 00000000000

The bits of encryption is determined by the key length. Note that this command, along with the key, can be seen in "ps aux".

Getting an IP address

If you have associated properly, you should see the accesspoint's mac address in from iwconfig instead of 00:00:00:00:00:00. If the network you have connected to uses dhcp, it is time to obtain an ip address:

 $ dhclient wlan0

Or:

 $ dhcpcd wlan0

You should see "DHCPOFFER" or similar in a minute if all went well. If it sits there for a while with no DHCPOFFER, then something is wrong. Perhaps the encryption key was incorrect.

However, if you would connect to a AP that doesn't have a dhcp server, you can do the following:

First scan for the AP so you can see the ESSID and the mac address. Do the following

 $ iwconfig wlan0 essid "MyAP" (if that's the ESSID)
 $ iwconfig wlan0 ap 00:40:CA:45:10:9C (if that's the mac)
 $ ifconfig wlan0 192.168.0.20 up
 $ route add -net default gw 192.168.0.1

Provided that the AP has the IP 192.168.0.1.

Create an access point

It is fairly simple to setup an AP in linux. This is how I did.

I purchased a D-Link DWL-G520 pci card. You need a card that supports Master mode. Check this (linux-wless.passys.nl) site for compatibility with Linux, I think ndiswrapper doesn't have support for Master mode, not sure though.

Creating the AP

Then if your interface is ath0:

 $ iwconfig ath0 mode Master
 $ iwconfig ath0 essid "LinuxAP"
 $ ifconfig ath0 192.168.1.1 up

I chose an IP that wasn't in my wired LANs subnet. Now you should be able to see the AP if you scan for APs.

Configure statically your client's card

Then on the client side (if your interface is ath0) you do:

 $ iwconfig ath0 mode Managed
 $ iwconfig essid "LinuxAP"
 $ iwconfig ap 00:11:22:AA:22:11 
 $ ifconfig ath0 192.168.1.10 netmask 255.255.255.0 up 
 $ route add -net default gw 192.168.1.1

It's not always necessary to specify the mac address for the ap, but sometimes it's a good thing. As you can see I chose an ip that was in the same subnet as the ap, it's important.

DHCP server, firewall and stuff

Now, that was the static ip way and you probably want a dhcp-server and some firewall-rules for the ap. Guess what... here they come!

iptables

I have some rules with iptables in a script:

 #!/bin/sh
 IPTABLES='/sbin/iptables'
 EXTIF='eth0'
 INTIF='eth1'
 WLAN='ath0'
 WAN='85.235.31.133'

 /bin/echo 1 > /proc/sys/net/ipv4/ip_forward

 $IPTABLES -F
 $IPTABLES -X

 $IPTABLES -X -t nat
 $IPTABLES -F -t nat

 $IPTABLES -X -t filter
 $IPTABLES -F -t filter

 # enable masquerading to allow LAN internet access
 $IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

 # forward LAN traffic from $INTIF1 to Internet interface $EXTIF
 $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -m state --state NEW,ESTABLISHED -j ACCEPT

 # allow ping
 $IPTABLES -A INPUT -p icmp -i $EXTIF -j ACCEPT

 # Allowing access to the FTP server"
 $IPTABLES -A INPUT -i $EXTIF -p tcp --dport 21 -j ACCEPT

 # Allowing access to the ssh server on port 2200 (I've changed it)
 $IPTABLES -A INPUT -i $EXTIF -p tcp --dport 2200 -j ACCEPT

 # block out all other Internet access on $EXTIF
 $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,INVALID -j DROP
 $IPTABLES -A FORWARD -i $EXTIF -m state --state NEW,INVALID -j DROP

dnsmasq

And my dnsmasq.config looks like this:

 resolv-file=/etc/resolv.conf
 no-poll
 domain-needed
 bogus-priv
 strict-order

 interface=ath0
 dhcp-range=192.168.1.10,192.168.1.50,12h

 interface=eth1
 dhcp-range=192.168.0.10,192.168.0.50,12h

 # alice and bob are declared in /etc/hosts
 dhcp-host=00:0A:E4:52:6B:12,alice
 dhcp-host=00:40:CA:45:10:9C,bob

 dhcp-authoritative

And that's it! Just run the script, start dnsmasq and connect to the ap described in the top of this wiki.

stuff

By the way, if you want to ping some host in the 192.168.0.0 subnet make sure that you don't have another interface that's not alive with an ip in that subnet. So if you have an ordinary wired card eth0 with an ip in the 192.168.0.0 subnet (but no cable in maybe) make sure that you bring that interface down.

 $ ifconfig eth0 down

Now you can ping hosts in that subnet with your wifi card.

External links

Howtos,Guides

Chipset list

Specific cards


Personal tools