Fix My Pi

Tools-128Tutorials are awesome, but what do you do when it stops working, or you tried a little experiment and now something that once worked is broken? Here are a few troubleshooting tips related to my projects, grouped by functionality.

 

Is It Reachable on your Network?

If you have a monitor connected to your Pi, it will display on the screen the IP address(es) it is using once it finishes booting. If it doesn’t have an IP address for the LAN its connected to, and your network connection is good (green light on the network switch), check your DHCP server (did you run out of available addresses?). Double check the /etc/network/interfaces file to make sure the eth0 interface is setup properly. For DHCP you should see a line with

iface eth0 inet dhcp

I you are setting it for a static IP address, it should look something like this:

iface eth0 inet static

address 192.168.1.200

netmask 255.255.255.0

gateway 192.168.1.1

Your exact configuration will be different, but the point is that you have the static option, and address, netmask and gateway values.

Apache

You should be able to access the apache web server using the IP address of the Pi in your web browser. If you cannot reach the web page:

  • Make sure apache is running with the command sudo service apache2 status.
  • If it’s not running, try restarting the service with sudo service apache2 restart.
  • If a restart fails to load apache, you may need to edit the configuration, which is found at /etc/apache2/apache2.conf.
    • Most of the time you should not have to mess with this unless you want to run on a non-standard port number (other than 80), or you need to alter other behavior.
    • Also, make sure you have your content in the /var/www/ directory.

Wi-Fi Drivers for Access Point

My projects have used the Edimax EB7811Un USB adapter that has support for WPS, WPA2, 802.11b/g/n varieties, and works at up to 150Mbps. This means it can be a Wi-Fi Client, but also a Wi-Fi Access Point as well with some tweaking.

In the access point how-to, we walk through the installation of hostapd; an application whose intent is to enable using a Wi-Fi adapter in an access point configuration just like a Wi-Fi router. There are explicit instructions for downloading the correct driver (a binary file) and a few steps to follow to ensure that the driver is used in the hostapd configuration, as well as being enabled at boot time. Here are the steps you can take to see if hostapd is still set up properly.

If you are unable to see the SSID or connect with the passphrase you are using run:

cat /etc/hostapd/hostapd.conf – check the ssid and wpa_passphrase values

Also,

cat /etc/default/hostapd – make sure the DAEMON_CONF=”/etc/hostapd/hostapd.conf” line is not commented out (and that it exists).

Make sure that the hostapd service is set to start at boot time –

sudo update-rc.d hostapd enable

If you are not connecting at a very fast speed.

cat /etc/hostapd/hostapd.conf – check that you have hw_mode=g, wmm_enabled=1, ieee80211n=1, and that the values for the “ht_capab=” option are something your clients support (a long list of options are in the How-To)
You can also check the channel you are on. If you have a lot of neighbors, you might have to move your channel to a different number.

There is a debugging mode for hostapd –

sudo hostapd -dd /etc/hostapd/hostapd.conf

This command starts the hostapd app and shows output at the console for you to watch. There is a lot of stuff thrown at you but you should be able to glean whether a client is able to connect or not. Ctrl-C stops the app from running in debug mode, and may also stop it altogether, so you will have to restart it in “background mode” to start it again –

sudo hostapd -B /etc/hostapd/hostapd.conf

DHCP Server

You will not be given an IP address by the Pi if this service is not running or mis-configured, even if the Wi-Fi connection is established at the RF level (ssid and passphrase are good and you connect). Check the following:

  • Make sure the DHCP service is running – sudo service isc-dhcp-server status. If not, you can start it manually with sudo service isc-dhcp-server start
  • Make sure it is setup to start at boot time – sudo update-rc.d isc-dhcp-server enable
  • If the service is running and you still cannot get an IP address, make sure that the wlan0 interface is specified in the /etc/isc-dhcp-server file – INTERFACES=”wlan0″.
  • If you are serving more interfaces, make sure they are defined inside the double-quotes. – INTERFACES=”wlan0 eth0″
  • Make sure the /etc/dhcp/dhcpd.conf file has the subnet and options for that subnet configured properly

If all else fails, you can re-install the isc-dhcp-server – sudo apt-get install isc-dhcp-server – see the How-To and retrace the steps there.

TFTP Server

While I had not spoken about a TFTP server in a tutorial, I use one to support testing the provisioning of cable modems, and loading Cisco IOS images on switches and routers. When you run the installation, it will run the scripts to establish it as a service at boot time. The /etc/default/tftpd-hpa file is installed with the following configuration:

# /etc/default/tftpd-hpa

TFTP_USERNAME=”tftp”
TFTP_DIRECTORY=”/srv/tftp”
TFTP_ADDRESS=”0.0.0.0:69″
TFTP_OPTIONS=”–secure”

The Raspberry Pi O/S does not support IPv6, so you have to explicitly add the option \”–ipv4\”to the TFTP_OPTIONS as shown below:

# /etc/default/tftpd-hpa

TFTP_USERNAME=”tftp”
TFTP_DIRECTORY=”/srv/tftp”
TFTP_ADDRESS=”0.0.0.0:69″
TFTP_OPTIONS=”–secure –ipv4

Then restart the service – sudo service tftpd-hpa restart

Be sure to put the files you want available into the /srv/tftp/ folder.

NAT

This is a complex topic, however our use of the iptables commands are extremely simple. They are just enough to enable NAT translation on the eth0 (Ethernet) port, and provide for basic security of the Wi-Fi clients serviced by the Pi. It only allows traffic from connections that originate from the Wi-Fi client subnet (wlan0 network).

The most common problem is that the NAT rules do not survive a reboot. If this is the case, you must re-enter the NAT commands. Then to make sure they are active upon a reboot, run –

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

… then edit the /etc/network/interfaces file to add this command to retrieve your NAT config and start it at boot time:

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

Well, I will put more here later as time permits, or as I have problems that need solving!

Cheers!