Speeding up wireless internet on Crunchbang 11

On a recent new install of Crunchbang 11 I was having major problems connecting to my router with a Ralink RT3370 wireless USB dongle from my main tower. After investigating and playing around, this is my list of changes which got me sorted:

1. AES vs TKIP Encryption:
Connect to the router and change the WPA2 encryption from AES to TKIP. My first suspicon about the lack of connection was the encryption method and maybe the latest RT3370 drivers and wpasupplicant. After changing to TKIP I could connect, allbeit with a slow connection due to packet loss.

2. Move Adapter from USB2 to USB3:
Moved the Dongle from the front USB2 connector to a blue USB3 connector at the back, and I noticed a slight speed increase. After these hardware changes, it was time to go for some terminal-fu and edit a few files to get some extra internet speed.

3. Firstly I edited /etc/nsswitch.conf:
sudo vim /etc/nsswitch.conf
I commented out the original line:
#hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
And changed it to:
hosts: files dns

4. Next I disabled ipV6 in Iceweasel:
In the address bar I typed “about:config” and changed “network.dns.disableIPv6” to “true” with a double-click.

5. Next up was to disable ipV6 system wide:
echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf

6. Adaptor Power Management:
Another thing I had heard is that sometimes powercontrol can interfere with wireless speed as well so I disabled it for the USB dongle:
sudo iwconfig wlan0 power off

7. Swap nm-applet and network-manager for a Manual Static Wireless Connection:
First I disabled nm-applet from autostarting:
sudo mv /etc/xdg/autostart/nm-applet.desktop /etc/xdg/autostart/BKPnm-applet
Then I stopped Network Manager:
sudo /etc/init.d/network-manager stop
And completely Disabled it:
sudo echo "manual" | sudo tee /etc/init/network-manager.override

8. Just needed to add my manual network config:
sudo vim /etc/network/interfaces
Added my wifi info:
auto wlan0
iface wlan0 inet static
address 192.168.1.136
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid ROUTER_ESSID
wpa-psk MYPASSWORD

Then manually added the Google dns addresses:
sudo vim /etc/resolv.conf
And add these:
nameserver 8.8.8.8
nameserver 8.8.4.4

Rebooted into a system with awesome internet cow-power-fu speeds!!

Stop resolv.conf being overwritten by Network Manager

Going Minimal and Manual
This is one of those niggly little problems that happens when people who install full desktop environments face when they go for a bit of fluff reduction and start doing things manually.

Network-Manager and Wicd
I’ve already written about manually setting up a wireless connection, and static wired connections, which will just usually takeover and leave network-manager-gnome or wicd redundant but still showing the applet in your panel.
I completely remove network-manager-gnome anyway, but you may have a reason for keeping it just in case.


Resolvconf
The thing is, you still have the resolvconf package installed which will automatically take over and wipe your manually edited /etc/resolv.conf file, it even tells you what will happen at the top of the file in a commented out warning.

Quick n Easy Method
Just edit and change the write permissions on the resolv.conf file so that resolvconf can’t wipe it.

sudo vim /etc/resolv.conf

Add your nameservers (Iuse Google’s)

nameserver 8.8.8.8
nameserver 8.8.4.4

Then change it to read only (Can be reveresed by changing the + to a – in that command)

sudo chattr +i /etc/resolv.conf

Now reboot, you should have a nice manually configured wireless connection with no DNS issues or resolv.conf overwriting.

Netcat – The Tcp/Udp Rambo Knife

Netcat
The netcat utility is used for practically anything involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, port scan, and is cool with both IPv4 and IPv6 connections.

In this example, open port 6881 using nc command:

nc -l 6881

On a second console or from a second UNIX / Linux machine, connect to the machine and port being listened on:

nc localhost 6881

OR

nc unix.system.ip.here 6881

In this example, send data from one computer to another:

nc -l 6881 > output.txt

Using a second machine, connect to the listening nc process (@ port 6881), feeding it the file which is to be transferred:

nc your.ip.address 6881 < input.txt

You can run netstat command to view open ports:

netstat -a
netstat -nat | grep LISTEN

Sample outputs:

netstat -nat | grep LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:7634 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:17500 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:55788 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:49198 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN

