Social Icons

Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Setup Dynamic DNS / DynDNS for *FREE* on Raspberry Pi / Ubuntu


Update: You can try our newer and easier guide which uses dns4e.com here

You might have recently setup your Raspberry Pi or your Linux box as a 24 x 7 torrent downloader, or a small Web server to host your own website. And just then you realize that your ADSL or Cable Internet connection has a dynamic IP address which changes frequently and every time you reconnect. Thus, it becomes hard to access your box with a fixed Domain name or IP address.

To solve this problem you can setup a Dynamic DNS which will update your IP to a DNS name everytime it changes and you can access you hosted website, or ssh into it to monitor torrent downloads with ease.

While there are many paid dynamic dns service providers available, but here you will see one way to do it for **FREE** [Thanks to freedns.afraid.org]

Step 1
Register for a Free domain at http://freedns.afraid.org/signup/
[We will take techhome.homenet.org in this guide]

Step 2
Logon to FreeDNS (where you just registered) and goto http://freedns.afraid.org/dynamic/
Or, simply click on "Dynamic DNS" link from the left navigation menu

Right click on "Direct URL" and copy the URL and paste it somewhere.

You should notice a large and unique alpha-numeric key in the URL, make a note of it as shown below:
http://freedns.afraid.org/dynamic/update.php?[alpha-numeric-key]

Step 3
Install inadyn using the following command:
sudo apt-get install inadyn


Step4
Configure inadyn using the below steps:
sudo nano /etc/inadyn.conf

And add the following contains in it replacing the actual values:
--username techhome
--password mypassword
--update_period 3600
--forced_update_period 14400
--alias techhome.homenet.org,alphanumeric key
--background
--dyndns_system default@freedns.afraid.org
--syslog



Step 4
Now, we need to ensure that the DNS updater (Inadyn) runs automatically after every re-boot

export EDITOR=gedit && sudo crontab -e

Add the following line:
@reboot /usr/sbin/inadyn


Step 5
Reboot system and then run the following command to ensure inadyn is running:

ps -A | grep inadyn

Now your host is ready and up for accessing from internet...

You can trying ssh-ing from another computer over the internet
ssh username@techhome.homenet.org

Or, if any web server is running, then simply browse to  http://techhome.homenet.org

Or, you can just ping it to test ping techhome.homenet.org

To check the logs you can use this:
more /var/log/messages |grep INADYN

This has been re-tested to be working perfectly with inadyn 1.96.2-1 on Raspbian 3.12.22+

How to setup mount / auto-mount USB Hard Drive on Raspberry Pi

Follow the simple steps in the order mentioned below to have your USB drive mounted on your Raspberry Pi every time you boot it.

*These steps works both on Raspbian Wheezy & Jessie*

These steps are required especially if your are setting up a Samba share, or a 24x7 torrent downloader, or alike where your Raspberry Pi must have your external storage already mounted and ready for access by the services / daemons.

Step 0.
Plug in your USB HDD / Drive to Raspberry Pi
If you are using a NTFS formatted drive, install the following
sudo apt-get install ntfs-3g

Step 1.
Log on pi using ssh terminal and execute:
ls -l /dev/disk/by-uuid/

You will see something like the following:

lrwxrwxrwx 1 root root 10 Jan  1  1970 0AC4D607C4D5F543 -> ../../sda1
Note down the value of the UUID --> 0AC4D607C4D5F543

Step 2.
Create a location for mount point:
sudo mkdir /media/NASDRIVE

Give proper permission:
sudo chmod 770 /media/NASDRIVE

Step 3.
Get the uid, gid for pi user and group with id command (usually 1000)

Step 4.
Mount the USB Drive and then check if it is accessible at /media/NASDRIVE
sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda1 /media/NASDRIVE

Note:
ntfs-3g for NTFS Drives
vfat for FAT32 Drives
ext4 for ext4 Drives

Step 5.
Now, we will configure RasPi to do this after every reboot:
Take a backup of current fstab and then edit
sudo cp /etc/fstab /etc/fstab.backup
sudo nano /etc/fstab

Add the mount information in the fstab file (replace UUID with your own):
UUID=0AC4D607C4D5F543 /media/NASDRIVE ntfs-3g uid=1000,gid=1000,umask=007 0 0

Step 6.
Reboot
sudo reboot

Step 8. (Optional, required if using as data storage for owncloud)
If you are configuring ownCloud's data directory on your NAS drive, it should be having a 770 permission for www-data user. You can simply add user www-data to pi group, since its already having 770 as permission as set above in fstab.

sudo usermod -a -G pi www-data


How to Setup Samba network share on Raspberry Pi

Raspberry Pi is one of the hottest thing in the tech world today with endless utilities. One of the common use is to set up a NAS (Network Area Storage) server, which you can access over your home netlibpam-smbpasswork (Wired LAN or WiFi).


Assuming your storage drive (USB HDD in this case) is already mounted we will proceed with the steps. If you haven't followed the steps to mount your USB HDD yet then follow my other guide here, and then return to this point.

