Turn Your Raspberry Pi into a TFTP Server
Raspberry Pi is a tiny and affordable computer consisting of a single, credit card-sized circuit board. You can use it to do almost anything that is doable with a regular desktop computer, such as running desktop applications and playing music files. Raspberry Pi also has great potential for developing automation systems using sensors, relays, lights, and motors due to its small size, low power requirements, and small price tag. Raspberry Pi was conceived and developed by the Raspberry Pi Foundation with the goal to promote teaching of basic computer science in schools. But today it has probably become more popular with enthusiasts. Since the initial launch of Raspberry Pi in February 2012, more than one million units have been sold.
This article will briefly walk you through the process of setting up your Raspberry Pi for the first time. It then presents an interesting application, using the Pi as TFTP server for downloading Cisco IOS software images to routers. This is just one of the many wonderful things that can be done with this miniature computer.
How to Get Your Pi
The Raspberry Pi comes in two models: the lower-priced model A and the higher-cost model B. We used the Raspberry Pi Model B Revision 2.0 with 512 MB memory to create the examples in this article. This model is available at Amazon.com for around $40. That amount gets you the board alone and does not include am SD card, power adapter, cables, or case. A better option is to purchase a starter kit that comes complete with case, power supply, HDMI cable, and a preloaded SD card. The kit would include everything other than the display, keyboard, and mouse you would need to have a working Raspberry Pi system. Such a kit is manufactured by CanaKit and is available at Amazon.com for around $70 at the time of this writing.
Raspberry Pi Hardware
Raspberry Pi is a computer and, just like every other computer, it has a processor at its heart—a Broadcom BCM2835 system-on-chip (SoC) multimedia processor in this case. The multiprocessor has the majority of system components built into it, including the central and graphics processing units, along with the audio and communications hardware. There is also a 512 MB memory chip at the center of the Raspberry Pi (Model B Revision 2.0) board.
The BCM2835 processor uses an instruction set architecture (ISA) known as ARM. The ARM architecture, though not common in the desktop computer world, is ideally suited for low-power applications. The smartphone you are carrying in your pocket right now quite likely has an ARM-based processor. The BCM2835 processor enables Raspberry Pi to operate on just the power supplied by an onboard micro-USB port and survive without any heat sinks on the device.
The Raspberry Pi is a bare-bones computer that comes without any peripherals. You need to connect a display, keyboard, and mouse before you can do anything useful. The Pi has an HDMI port that you can use to connect to an existing computer monitor with an HDMI port. Even if your monitor only has a DVI port, you can purchase an HDMI-to-DVI cable to connect it to the Pi. You also need to connect a keyboard and optionally a mouse for input devices.
The Raspberry Pi doesn’t have a traditional hard drive like PCs have. It uses a secure digital (SD) memory card to store the entire operating system as well as other software and data. SD cards with the operating system preloaded are available for use with the Pi. You can also install an operating system yourself onto a blank SD card and use it with your Pi.
The Raspberry Pi is powered by a micro-USB connecter that is the same one found on most smartphones. The Pi requires up to 700 mA in order to operate. You must make sure that the charger you are using can supply that much juice or it may cause problems in the operation of Pi. There is no power button on the device, so it will fire up the instant power is connected.
Raspbian Operating System
Linux is an open-source operating system that consists of a kernel at its heart. As a matter of fact, the kernel is Linux but it is often bundled with a collection of different open source software to form different flavors of Linux, known as distributions. Linux is traditionally a command-line interface (CLI) based operating system, though all modern Linux distributions now come with a desktop environment as well.
Debian is one of the numerous Linux distributions and a great choice for Raspberry Pi due to its lightweight nature. The Raspberry Pi runs on Raspbian, which is a modified form of Debian optimized for Raspberry Pi hardware. Raspbian does not include all the software found on desktop versions of Debian. That’s a choice made to keep the image size to the minimum. However, additional software can be easily installed using the advanced packaging tool (APT) that is part of the distribution.
The Debian build for Raspberry Pi includes a desktop environment known as the Lightweight X11 Desktop Environment (LXDE). LXDE uses the X Window System, also known as X11, to offer a familiar point-and-click graphical user interface (GUI) similar to Windows and OS X. The GUI may not load by default in your Raspberry Pi distribution. You may need to log in and then enter startx to leave the text-based console behind and load the GUI.
The configuration examples that follow were developed using the topology shown in Figure 1. It enables our Raspberry Pi system to access the Internet through the gateway as well as offer Cisco IOS images to the router over LAN.
Figure 1. Network Diagram
You can fire up the Raspberry Pi by simply connecting the micro-USB connector. The Pi takes less than a minute to boot, during which the usual Linux boot messages scroll across the screen. You are then presented with the login prompt:
Debian GNU/Linux 7.0 raspberrypi tty1 raspberrypi login:
You can enter pi as login and raspberry as password to get into the system.
pi@raspberrypi ~ $
If you are familiar with the Linux command-line interface (CLI), you can do a lot of things right from the CLI, which, in fact, can be quite powerful for the experienced. But, let’s face the fact that most of us live in a world dominated by Windows and we are not comfortable with the Linux CLI. However, Raspbian comes with a GUI environment just like most other modern Linux distributions. You can launch the GUI environment simply by entering startx at the CLI.
pi@raspberrypi ~ $startx
This starts the GUI system of Linux and presents you with a desktop environment as shown in Figure 2. You can see shortcuts to a few applications right on the desktop including, the Midori Web browser and the LXTerminal terminal application.
Figure 2. Raspbian Desktop
You may recall that we logged in as pi. In order to perform IP configuration, you need to switch to the root user by using the su root command. By default, the root password is not set so you can just hit enter when prompted for root password. You will then be able to configure a root password of your choice.
pi@raspberrypi ~ $su root Password: root@raspberrypi:/home/pi#
The Pi can automatically receive its IP configuration through the dynamic host configuration protocol (DHCP) when connected to a LAN. You can also configure the IP address and other related details manually. We will resort to the manual configuration option.
The list of network interfaces is stored with other useful information in a file called interfaces, located in the folder /etc/network. This file can be edited only by the root user because removing a network interface from this file will cause it to stop working. That is also one of the reasons we switched to the root user using su root command. You have to first launch a terminal application, such as LXTerminal, which is available right on the desktop of user pi. You can then edit this file using a text editor like nano. Open the file for editing using the following command:
You need to edit the line that starts with iface eth0 inet. Just delete dhcp at the end of this line and replace it with static. Then press Enter to go to a new line, and fill in the remaining details in the following format with a tab at the start of each line:
address 192.168.1.2 netmask 255.255.255.0 gateway 192.168.1.1
Figure 3 The nano editor
When you’re done editing, press Ctrl+O to save the changes and then press Ctrl+X to exit nano and return to the terminal. You need to shutdown the Ethernet interface and bring it up again in order to bring the IP configuration into effect.
root@raspberrypi:/home/pi#ifdown eth0 root@raspberrypi:/home/pi#ifup eth0
The IP configuration done so far isn’t enough to get your Pi connected to the outside world. You must tell the Pi which DNS servers to use. The list of DNS servers, known as nameservers in the Linux world, is kept in the file /etc/resolv.conf. We will use nano again and edit that file to configure a couple of nameserver entries like this:
nameserver 18.104.22.168 nameserver 22.214.171.124
The IP addresses 126.96.36.199 and 188.8.131.52 correspond to two DNS servers Google is offering for public use. You should be able to ping the gateway as well as any host on the Internet at this point.
root@raspberrypi:/home/pi# ping -c 4 192.168.1.1 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. 64 bytes from 192.168.1.1: icmp_req=1 ttl=128 time=0.934 ms 64 bytes from 192.168.1.1: icmp_req=2 ttl=128 time=0.816 ms 64 bytes from 192.168.1.1: icmp_req=3 ttl=128 time=0.856 ms 64 bytes from 192.168.1.1: icmp_req=4 ttl=128 time=0.779 ms --- 192.168.1.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 0.779/0.846/0.934/0.061 ms
Our IP configuration is complete at this point and we can now turn our attention to TFTP. There are multiple TFTP client and server implementations for Debian. We choose to use the package known as atftpd, which is an advanced TFTP server implementing all options specified in various TFTP RFCs. The first step is to install the package, as it does not come bundled with the default Raspberry Pi distribution. Your Raspberry Pi has to be connected to the Internet before you can download packages. Use the command apt-get install aftpd to download and install the aftpd package using the advanced package tool (APT):
root@raspberrypi:/home/pi# apt-get install atftpd Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: rlinetd Recommended packages: inet-superserver The following NEW packages will be installed: atftpd rlinetd 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 166 kB of archives. After this operation, 473 kB of additional disk space will be used. Do you want to continue [Y/n]? Y Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main atftpd armhf 0.7.dfsg-11 [63.3 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main rlinetd armhf 0.8.2-2 [102 kB] Fetched 166 kB in 6s (26.1 kB/s) Preconfiguring packages ... Selecting previously unselected package atftpd. (Reading database ... 59229 files and directories currently installed.) Unpacking atftpd (from .../atftpd_0.7.dfsg-11_armhf.deb) ... Selecting previously unselected package rlinetd. Unpacking rlinetd (from .../rlinetd_0.8.2-2_armhf.deb) ... Processing triggers for man-db ... Setting up atftpd (0.7.dfsg-11) ... *** WARNING: ucf was run from a maintainer script that uses debconf, but the script did not pass --debconf-ok to ucf. The maintainer script should be fixed to not stop debconf before calling ucf, and pass it this parameter. For now, ucf will revert to using old-style, non-debconf prompting. Ugh! Please inform the package maintainer about this problem. Creating config file /etc/rlinetd.d/tftp_udp with new version rlinetd: no process found Setting up rlinetd (0.8.2-2) ... [ ok ] Starting internet superserver: rlinetd. root@raspberrypi:/home/pi#
You may have noticed from the above output that the atftpd package depends on the rlinetd package, also known as the Internet superserver. The latter also gets installed automatically.
The TFTP server uses /srv/tftp as its home directory by default. You need to put your IOS image files in this directory before your TFTP server is able to serve them to a router. You may use the Midori Web browser to download images from the Internet or company Intranet depending on your situation.
Let’s go to our router now and perform basic IP configuration first. The interface FastEthernet0/0 of the router is assigned the IP address 192.168.1.3 and subnet mask 255.255.255.0.
Router>enable Router#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router(config)#interface FastEthernet0/0 Router(config-if)#ip address 192.168.1.3 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#end Router#
You can use the copy tftp flash command to download an IOS image stored on the SD card of your Raspberry Pi.
Router#copy tftp flash Address or name of remote host ? 192.168.1.2 Source filename ? c1841-adventerprisek9-mz.124-6.t7 Destination filename [c1841-adventerprisek9-mz.124-6.t7]? Accessing tftp://192.168.1.2/c1841-adventerprisek9-mz.124-6.t7... Loading c1841-adventerprisek9-mz.124-6.t7 from 192.168.1.2 (via FastEthernet0/0): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! [OK - 25577616 bytes] 25577616 bytes copied in 98.200 secs (260465 bytes/sec) Router#
The low cost Raspberry Pi system can thus be turned into an inexpensive repository of Cisco IOS image files for personal or commercial use.
Latest posts by Muhammad Furqan (see all)
- GNS3 Labs for CCNA: Basic NAT (Network Address Translation) - May 27, 2014
- GNS3 Labs for CCNA: Advanced Access Control Lists - May 9, 2014
- GNS3 Labs for CCNA: Basic Access Control Lists - April 25, 2014