Howto: Wireless Cheat Sheet – Cli Commands

Linux Wireless Help

Here is a list of Cli commands which provide valuable information when trying to configure your wireless connection

sudo iwlist scanning – shows wireless networks that are available in the area with basic encryption information

sudo lshw -C network – Shows Details of Interface card and drivers of each networking device

sudo lspci -nn – Shows PCI vendor and device codes as both numbers and names of hardware connected to the pci bus

lsusb – Shows USB connected hardware

lshw -C usb – Additional info on USB related hardware (good for USB dongles)

route -n – Lists kernel IP routing table — Good for troubleshooting problems with the gateway

sudo route add default gw 192.168.1.1 – Example of how to set the default gateway to 192.168.1.1

sudo route del default gw 192.168.1.1 – Example of how to delete the default gateway setting

sudo modprobe ***** – Loads the kernel module **** . (Example usage – sudo modprobe ndiswrapper, sudo modprobe r818x, sudo modprobe ath_pci)

sudo modprobe -r **** – Unloads the kernel module ****. (Example usage – sudo modprobe -r ath_pci)

sudo ifconfig – lists IP address

sudo ifup/ifdown – Brings up/down the interface and clears the routing table for the specified interface

sudo ifconfig wlan0 up/down – Brings up/down the interface for the specified interface

sudo dhclient – Request IP address from DNS server for specified interface

sudo dhclient -r – Release IP address associated with specified interface

sudo iptables -L – Lists firewall rules

sudo iptables -F – Flush all firewall rules

dmesg | more – Lists boot log — good for troubleshooting problems with modules/drivers not being loaded

uname -r – Displays kernel version

/etc/udev/rules.d/70-persistent-net.rules – File which assigns logical names (eth0, wlan0, etc) to MAC addresses

cat /etc/resolv.conf – Lists DNS servers associated with network connections (Network Manager)

/etc/dhcp3/dhclient.conf – File which sets or modifies dns (domain name servers) settings

How to Automatic Wireless Network Connection At Boot

This howto relies on the fact that your card is recognized and working.
[b]No network auto-connection at boot[/b]
If you configure your network and when you reboot, the operation has to be repeated, it’s because your network configuration data hasn’t been/isn’t being stored.

I have already shown how to configure a network manually via the command line, now you need to know where to store the data so that everything connects automatically at boot.

[b]Nano text editor:[/b]
*note* I use the text editor “Nano” it edits text inside the terminal with no need to open an external GUI application like Gedit, Kate or Mousepad. You can use what you prefer, but I will add the commands for Nano as well.
[b]
/etc/rc.local[/b]
The rc.local file is a script which will run at boot and issue any commands that you add. In this case, we are going to issue the network config commands and connect.
[b]
Howto:[/b]
1. Open your terminal to edit the “rc.local” file.

sudo nano /etc/rc.local

[b]It will be empty apart from a description:[/b]

#!/bin/sh -e<br />#<br /># rc.local<br />#<br /># This script is executed at the end of each multiuser runlevel.<br /># Make sure that the script will "exit 0" on success or any other<br /># value on error.<br />#<br /># In order to enable or disable this script just change the execution<br /># bits.<br />#<br /># By default this script does nothing.<br /><br />exit 0<br /><br />

You need to add your commands between the last [b]#[/b] and the [b]exit 0[/b] code:

I connect through a wireless network, with a 13 digit “ascii” wep key, I need the “s:” before my key to denote ascii. You may only need to type your key if it is a 64/128bit wep key.

[b]Mine looks like this:[/b]

#!/bin/sh -e<br />#<br /># rc.local<br />#<br /># This script is executed at the end of each multiuser runlevel.<br /># Make sure that the script will "exit 0" on success or any other<br /># value on error.<br />#<br /># In order to enable or disable this script just change the execution<br /># bits.<br />#<br /># By default this script does nothing.<br />sudo iwconfig wlan0 essid WLAN_XX<br />sudo iwconfig wlan0 mode managed<br />sudo iwconfig wlan0 key s:xxxxxxxxxxxxx<br />sudo /etc/init.d/networking start<br /><br />exit 0<br />

Now when you reboot, this script will run and connect your network card.