Step 1.
Install Samba
sudo apt-get install samba samba-common-bin

Update: Install libpam-smbpass (For auto sync of unix user passwords)
sudo apt-get install libpam-smbpass

Step 2.
Backup Samba configuration file, and then configure Samba
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup

Edit smb.conf
sudo nano /etc/samba/smb.conf

You can copy over the configurations from the below snippet replacing the path to your mounted USB drive.


Step 3.
Restart Samba
sudo service samba restart

You should be able to access your NAS from any windows / unix system using the following path \\RaspPiNAS

Remember you will require to provide credentials of a valid user as added on Raspberry Pi to be able to access the share. If you want it to behave differently then change the settings for security = user and valid users = @users related parameters.

USB drive not mounted before transmission daemon startup - Raspberry Pi


Many Raspbian users face a common issue of transmission daemon (service) getting started before their USB HDD is auto mounted by the Raspberry Pi or Raspbian where as for some the issue simply doesn't exists.

The issue lies in the auto mount feature with Raspbian Wheezy, which automatically mounts the USB drives when X-mode (GUI mode) is enabled on bootup. Primarily I would suggest to keep that mode disabled unless you are using RasPi with a head (Read: Monitor / Display), as it otherwise unnecessarily wastes system resources. In case you don't want to disable it for your daily use, just disable it for the time being of this fix but running "sudo raspi-config" and selecting appropriate option then rebooting your pi.

Now, lets see the steps to configure the mount point for USB Drive and set it to be done after every reboot automatically.

Step 0.
Make sure the GUI (X-mode) is turned off
Plug in your USB HDD / Drive to RasPi


Step 1.
Log on pi using ssh terminal and execute:
ls -l /dev/disk/by-uuid/

You will see something like the following:

lrwxrwxrwx 1 root root 10 Jan  1  1970 0AC4D607C4D5F543 -> ../../sda1

Note down the value of the UUID --> 0AC4D607C4D5F543

Step 2.
Create a location for mount point:
sudo mkdir /media/NASDRIVE

Give proper permission:
sudo chmod 775 /media/NASDRIVE

Step 3.
Mount the USB Drive and then check if it is accessible at /media/NASDRIVE
sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/NASDRIVE

Note:
ntfs-3g for NTFS Drives
vfat for FAT32 Drives
ext4 for ext4 Drives

Also, if ntfs-3g is not installed u might have to install it by:
sudo apt-get install ntfs-3g

Step 4.
Now, we will configure RasPi to do this after every reboot:

Take a backup of current fstab
sudo cp /etc/fstab /etc/fstab.backup

Add the mount information in the fstab file:
UUID=0AC4D607C4D5F543 /media/NASDRIVE ntfs-3g rw,defaults 0 0

Step 5.
Reboot
Turn on the GUI mode by sudo raspi-config, only if required.





You should see your USB drive automatically mounted at /media/NASDRIVE

Now, even your transmission should also be able to get your drive in mounted state while the service starts. 

How to configure inotify to work with MiniDLNA and pickup changes in media_dir

With the advent smart computing devices like ARM processor based Raspberry Pi there has been a significant rise is people setting up their home DLNA Servers for streaming their multimedia collections like movies, videos, pictures directly to their internet enabled or DLNA enabled smart TVs. Even almost all modern Android devices are capable to receiving DLNA streams.

MiniDLNA is one of the very popular DLNA server being used by raspbian users and also by users of Arch Linux and even a large community of Ubuntu users, mainly due to to it's fairly small size and simple ease of use. However there is some issue with MiniDLNA in automatically picking up changes / additions to the media_dir (Media Directory) i.e. more often it doesn't picks up any new file if added to the folder and updates the database which appears on your DLNA renderer like TV.

It generally throws the following warning in the logs:
[2012/10/19 18:35:41] inotify.c:195: warn: WARNING: Inotify max_user_watches [8192] is low or close to the number of used watches [4] and I do not have permission to increase this limit.  Please do so manually by writing a higher value into /proc/sys/fs/inotify/max_user_watches.

While most of the solutions suggests setting up a cron job to rebuild the whole of the database at some specific time but hardly any of them address the fix to real issue or some says that the kernel or OS version doesn't supports the inotify feature. Also I don't like the idea of rebuilding the whole media library database every day or every time a new file is added, as ideally it should just add the new file in the media database  Some of you might have even tried to update /proc/sys/fs/inotify/max_user_watches but probably failed with a error "E667: Fsync failed" at the vi.

Solution:
Edit sysctl.conf (A file for defining kernel parameters)
sudo nano /etc/sysctl.conf

Find and change as below if the following line exists or add at the bottom:
fs.inotify.max_user_watches=65536

Save the file Ctrl + X and Y(es)

Now run the below command, you should be able to see the values you have set:
sudo /sbin/sysctl -p

Finally restart MiniDLNA service and things should be working:
sudo service minidlna restart

Note: Make sure you have inotify enabled and a notify interval is set as per your requirement in /etc/minidlna.conf per the following settings
inotify=yes
notify_interval=300