For some reason, the configuration of static IP addresses in /etc/network/interfaces in the manner I've been using since Redhat 4.0 back in the mid to late 90s no longer works on the recent Raspbian Jessie images for the Raspberry Pi.
I've not researched why, I think its related to the GUI tools. I only use the cmd line and never even boot a GUI on so have come to the conclusion life is too short. So its time to learn something new again, but once you know where it is configured it isn't too difficult.
The configuration is now performed in the file /etc/dhcpcd.conf with the follow entries being added:-
interface eth0
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=208.67.222.222 208.67.220.220
Obviously you need to change the details above to reflect your particular network.
The DNS servers listed are for the OpenDNS servers
Its as easy as Pi, just I quiet liked my old Pi.
0x25.eu
A random collection of thoughts, ramblings and how-to's.
Wednesday 3 February 2016
Monday 11 January 2016
Perl - CPAN shell
Brief guide to setting up CPAN shell to easily install Perl modules.
sudo perl -MCPAN -e shell
If this fails with error message "Can't locate local/lib.pm in @INC" or make not found, either way you may need to install supporting tools. In a debian world this is as easy as:-
Once in the Perl CPAN shell its a good idea to update the shell:-
sudo perl -MCPAN -e shell
install CPAN
reload cpan
Finally to install a module such as Net::Telnet simply:-
sudo perl -MCPAN -e shell
install Net::Telnet
Thats all for now.
Wednesday 6 January 2016
HW - Emergency Null Modem Cable.
At some point in time, many IT engineers from numerous backgrounds have at some time or other had an emergency requirement for a Null Modem Cable. I was in one such situation recently and had to cobble together one quick to get a box back up and running.
With just a pocket (pen) knife and a couple of Cisco DB9-8p8c (or RJ45 if you prefer) I was able to cobble one together. I needed DB9 at both ends so chopped of the RJ45 connectors.
The pins we are interested in (viewed from the transparent RJ45 ends) are :-
3 - TXD (red)
5 - RXD (green)
6 - GRND (yellow)
The first thing I noticed after doing a quick search to confirm interesting pins, is that the colours people report don't always agree. My advise would be to work from the pin number and confirm the colours.
Once identified it is simply a case of stripping the insulation on the required pins back, (red, green and yellow) to reveal the copper beneath, they could be twisted together again in the right order to make a Null Modem Cable with DB9 on both ends.
So I twisted the two yellow cables together to connect the ground, then the red and green cables were crossed and twisted together, Finally a paper clip was used to try and provide some strain relief to the cables.
In an ideal world, solder and insulation is highly recommended, but as a quick get out of jail card it worked fine.
The finished article, if you call it finished.
With just a pocket (pen) knife and a couple of Cisco DB9-8p8c (or RJ45 if you prefer) I was able to cobble one together. I needed DB9 at both ends so chopped of the RJ45 connectors.
The pins we are interested in (viewed from the transparent RJ45 ends) are :-
3 - TXD (red)
5 - RXD (green)
6 - GRND (yellow)
The first thing I noticed after doing a quick search to confirm interesting pins, is that the colours people report don't always agree. My advise would be to work from the pin number and confirm the colours.
Once identified it is simply a case of stripping the insulation on the required pins back, (red, green and yellow) to reveal the copper beneath, they could be twisted together again in the right order to make a Null Modem Cable with DB9 on both ends.
So I twisted the two yellow cables together to connect the ground, then the red and green cables were crossed and twisted together, Finally a paper clip was used to try and provide some strain relief to the cables.
In an ideal world, solder and insulation is highly recommended, but as a quick get out of jail card it worked fine.
The finished article, if you call it finished.
Monday 4 January 2016
Linux - Debian Media Content Server
I've decided to combine a number of server functions I currently have onto a single Debian box for ease of sharing media etc. Having now got to the point where I have a spare HP Microserver N40 freed up which has 1 x 250GB and 3 x 2TB HDDs, its time to get this project started.
Several minutes later I had the latest stable Debian (8.2.0) NetInstall ISO downloaded and burnt to a CD all ready to get started.
Upon booting, I always use the expert install, not because that reflects my skill level, more from habit following years of the graphical installers not working on all sorts of old hardware I've accumulated over the years.
Anyway, before we get started ensure the system is up to date, it should be as it was a fresh Net Install, but old habits die hard.
apt-get update
apt-get upgrade
apt-get install vim vsftpd apache2 samba
Following the installation two new directories are to be created. Using the -p option, any parent directories are also created.
mkdir -p /home/TRUSTEDUSER/content/media/video
mkdir -p /home/TRUSTEDUSER/content/media/audio
FTP Access
As I am hosting the media within my home directory, it is simple enough to allow me ReadWrite FTP access to it all by making the following changes in the /etc/vsftpd.conf file.
local_enable=YES
write_enable=YES
local_umask=022
Following the edits, restart the service.
service vsftpd restart
Web Browser (HTTP) Access
I need read access to all my media content using a nothing more than a browser. This isn't destined to be publically available so I'm happy with the security implications of such a broad approach to access and security. In this simple scenario it is easiest to just update the default Document Root as below:
vi /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www/html
DocumentRoot /home/TRUSTEDUSER/content
Once the default document root has been updated, we need to turn attention to the apache2.conf file. In this file we delete (or comment if you prefer) the eisting Directory statements before adding a new one and restarting apache as shown below:
vi /etc/apache2/apache2.conf
<Directory /home/TRUSTEDUSER/content/>
Options Indexes FollowSymLinks
Require all granted
</Directory>
service apache2 restart
Samba (Microsoft Networking Access)
For samba I wanted 3 shares, one hidden which would be write enabled for me, and two others which were read only by anyone using the guest account.
My target folder structure and permissions are shown below
/home/TRUSTEDUSER/content/media # Write access enabled for me (TRUSTEDUSER)
/home/TRUSTEDUSER/content/media/audio # Read only access for Guest account
/home/TRUSTEDUSER/content/media/video # Read only access for Guest account
The supplied Samba config file /etc/samba/smb.conf is replaced with one containing just the elements I require. Of course, I take a backup first.
cp /etc/samba/smb.conf /etc/samba/smb.conf.original
The file below is my new /etc/samba/smb.conf file. For simplicity I've just copied it here.
#======================= Global Settings =======================
[global]
workgroup = WORKGROUP
dns proxy = no
load printers = no
printcap name = /dev/null
disable spoolss = yes
#### Networking ####
interfaces = 127.0.0.0/8 eth0
bind interfaces only = yes
#### Debugging/Accounting ####
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
####### Authentication #######
server role = standalone server
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
############ Misc ############
usershare allow guests = yes
#======================= Share Definitions =======================
[media]
comment = Media Share
path = /home/TRUSTEDUSER/content/media
valid users = "TRUSTEDUSER"
write list = "TRUSTEDUSER"
guest ok = no
browseable = no
[audio]
comment = Audio Media Share
path = /home/TRUSTEDUSER/content/media/audio
read only = yes
guest ok = yes
[video
]
comment = Video Media Share
path = /home/TRUSTEDUSER/content/media/video
read only = yes
guest ok = yes
Once the /etc/samba/smb.conf file has been updated, its a good idea to use the testparm command to catch any mistakes. Once that looks ok, reload samba with the following:
/etc/init.d/samba restart
Samba stores it user accounts seperate from the Linux system running Samba, therefore I need to create a Samba Password as below:
smbpasswd -a TRUSTEDUSERIf you want to use a Samba username that doesn't already have a Linux account, you can either create a Linux account the normal way with useradd, or as below if you do not want the user to be able to log into the Linux host.
useradd -c "Another Users Name" -d /home/AnotherUsersName -s /sbin/nologin AnotherUsersName smbpasswd -a AnotherUsersNameAfter samba is configured, and the new user has been configured we can test to make sure the access works as expected. I am not going to document all that here, but if what I have written helps someone then great. Final things to think about, are the underlying Linux file permissions on the appropriate directories and files. I have mine configured for 755, but there are other schools of thought out there.
Linux - expanding LVM volume
I have set up a new media sharing Debian box which I need to expand the size of the existing home logical volume to allow me to store my media content in one place. The process is relatively straight forward assuming the server has LVM up and running already. We need to follow the process of:-
- Install the new disk(s)
- Partition the new disk(s)
- Prepare the PV's (Physical Volumes)
- Extend the existing VG (Volume Group)
- Extend the existing LV (Logical Volume) and the associated filesystem
fdisk -l
.
Assuming the disk(s) are all present and correct simply delete any existing partitions and create a new one on each disk. Use caution with fdisk
as you could delete your data if you make errors. Use your favorite search engine if you are not sure.
In my example there are 2 x 2TB disks, so I have 2 new PV's to create as shown below:
root@content:~#pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@content:~#pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully createdOnce the PV's are created we need to extend the existing volume group (which on my system is called content-vg):
root@content:~#vgextend content-vg /dev/sdb1 Volume group "content-vg" successfully extended root@content:~#vgextend content-vg /dev/sdc1 Volume group "content-vg" successfully extendedOnce we have extended the volume group to include the 2 new disks, we just need to expand the logical volume and file system to use the free space:
root@content:~#lvextend -r -l 100%FREE /dev/content-vg/homeNow when we check with
df
we can see the increased space available on my home volume.
Other command useful along the way are pvdisplay vgdisplay and lvdisplay
. I am not about to document them all here, as compious information is available 3 clicks from your favorite search engine.
Once we have extended the volume group to include the 2 new disks, we just need to expand the logical volume and file system to use the free space:
Thats All Folks.
Monday 23 February 2015
Raspberry Pi - SMS Texting using 3G dongle
The problem I'm having to solve is that the 3G Dongle isn't being recognised as a serial port, it is being recognised as a storage device. Even though the description obtained from lsusb clearly identifies it as a modem.
root@rasp-storage:~# lsusb
DefaultVendor=0x12d1
DefaultProduct=0x1446
MessageContent="55534243123456780000000000000011062000000100000000000000000000"
Create a file /usr/local/sbin/3gmodemswitch containing.
usb_modeswitch -I -W -c /etc/usb_modeswitch.d/12d1\:1446
Create a file /etc/udev/rules.d/99-3gmodem.rules which contains:
ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="/usr/local/sbin/3gmodemswitch"
So when the modem is plugged in, udev rules pick it up and execute the 3gmodemswitch script, which in turn calls usb_modeswitch. If we have a look at the output from lsusb now, we see:
Incidentally the number above is random, furthermore I put a letter B in the text on purpose just to save some poor soul getting unsolicited texts by anyone reading this and simply copying the text.
So with a little more scripting, I now use this Raspberry Pi as a notification server, it polls other devices (predominately network equipment) and services and text's me if there are problems. I can also sent it texts to perform simple actions, but that element is still very much a work in progress.
Hope someone other than myself find this information useful. :)
root@rasp-storage:~# lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 006: ID 12d1:1446 Huawei Technologies Co., Ltd. E1552/E1800/E173 (HSPA modem)
Anyway, before we get started ensure the system is up to date. I'm using the latest Raspian so its a simple case of:
apt-get update
apt-get upgrade
The tool we are going to be using is called usb-modeswitch.
root@rasp-storage:~# apt-cache search modeswitch
usb-modeswitch - mode switching tool for controlling "flip flop" USB devices
usb-modeswitch-data - mode switching data for usb-modeswitch
root@rasp-storage:~# apt-get install usb-modeswitch usb-modeswitch-data
I found the information for the usb_modeswitch elements by googling the "Huawei E173 modem", the details below are unlikely to work on other 3G modems. Create a file named 12d1:1446 under /etc/usb_modeswitch.d/ which contains:
Anyway, before we get started ensure the system is up to date. I'm using the latest Raspian so its a simple case of:
apt-get update
apt-get upgrade
The tool we are going to be using is called usb-modeswitch.
root@rasp-storage:~# apt-cache search modeswitch
usb-modeswitch - mode switching tool for controlling "flip flop" USB devices
usb-modeswitch-data - mode switching data for usb-modeswitch
root@rasp-storage:~# apt-get install usb-modeswitch usb-modeswitch-data
I found the information for the usb_modeswitch elements by googling the "Huawei E173 modem", the details below are unlikely to work on other 3G modems. Create a file named 12d1:1446 under /etc/usb_modeswitch.d/ which contains:
DefaultVendor=0x12d1
DefaultProduct=0x1446
MessageContent="55534243123456780000000000000011062000000100000000000000000000"
Create a file /usr/local/sbin/3gmodemswitch containing.
usb_modeswitch -I -W -c /etc/usb_modeswitch.d/12d1\:1446
Create a file /etc/udev/rules.d/99-3gmodem.rules which contains:
ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="/usr/local/sbin/3gmodemswitch"
So when the modem is plugged in, udev rules pick it up and execute the 3gmodemswitch script, which in turn calls usb_modeswitch. If we have a look at the output from lsusb now, we see:
lsusb Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0781:5571 SanDisk Corp.
Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 006: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
root@rasp-sms:/etc/usb_modeswitch.d#
I was able to reboot, and do a complete power down restart, and the modem continued to be recognized as a 3G modem. It should be noted I have in the past experienced an issue where the root filesystem was not on the SD card, but a USB drive. However when starting the Pi in that configuration sometimes the built in storage of the 3G modem was identified as SDA rather than the USB thumb drive. To fix this situation I made sure to use the root=PARTUUID=XXXXX notation in the /boot/cmdline.txt file. Finally, install smstools using:
apt-get install smstools
Following which edit the /etc/smsd.conf file and append the following to the bottom (using the correct ttyUSB device:-
[GSM1]
#init =
device = /dev/ttyUSB0
incoming = yes
#pin =
baudrate = 19200
Now when I drop a file into the /var/spool/sms/outgoing/ directory in the format:
To: 444797575B134
Hello From My Raspberry Pi. :)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0781:5571 SanDisk Corp.
Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 006: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
root@rasp-sms:/etc/usb_modeswitch.d#
I was able to reboot, and do a complete power down restart, and the modem continued to be recognized as a 3G modem. It should be noted I have in the past experienced an issue where the root filesystem was not on the SD card, but a USB drive. However when starting the Pi in that configuration sometimes the built in storage of the 3G modem was identified as SDA rather than the USB thumb drive. To fix this situation I made sure to use the root=PARTUUID=XXXXX notation in the /boot/cmdline.txt file. Finally, install smstools using:
apt-get install smstools
Following which edit the /etc/smsd.conf file and append the following to the bottom (using the correct ttyUSB device:-
[GSM1]
#init =
device = /dev/ttyUSB0
incoming = yes
#pin =
baudrate = 19200
Now when I drop a file into the /var/spool/sms/outgoing/ directory in the format:
To: 444797575B134
Hello From My Raspberry Pi. :)
Incidentally the number above is random, furthermore I put a letter B in the text on purpose just to save some poor soul getting unsolicited texts by anyone reading this and simply copying the text.
So with a little more scripting, I now use this Raspberry Pi as a notification server, it polls other devices (predominately network equipment) and services and text's me if there are problems. I can also sent it texts to perform simple actions, but that element is still very much a work in progress.
Hope someone other than myself find this information useful. :)
Thursday 15 January 2015
Raspberry Pi - Basic Setup
This is the initial setup and configuration I use for Raspberry Pi's. It isn't an all encompassing How-To, more a simple task list to jog my memory along the way:-
iface eth0 inet dhcp iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
Setup your own user account:
sudo adduser fred
Enable sudo access on your new account and delete it from pi account:
sudo visudo
pi All=(ALL) NOPASSWD: ALL
- Download the latest debian based image; Raspbian Latest
- Write the image to a SD Card.
- Boot the Raspberry Pi.
- Run through the raspi-config script that runs automatically.
- After the Raspberry Pi has booted customize the required elements below.
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
Setup your own user account:
sudo adduser fred
Enable sudo access on your new account and delete it from pi account:
sudo visudo
fred All=(ALL) NOPASSWD: ALL
Logout as the pi user and log back in as your new use defined above. Once logged back in as your new user remove the pi account if you wish.
sudo deluser pi
If preferred you can just lock the pi account:
sudo passwd -l pi
Name Resolution, configure DNS if desired in /etc/resolv.conf you only really need 1 or 2 nameserver entries, the multiple addresses are there for my reference only.
Finally update using:
sudo apt-get update
At this point, I usually shutdown the PI and take a backup of the SD card before moving on to more specific installation and configuration.
Logout as the pi user and log back in as your new use defined above. Once logged back in as your new user remove the pi account if you wish.
sudo deluser pi
If preferred you can just lock the pi account:
sudo passwd -l pi
Name Resolution, configure DNS if desired in /etc/resolv.conf you only really need 1 or 2 nameserver entries, the multiple addresses are there for my reference only.
domain localdomain.com # Whatever domain name you wish to use
search localdomain.com #
nameserver 8.8.4.4 # Public DNS provided by Google
nameserver 8.8.8.8 # Public DNS provided by Google
nameserver 208.67.222.222 # Public DNS provided by opendns
nameserver 208.67.220.220 # Public DNS provided by opendns
nameserver 192.168.0.111 # Private hosted DNS server
sudo apt-get update
sudo apt-get dist-upgrade
At this point, I usually shutdown the PI and take a backup of the SD card before moving on to more specific installation and configuration.
Subscribe to:
Posts (Atom)