Ever wanted to run your own usenet search engine? This howto will go through the steps required to install the Newznab usenet indexer on Ubuntu. Ubuntu 12.04 was used for this guide, however all current versions of Ubuntu should be the same.
Continue Reading…
- A linux PC (Only required for this guide. The same process could be done using tools on other operating systems).
- SD card (minimum 64mb)
- USB memory stick (minimum 2gb)
To update the time on a Linux installation, simply run the following command:
$ sudo ntpdate <time server address>
Replacing <time server address> with a valid NTP time server address.
eg:
$ sudo ntpdate pool.ntp.org
If you only want to query the time, without updating your system, use the following command:
$ ntpdate -q pool.ntp.org
To update the time, without outputting any log information to standard output (handy for a cron job), use the following command:
$ sudo ntpdate -s pool.ntp.org
This howto outlines how to connect to a PPTP VPN server from a Linux computer running Ubuntu (or a Ubuntu based distribution). It covers the installing of the PPTP VPN client, configuration, and connecting/disconnecting from the VPN connection.
Continue Reading…
Raspbian is a Debian based Linux distribution, specifically for use with the Raspberry Pi. The Raspberry Pi requires that the system is initially booted of SD. Because of this, a default install of Raspbian requires an SD card of at least 2gb.
I received my Raspberry Pi the other day, and didn’t have a spare 2gb SD card that wasn’t already being used, but I had a few smaller ones around the place (128mb, 256mb, etc). I wanted to find a way to utilize one of these smaller SD cards just for the system boot files, and then run the main system off a USB memory stick.
It turns out that the Raspbian image contains a boot partition, and as long as you can copy this to a SD card (and modify the cmdline.txt file to point to the root partition on the USB memory stick), you will be able to initially boot of a small SD card, then load the rest of the system off a larger USB memory stick.
Requirements:
Determining device names:
Find the device names for both your USB device, and your SD device. You can usually use the ‘dmesg’ command to find the device names for your storage devices.
Eg: This shows the dmesg output after plugging in a USB memory stick.
$ dmesg | tail [4489268.141393] scsi 18:0:0:0: Direct-Access SanDisk Cruzer Switch 1.20 PQ: 0 ANSI: 5 [4489268.143286] sd 18:0:0:0: Attached scsi generic sg10 type 0 [4489268.146251] sd 18:0:0:0: [sdj] 7821312 512-byte logical blocks: (4.00 GB/3.72 GiB) [4489268.150144] sd 18:0:0:0: [sdj] Write Protect is off [4489268.150156] sd 18:0:0:0: [sdj] Mode Sense: 43 00 00 00 [4489268.150163] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.158814] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.162381] sdj: sdj1 sdj2 [4489268.173591] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.176965] sd 18:0:0:0: [sdj] Attached SCSI removable disk
In my examples, /dev/sdf is the SD card, and /dev/sdj is the USB memory stick.
Obtaining Raspbian:
Download the latest Raspbian release from http://www.raspberrypi.org/downloads
At the time of writing, the latest release was 2012-07-15-wheezy-raspbian.zip
Installing Raspbian to a USB memory stick:
Extract the zip to a location on your PC.
unzip 2012-07-15-wheezy-raspbian.zip
This should extract a single file named “2012-07-15-wheezy-raspbian.img”.
Write this image to your USB memory stick device. Make sure you get the “of” (output file) part of the command line parameters correct, so you don’t overwrite your hard drive, or any other storage device.
sudo dd if=2012-07-15-wheezy-raspbian.img of=/dev/sdj
2012-07-15-wheezy-raspbian.img being the input file.
/dev/sdj being the output file/device (the USB memory stick device).
Preparing the SD card:
Make sure you obtain the correct device name for your SD card. In this example, my SD card is /dev/sdf.
Remove any partitions that may already exist on the SD card.
(you can do this via fdisk, or use ‘sudo dd if=/dev/zero of=/dev/sdf’)
Create a single FAT32 partition.
$ sudo fdisk /dev/sdf
You should be presented with the following prompt:
Command (m for help):
press ‘n’ to create a new partition
Command (m for help): n Command action e extended p primary partition (1-4)
Press ‘p’ to create a primary partition.
p Partition number (1-4):
Press ‘1’ to create the first partition.
Partition number (1-4): 1 First cylinder (1-1024, default 1):
Press enter to automatically select the default first cylinder.
Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1024, default 1024):
Press enter again to automatically select the last cylinder.
Using default value 1024 Command (m for help):
Press ‘t’ to change the partition id
Command (m for help): t Selected partition 1 Hex code (type L to list codes):
Enter in the hex code ‘c’. This will change this partition to be FAT32.
Hex code (type L to list codes): c Changed system type of partition 1 to c (W95 FAT32 (LBA))
Press ‘w’ to write changes to the device, and exit.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks. $
Now that you have a FAT32 partition created, you need to put a filesystem on it.
sudo mkfs.msdos -v /dev/sdf1
eg:
$ sudo mkfs.msdos -v /dev/sdf1 mkfs.msdos 3.0.7 (24 Dec 2009) /dev/sdf1 has 8 heads and 61 sectors per track, logical sector size is 512, using 0xf8 media descriptor, with 499650 sectors; file system has 2 16-bit FATs and 8 sectors per cluster. FAT size is 244 sectors, and provides 62391 clusters. Root directory contains 512 slots. Volume ID is 43181ecb, no volume label. $
Installing the boot files onto the SD card:
Create a couple of folders under /tmp for use when mounting the USB memory stick, and the SD card.
$ sudo mkdir /tmp/mnt_usb $ sudo mkdir /tmp/mnt_sd
Mount the USB memory stick.
$ sudo mount /dev/sdj1 /tmp/mnt_usb
Mount the SD card.
$ sudo mount /dev/sdf1 /tmp/mnt_sd
Copy across the boot files from the USB memory stick to the SD card.
$ sudo cp /tmp/mnt_usb/* /tmp/mnt_sd/
Modify the cmdline.txt file to tell the system where to find the root partition.
$ sudo nano /tmp/mnt_sd/cmdline.txt
modify this line:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
to read:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait
(This is just changing /dev/mmcblk0p2 (the 2nd partition on the SD card) to /dev/sda2 (the second partition on the USB memory stick). This tells the Raspberri Pi device where to find the root partition.
Save and exit the editor.
Finishing up:
Unmount the devices.
$ sudo umount /tmp/mnt_usb $ sudo umount /tmp/mnt_sd
Remove the temporary mount folders. (Make sure they unmounted OK first, otherwise it will delete the data on the device itself).
$ sudo rm -rf /tmp/mnt_usb $ sudo rm -rf /tmp/mnt_sd
You can now unplug your USB memory stick, and SD card, and insert them into your Raspberry Pi.
Power up your Raspberry Pi, and make sure it boots up into Raspbian correctly. If all goes well, it should boot up fine.
There may be times when you need to set up a static route in Linux to allow your PC to access a network that is not accessible via the default gateway route. An example of this would be if you had a inter office VPN. You would want your main internet traffic to go via a default gateway (your main cable/adsl router), and traffic destined for the subnet of the other office would go via the device managing the VPN connection, assuming its not the same device that is managing the main internet connection.
Setting up a static route in Linux:
Route command syntax:
route add -net <destination>/<prefix> gw <gateway>
Destination = The destination network address.
Prefix = The cidr notation/network prefix for the destination network. (eg. 24 for 255.255.255.0, 8 for 255.0.0.0, etc).
Gateway = The gateway/router ip address to route the traffic through.
eg:
# route add -net 192.168.200.0/24 gw 192.168.0.254
Make sure you run the command as root, or using “sudo”.
This adds a route for the 192.168.200.0/24 network, so that traffic destined for this network gets routed through 192.168.0.254. The gateway address must be on on the same network subnet that you are on.
This route wont get saved automatically, so after rebooting it will be gone. To set it up to automatically add the route at start up, you will need to edit one of the interface config files, or start up scripts, depending on the Linux distribution used.
For example, you could add the route command into the “/etc/rc.local” script on Ubuntu, above the “exit 0” line, and the route will automatically get added on system boot up.
Test connectivity using the ping and traceroute commands to make sure the destination network is accessible and going via the correct route.
Slax is a great LiveCD linux distribution based on Slackware that fits in your pocket. One of the great features is the modular approach that is used for the packages, which are known as modules in Slax. Got a small USB stick that you no longer use? Put Slax on it.
This guide shows you how to install Slax linux to a USB memory stick.
Download and Extract:
Download the .tar version (also may be labeled as the USB version) of Slax from http://www.slax.org/get_slax.php.
Install 7-Zip or another archiving application that is capable of extracting .tar files.
Insert a USB memory stick into your PC. Must be at least 256mb.
Format the USB stick as FAT32 if it currently formatted with some other file system.
Open the slax.tar file that you downloaded, in your archive program of choice.
Extract the archive to the root of your USB memory stick. In this example, my USB memory stick is set as “I:”.
Installation using Windows XP:
Open Windows explorer and browse to the drive letter of your USB memory stick.
Go into the “boot” sub folder.
Double click the “bootinst.bat” batch file.
Installation using Windows Vista / Windows 7 / Windows 2008 / or newer:
Open a command prompt window “as administrator”. Meaning, right click a shortcut for the command prompt, and select “Run as administrator”.
Change to the drive letter of your USB memory stick by simply typing the drive letter, followed by :
Eg:
i:
Change directory to the “boot” folder.
cd boot
bootinst
The bootinst installation script:
If you have a card reader installed, you may get some warnings about not having a disk in a drive. You can hit “Cancel” on those.
You will be presented with a Slax boot installer warning screen.
Make sure this specifies your USB drive letter correctly, so it doesn’t corrupt any other drives in your system.
Press any key to continue, or close the window if you do not want to continue.
The script will update the master boot record on the USB memory stick, and should now be bootable.
You can now “safely remove” the USB device from Windows, unplug it, and use it to boot into Slax.
Below is an example of a PHP-FastCGI init script for use on Ubuntu systems.
This startup init script was copied from http://wiki.nginx.org/Ubuntu-php-fastcgi and slightly modified to keep all start up settings in the one script file. Thanks to the original author.
It can also be downloaded in full from:
http://www.networkinghowtos.com/wp-content/uploads/scripts/php-fastcgi
Remember to “chmod +x” this script to make it executable.
This file should be stored in “/etc/init.d” and set to run at startup by running the “sudo /usr/sbin/update-rc.d -f php-fastcgi defaults” command.
To download and set up the init file in one go, run the following commands:
cd /etc/init.d sudo wget -O php-fastcgi "http://www.networkinghowtos.com/wp-content/uploads/scripts/php-fastcgi" sudo chmod +x php-fastcgi sudo update-rc.d -f php-fastcgi defaults
/etc/init.d/php-fastcgi contents:
#! /bin/sh ### BEGIN INIT INFO # Provides: php-fastcgi # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start and stop php-cgi in external FASTCGI mode # Description: Start and stop php-cgi in external FASTCGI mode ### END INIT INFO # Author: Kurt Zankl# Do NOT "set -e" PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="php-cgi in external FASTCGI mode" NAME=php-fastcgi DAEMON=/usr/bin/php-cgi PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME ######################################################################## # # Settings for php-cgi in external FASTCGI Mode # # Should php-fastcgi run automatically on startup? (default: no) START=yes # Which user runs PHP? (default: www-data) EXEC_AS_USER=www-data # Host and TCP port for FASTCGI-Listener (default: localhost:9000) FCGI_HOST=127.0.0.1 FCGI_PORT=9000 # Environment variables, which are processed by PHP PHP_FCGI_CHILDREN=4 PHP_FCGI_MAX_REQUESTS=1000 ######################################################################## # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present #[ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # If the daemon is not enabled, give the user a warning and then exit, # unless we are stopping the daemon if [ "$START" != "yes" -a "$1" != "stop" ]; then log_warning_msg "To enable $NAME, edit /etc/init.d/$NAME and set START=yes" exit 0 fi # Process configuration export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT" do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \ $DAEMON_ARGS \ || return 2 } do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. # If the above conditions are not satisfied then add some other code # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON [ "$?" = 2 ] && return 2 # Many daemons don''t delete their pidfiles when they exit. rm -f $PIDFILE return "$RETVAL" } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 3 ;; esac :
An important aspect of any firewall are the log files. Iptables on Linux provides logging functionality, however by default, it will get outputted to the /var/log/messages log file. This can clutter things up, and make it hard to check the logs.
If you want to change the file that IPTables logs to, you need to set up your iptables rules to output a log prefix. Rsyslog will then be configured to pick up this prefix, and output the information to a custom log file, containing just the iptables log information.
Install rsyslog if it is not already installed.
$ sudo apt-get install -y rsyslog
Configure your iptables firewall rules to output a log prefix using the –log-prefix command:
$ sudo iptables -A INPUT -p tcp --dport 22 --syn -j LOG --log-prefix "iptables: "
(this will log connection attempts to the SSH port)
Next you need to configure rsyslog to pickup the iptables log prefix.
Create an empty rsyslog conf file for iptables.
$ sudo touch /etc/rsyslog.d/10-iptables.conf
Open this file up in a file editor.
$ sudo nano /etc/rsyslog.d/10-iptables.conf
Add the following two lines:
:msg, contains, "iptables: " -/var/log/iptables.log & ~
Save the file and exit the editor.
The first line checks the log data for the word “iptables: ” and appends it into the /var/log/iptables.log file.
The second line simply halts the processing of the log information, so that it doesnt get logged into /var/log/messages as well as the iptables.log file.
Restart rsyslog:
$ sudo service rsyslog restart
The logs should now be appearing in /var/log/iptables.log
You can verify this by tailing the log file:
$ tail -f /var/log/iptables.log
Try and connect to SSH from another machine, and you should see a log entry get created, and appear on the screen automatically.
Eg:
$ tail -f /var/log/iptables.log Feb 20 23:27:11 ubuntu kernel: [1988916.899165] iptables: IN=eth0 OUT= MAC=00:00:00:00:00:00:00: 00:00:00:00:00:00:00 SRC=192.168.0.3 DST=192.168.0.1 LEN=60 TOS=0x10 PREC=0x00 TTL=64 ID=30541 DF PROTO=TCP SPT=60148 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0
Close the ‘tail’ program using Ctrl+c.
The Linux DD command allows you to read and write directly to block devices. If you are playing around with boot loaders, dual booting, etc, its a good idea to take a copy of your master boot record just in case things go astray and you need to restore it.
To backup the master boot record (MBR):
$ sudo dd if=/dev/sda of=boot.bin bs=512 count=1
/dev/sda is the device of the hard drive you want to take the backup from.
boot.bin is the file that will get created, containing the backup. Keep this in a safe place.
To restore the MBR backup back to the hard drive:
$ sudo dd if=boot.bin of=/dev/sda bs=512 count=1
Note: Don’t mix up the ‘if=’ (input file) and ‘of=’ (output file) options, as you may overwrite your MBR accidentally.
The default port for SMTP is port 25, but there may be some scenarios where you may need Postfix to listen on another port as well (or instead of). For example, if you want to send emails via your own mail server, from your work computer, but the work network may be blocking all port 25 traffic out onto the internet from all PC’s but the mail server.
You can get around this by setting up Postfix on another port number, for example 10025.
This configuration is done in the master.cf configuration file. Edit it in your editor of choice.
$ sudo nano /etc/postfix/master.cf
This file is in the following format:
# ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ==========================================================================
The first column is the port number that you want to listen on. The default SMTP port 25 line will read as follows:
smtp inet n - - - - smtpd
To allow listening on port 10025 as well, its simply a matter of copying this line, pasting it below the smtp line, and changing smtp to ‘10025’.
For example:
smtp inet n - - - - smtpd 10025 inet n - - - - smtpd
If you dont want to listen on port 25, you can simply change ‘smtp’ to your new port number.
Save the file and exit the editor.
Restart Postfix for the changes to take effect.
$ sudo /etc/init.d/postfix restart
You can now issue the ‘netstat -an’ command and see that it is listening on port 25 and port 10025.
The netstat output would look something like this for my example:
$ netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:10025 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
Be aware that if you are running a mail server on the internet, and you are not listening on port 25, you won’t receive external emails. If you are setting up a new server, make sure your configuration doesn’t allow your mail server to be an open relay.