Connect Raspberry Pi to a PC without router or network

If you want to connect a Pi to a computer such as a laptop or a netbook without having to have a network then one method is to connect the laptop to the Pi using an Ethernet cable and then install Remote Desktop (xrdp) onto the Pi. You can also use this method if your Pi is connected into your network of course, but what I wanted was to be able to interact with my Pi even if I had no network. On your laptop you then just run Windows Remote Desktop and connect using the IP address of the Pi in the same way as you would when connecting to any other remote computer.

Install xrdp

On the Pi you first need to install xrdp which is very straight foreword.

#sudo apt-get install xrdp

Once installed go to your laptop and run Remote Desktop, enter the IP address or the server name of the Pi and it should connect.

You may want to modify your Pi so that it has a fixed IP address which you will need if you want to connect to the Pi away from a network.

Normally the Pi will get its IP address dynamically using DCHP.

On our Pi, when logged in, if we do:

#cat /etc/network/interfaces

The line:

iface eth0 inet dhcp

indicates that we are getting our IP address dynamically from the router.

Configuring the Static IP

We have to configure the network settings on the Pi and set up our static IP address. To do this, when we are logged into the Pi:

#sudo nano /etc/dhcpcd.conf

This is to edit the dhcpcd.conf file.

Now, add this code to the end of the /etc/dhcpcd.conf file, and change the IP addresses with your own:

interface eth0
static ip_address=169.254.141.255
static routers=10.0.0.1
static domain_name_servers=192.168.1.254

The above are examples of IP address for my system which will probably be different to yours.

The three IP address are created as follows:

static IP_addresss = This will be the static IP address you use to SSH or remotely connect to your Pi. Take the IP address of your computer’s ethernet adapter, and change the last number to any other number between 0 and 255. To find this out, on your laptop open a command prompt and enter in ipconfig. This will display the IP configuration details for your laptop. Scroll down to see the configuration settings of your Ethernet adapter, which should say something like “Ethernet adapter Ethernet” and give an IP address. On mine it is 169.254.141.78 Change the last number to any other number between 0 and 255, so my static IP address is now 169.254.141.255

static routers = This is the default gateway IP we can find by logging into the Pi and using: #route -ne Under the “Gateway” column, you can see your Default Gateway IP (10.0.0.1 in my case) for each interface (Iface) – ethernet (eth0) and WiFi (wlan0). It is this IP address which is the default gateway IP.

static domain_name_servers = Log in to the command prompt, then enter cat /etc/resolv.conf These are the IP addresses of the domain name servers your Pi uses to find websites on the internet. Separate each IP with a single space.

For example, I found out that the IP address of the ethernet adapter on my laptop is 169.254.141.78. To create the static IP_address for my Pi, I replaced the 78 with 255 to get 169.254.141.255. This is the new static IP address I will use to log in to my Pi via SSH and remote desktop connection.

After you have added the IP addresses, press Ctrl-X and Y to exit and save the /etc/dhcpcd.conf file.

Now you can connect to the Pi from your laptop directly through the wired Ethernet connector away from your network.

Setting the Raspberry Pi 3 into monitor mode

The Raspberry Pi 3 is equipped with an in-built wifi interface which is handy if you want to connect to your local router.

If you want to use your Pi 3 to monitor network data on your local network using applications such as aircrack-ng or Wireshark, the problem is that the in-built wifi adapter is not able to go into monitor mode – or at least I have not been able to make it do that.

Monitor mode is needed if you want to monitor other network data other than the one that you are connected to.

The solution is to get a USB wifi adapter which has a chip set compatible with monitor mode.

The one that I use is an adapter with the RT5370 chipset which works fine.

Assuming that you have the aircrack-ng suite of applications installed on your Pi:

To set to monitor mode first do:

#iwconfig

which will display the list of wireless interfaces.

Then do:

#sudo airmon-ng start wlan1

In my case I want the second interface wlan1 to be in monitor mode, (not the in-built wifi adapter wlan0).

The problem is that this stops communications and my SSH connection hangs, hence I have to exit and log back in again then:

#iwconfig

This should display wlan1mon as the interface in monitor mode – it has created a new version of wlan1 and called it wlan1mon.

To check connections on the interface:

#sudo airodump-ng wlan1mon

Installing Web Server nginx on a Raspberry Pi

nginx is considered to be a better web server for devices with low amount of memory such as the Raspberry Pi. This is because nginx is event driven rather than process driven which is the technique that Apache uses. This can mean that in some situations, nginx can serve more concurrent clients than Apache particularly if there is only one website and it is delivering static HTML pages.

However, I prefer Apache because it is well known, is relatively easy to configure and there are many control panels and configuration tools available for it. For most situations there is very little difference between the performance and if you are setting up a simple web server then Apache may be suitable.

If you wish to install nginx, the following is a description on how to do this and configure it.

We can install nginx web server with PHP5 and MySQL all at the same time using the following command in the terminal:

sudo apt-get install nginx php5-fpm php5-curl php5-gd php5-cli php5-mcrypt php5-mysql php-apc mysql-server

Answer any prompts that are displayed and enter in a root password for the MySQL database when asked.

The default settings for PHP should be fine but we should make a modification to the configuration file so that the FPM module will only listen to nginx:

sudo nano /etc/php5/fpm/pool.d/www.conf

In this config file un-comment the lines listen.owner and listen.group then Ctrl-x and exit the file.

Configure nginx for your web site

We need to make a configuration file from the default config file and then modify it.

So in terminal we need to:

cd /etc/nginx/sites-available

and then make a copy of the default configuration as follows:

sudo cp default mywebsite

To enable the site to nginx we have to create a symbolic link inside /etc/nginx/sites-enabled by doing the following:

sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/mywebsite

Now we can remove the default web site by:

sudo rm /etc/nginx/sites-enabled/default

and reload to make sure the changes are auctioned:

sudo /etc/init.d/nginx reload

We now have to edit the config file to make sure that the settings are what we want:

sudo nano /etc/nginx/sites-available/mywebsite

Within the server block there will be some setting which you should check and modify.

The first modification is to identify the root of your web site. You may want to leave this as it is but in my configuration I am using a flash drive to store the web site on and hence this line becomes:

root /websites/mywebsite/www

Make sure the following are listed:

index index.php index.html index.htm

and make sure the server name is listed:

server_name mywebsite.local mywebsite.com

where mywebsite.local is the name of your local server in my case paulserver.local and mywebsite.com is the url of the web site.

We can now save and exit this file and then reload the nginx using:

sudo /etc/init.d/nginx reload

We can test our configuration by creating a test html file as follows:

sudo nano /websites/mywebsite/www/index.html

Enter some text then save and quit.

If you go to a browser on your computer and then do http://mywebsitelocal you should an html file that you created.

Set up nginx to use PHP

At the moment the webserver will only output html files.

To do this we edit the configuration file by:

sudo nano /etc/nginx/sites-available/mywebsite

Now, as a separate location block inside the server curly bracket block {}, add:

location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;

if (!-f $document_root$fastcgi_script_name) {
return 404;
}

fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

We can now test our configuration by creating a PHP file at the root of our web site. In my example this is:

sudo nano /websites/mywebsite/www/index.php

Add the following code:

<?php phpinfo(); ?>

Save and close the file and visit http://mywebsite.local/index.php in your browse to show that it is working correctly.