Dynamic DNS with OVH

It may not be a clear thing, but OVH allows to have your own Dynamic DNS if you rent a domain name, surely a better thing than the weird paid website from dyndns.org. I will explain how to handle the update with Linux using ddclient.

On the manager

Connect to https://www.ovh.com/manager/web/#/configuration/domain/ , select your domain name, and create a new dynhost with the button on the right.

Enter a sub-domain name such as “mydyn” (.tombarbette.be), and add the actual IP for now, or just 8.8.8.8 for the time being.

Then it is not finished, you have to create a login that will be able to update that dns entry. Select the second button to handle accesses and create a new login.

Select a login, probably the name of the subdomain, the subdomain itself, and a password.

On the server

sudo apt install ddclient

Then edit /etc/ddclient.conf

protocol=dyndns2
use=web,web=checkip.dyndns.com
server=www.ovh.com
login=tombarbette.be-mydns
password='password'
mydns.tombarbette.be

Just do “sudo ddclient” to update once then “sudo service ddclient restart” to get it updated automatically.

May this be helpful to someone, personally I just forget it all the time so I wanted to leave a post-it somewhere.

Proximus BBOX 3 in bridge mode on Linux (ubuntu,debian,raspbian,centos,fedora,…)

Using bridge mode allows you to get a public IP address on one computer (which can serve as a router) behind your modem. This allows you to know your public IP address without using a third party service, and control more finely all your routing parameters inside your own Linux-based router (this tutorial) or a better router than the BBOX’s one (which is not that bad, now that I can unfortunately compare with Voo…). We’ll call “the router” the device you want to use behind the modem for clarity.

The bridge mode of the Proximus BBOX 3 is quite interesting. You connect normally to your BBOX using DHCP, but you can use PPP over Ethernet (PPPoE) to get a virtual interface inside your router. This virtual “ppp” interface will have a public IP address, and packets will flow IN and OUT the internet through that interface.

Proximus allows you to therefore maintain 2 PPP connection, one established in the BBOX (also used for the TV), and the other inside your router. It also means your home get 2 IP addresses.

I perfer that mode than the VOO one, where the external IP address is given by DHCP to only one host in the LAN, the first to ask it using DHCP (dangerous and prone to configuration errors…). Same and independently for IPv6 using DHCPv6. While Proximus not only gives you an IPv6 address but also a /64 prefix via PPPoE to get a direct connection without using a crappy NAT to all your PCs. For IPv6, Proxiumuss is much more simpler than setting up an independent DHCPv6 client which gives back the v6 prefix to your LAN side. The second downside is that VOO must use ugly hacks to allow connection to the box as there is no “modem internal network” anymore. You can access to your modem at the normally-ilegal 192.168.100.1 address as this is on the “public web” space from the router perspecrive. Moreover it seems that the modem stops responding at DHCP requests from time to time, loosing connectivity… VOO bridge mode is definitively not good… But this may be a temporary bug.

The bridge part

Edit /etc/network/interfaces to add the following lines , assuming that eth0 is the interface used to connect to your BBOX.
auto dsl-provider
iface dsl-provider inet ppp
pre-up /bin/ip link set eth0 up
provider dsl-provider

Install pppoe with sudo apt-get install pppoe on ubuntu/debian or sudo yum install pppoe centos/fedora

Then create a file named /etc/ppp/peers/dsl-provider and add the following lines :

noipdefault
defaultroute
replacedefaultroute
hide-password
noauth
persist
mtu 1492
plugin rp-pppoe.so eth0
user "fc0123456@skynet"
usepeerdns

Then edit the file /etc/ppp/chap-secrets and add the line :
"fc012345@skynet" * "password"

If you lost your skynet creditentials (personnaly, I just never received them), you can change them online on MyProximus. You’ll have to reboot your modem so it receives automatically the new credentials.

And that’s all, you can reboot or do a sudo pon dsl-provider and you’ll have a new inteface with a public IPv4 and a /64 IPv6.

The router part

To give connectivity in IPv4 for your hosts and use your linux host as a router, you’ll have to NAT. But you can delegate your IPv6 range and give public IPv6 addresses to all your PCs using SLAAC ! Remember to also install a firewall…

To do so, install radvd and add in /etc/radvd.conf (if br0 is the interface connected to your internal network) :

interface br0
{
AdvSendAdvert on;
prefix ::/64
{
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
RDNSS 2001:4860:4860::8888 2001:4860:4860::8844
{
# AdvRDNSSLifetime 3600;
};
};

Then do a sudo radvd restart and that’s it.

The RDNSS line give the address of Google’s public DNS to your host. We could use Proximus one, but I don’t have the address on hand.

Note that I write this tuto only now but I did this month ago, I may have forgotten some steps, do not hesitate to contact me 😉

Installing Spotify 9.10 (may 20), 9.11 (july 2) on fedora 20 64 bits

UPDATE : Tested for 9.11 on July 2

 

Remove any old version of spotify :

yum remove “*spotify*”

rm -rf /usr/local/share/spotify*

 

Remove any configuration file of the last spotify version :

rm -rf /home/$USER/.config/spotify

rm -rf /home/$USER/.cache/spotify

 

Download the debian package at http://repository.spotify.com/pool/non-free/s/spotify/spotify-client_0.9.10.17.g4129e1c.78-1_amd64.deb  http://repository.spotify.com/pool/non-free/s/spotify/spotify-client_0.9.11.26.g995ec04.78-1_amd64.deb:

wget http://repository.spotify.com/pool/non-free/s/spotify/spotify-client_0.9.11.26.g995ec04.78-1_amd64.deb

 

Install alien to convert the deb to RPM :

sudo yum install alien

 

Convert the deb to RPM with alien :

fakeroot alien -r spotify-client_0.9.10.17.g4129e1c.78-1_amd64.deb

 

Install the rpm :

sudo rpm -ivh –nodeps –force spotify-client-0.9.10.17.g4129e1c.78-2.x86_64.rpm

 

You will very probably have problems of dependencies to old libraries when launching spotify, like for libssl.so.1.0.0 , libudev.so.0 and libcrypto.so.1.0.0, I made a tarball with them.

 

Download oldlibs.tar :

wget https://www.tombarbette.be/wp-content/uploads/2014/05/oldlibs.tar.gz

 

Untar them :

tar -zxvf oldlibs.tar.gz

 

Copy them to /usr/lib64 :

cp -rf oldlibs/* /usr/lib64/

 

Remove the tarball :

rm -rf oldlibs*

 

If you don’t have any shorcut to launch spotify, copy the desktop entry :

cp -rf /opt/spotify/spotify-client/spotify.desktop /usr/share/applications/

 

If when you type “spotify” it doesn’t launch anything (and say this command is not found) :

sudo ln -s /opt/spotify/spotify-client/spotify /usr/bin/spotify

HDParm

HDParm is a tool to manage your drives. The first section show you how to get informations about your drives, the second tells you how to make them sleep when they aren’t used (and so make power economy). If you’ve got a home server like me with the system on a SSD, with only your big files on the hard drives(s), you’ll want to do this.

 

Get disk informations

You’ve got to use “sudo” to gain super user privilege. Your disk are in the /dev/ folder, named sd* where “*” is a letter. To see the list of disk, one can type use “ls /dev/sd[a-z]“:
debserver % ls /dev/sd[a-z]
/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde

 

To display informations about one disk, you can use “sudo hdparm -i”

 

debserver % sudo hdparm -i /dev/sda
/dev/sda:

Model=WDC WD20EFRX-68EUZN0, FwRev=80.00A80, SerialNo=WD-WCC4M1067803
Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=3907029168
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
AdvancedPM=no WriteCache=enabled
Drive conforms to: Unspecified: ATA/ATAPI-1,2,3,4,5,6,7

* signifies the current active mode

 

Make a drive sleep after some time

From the manual (man hdparm on the command line):

-S Set the standby (spindown) timeout for the drive. This value is used by the drive to determine how long to wait (with no disk activity) before turning off the spindle motor to save power. Under such circumstances, the drive may take as long as 30 seconds to respond to a subsequent disk access, though most drives are much quicker. The encoding of the timeout value is somewhat peculiar. A value of zero means "timeouts are disabled": the device will not automatically enter standby mode. Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes. A value of 253 sets a vendor-defined timeout period between 8 and 12 hours, and the value 254 is reserved. 255 is interpreted as 21 minutes plus 15 seconds. Note that some older drives may have very different interpretations of these values.

 

So “sudo hdparm -I /dev/sdb | grep level” will show the current spindown value, for Example:

debserver % sudo hdparm -I /dev/sdb | grep level
Advanced power management level: 254

Example:

sudo hdparm -S 25 /dev/sdb = spindown after 25*5 seconds.

sudo hdparm -S 245 /dev/sdb = spindown after (245-240)*30 minutes.

 

If you want to check the state to see if it works :

sudo watch -n 1 "hdparm -C /dev/sdb && hdparm -C /dev/sdc && hdparm -C /dev/sdd && hdparm -C /dev/sde"

 

You can use /etc/hdparm.conf to make it permanent:
/dev/sdb {
spindown_time = 60
}

 

 

Ugly things : Autologin of console at startup

→ Ugly but okay in a development virtual machine…

Add “– – autologin root” at the end of /etc/init/tty1.conf

It will auto-log you as root for the first console. For the others, do the same with /etc/init/tty[1-5].conf

You can autolog as “student” by replacing root by student. It’s a little safer … but still ugly.

Detecting if another user is connected on UNIX systems

How to detect if another user is connected to your machine or your server? You can use the command “users” to check yourself is someone is connected. But to do it automatically, you’ll have to use some pipe :

expr length "`users | sed -e "s/\($USER\|\[ \]*\)//ig"`"

The first thing executed by the shell will be the thing under french apostrophe ( ` ). Theses are for evaluation a command, and replace it by what it outputs (normally print on the screen). The command users print the list of connected users into a pipe, to sed which evaluate its command as a regular expression (-e parameter). The command is “s” for substitute, and the rest tells him to find “$USER” (replaced by the currently connected user, you) and spaces and replace them by … nothing. So this part will be an empty string if there is no other users connected than “$USER” and something not empty if there is.

The “expr length” return the length of a string. So this commands print 0 if there is no other user connected, and >0 if there is some !

In a shell script to do something if yes or no…

#!/bin/sh
usersstripped=`users | sed -e "s/\(tom\|\[ \]*\)//ig"`
connected=`expr length "$usersstripped"`
if [ "$connected" -eq "0" ] ; then
echo "No other user is connected"
else
echo "Other user connected !"
fi

It is essentially the same command but done in two times, as in a shell script this command would not be evaluated correctly.

And if you want to put that in a cron to eg. send you a mail, you just have to type “crontab -e” and put a line like :

* * * * * /home/tom/connected

To launch it every minutes. But if you do that you’d better do something like detecting a connection…

My .ZSHRC

To gain a lot of time, you can replace the old “bash” by “zsh”, which is a very more powerful shell with autocompletion, but not only… It has a configuration file called “.zshrc” that you have to put in your home. You can try zsh by installing it and typing “zsh”, and if you’re convinced, keeping it by typing chsh and choosing /bin/zsh.

You have my entire .zshrc but I choose 3 snippets that I prefer to show you the usefullness :

As I use Fedora, Debian, and Ubuntu, I made this to type “i program” to install profram on any system, and “u” to update the system. 



#i for install, u for update

if [ -e /bin/yum ]; then
alias i="sudo yum install"
alias u="sudo yum update"
else
alias i="sudo apt-get install"
alias u="sudo apt-get update && sudo apt-get dist-upgrade"
fi

Force sudo for commands that anyway need it


alias yum="sudo yum"
alias apt-get="sudo apt-get"
alias service="sudo service"

 

Setting vi as default editor :


export EDITOR="vi"

 

The multiples ssh shorcuts

alias sshd="ssh mappam.dyndns.org -X"
alias sshc="ssh itstudents.be -X -L 3129:localhost:3129"

I use my zshrc on multiple system and multiple environment, hence you have some tricks and multiplications like different variables for the same program in the path variable.


#Using color schemes
autoload -U colors && colors

#Adding ADB to path variable
export PATH=${PATH}:/usr/src/android-sdk-linux/platform-tools/:/usr/src/android-sdk-linux/tools/:/opt/android/platform-tols/

##################
# Aliases
##################
#SSH shorcuts
alias sshd="ssh mappam.dyndns.org -X"
alias sshc="ssh itstudents.be -X -L 3129:localhost:3129"
alias ssha="ssh asbss.be -X"
alias sshu="ssh barbette@ms806.montefiore.ulg.ac.be -X"
alias sshq="ssh barbette@queen.run.montefiore.ulg.ac.be -X"
alias scpi="scp -i /home/tom/.ssh/id_rsa"
alias scp3="scp -P 3690 -i /home/tom/.ssh/id_rsa"
alias sam="ssh-add /home/tom/.ssh/id_rsa.montefiore"

#I have all my usefull scripts on my server itstudents, this alias update all scripts on a client, including this .zshrc
alias us="mkdir -p /home/tom/.scripts && scpi tom@itstudents.be:/home/tom/.ssh/authorized_keys /home/tom/.ssh/authorized_keys && scpi tom@itstudents.be:/home/tom/.zshrc /home/tom/.zshrc && scpi -r tom@itstudents.be:/home/tom/.scripts/ /home/tom/ && source /home/tom/.zshrc"

#Alias for these scripts...
#Archiver pack a folder in tar.gz
alias archiver="/home/tom/.scripts/archiver"
#Archiver7 pack a folder in a tar.7z
alias archiver7="/home/tom/.scripts/archiver7"
#Update and reset permissions of an svn
alias svnup="/home/tom/.scripts/svnup"
#Push an rsa key to the list of authorized keys
alias pushrsa="ssh tom@itstudents.be \"cat - >> /home/tom/.ssh/authorized_keys\" < "

#Mount some local shares
alias mh="sudo mount -t nfs debserver:/home/tom /mnt/debserver-home"
alias mp="sudo mount -t nfs debserver:/pub /mnt/debserver-pub"

#Force sudo for some sudo-only commands like installers
alias yum="sudo yum"
alias apt-get="sudo apt-get"
alias service="sudo service"

#Some copy-pasted shorcut from elsewhere
alias k='tree'
alias ltr='ls -ltr'
alias r='screen -D -R'
alias ls='ls --color'
alias l='ls -lh'
alias ll='ls -la'
#i for install, u for update
if [ -e /bin/yum ]; then
alias i="sudo yum install"
alias u="sudo yum update"
else
alias i="sudo apt-get install"
alias u="sudo apt-get update && sudo apt-get dist-upgrade"
fi

#Some links to launch programs on my android devices
alias adbf="ard && adb forward tcp:8999 tcp:8999 && google-chrome http://localhost:8999 &"
alias agmail="adb shell am start -a android.intent.action.MAIN -n com.google.android.gm/.ConversationListActivityGmail"
alias amail="adb shell am start -a android.intent.action.MAIN -n com.google.android.email/com.android.email.activity.EmailActivity"
alias ard="adb shell am start -a android.intent.action.MAIN -n net.xdevelop.rm/.RemoteMobile"
alias rr="sudo route del default && sudo route add default gw 10.0.0.1"

#Wake on lan shorcuts
alias wdebian="sudo etherwake 8C:89:A5:C1:D2:8A"

 

 

# Meta-u to chdir to the parent directory
bindkey -s '\eu' '^Ucd ..; ls^M'

bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
bindkey '\eOH' beginning-of-line
bindkey '\eOF' end-of-line
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
bindkey '\e[5~' beginning-of-history
bindkey '\e[6~' end-of-history
bindkey '\e[3~' delete-char

#Enable auto correct for commands
setopt correct

# Pipe the current command through less
bindkey -s "\el" " 2>&1|less^M"
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'

#Mode verbose pour cp, rm, chmod, chown et rename
for c in cp rm chmod chown rename; do
alias $c="$c -v"
done

#Pendunt une complétion affiche les points
expand-or-complete-with-dots() {
echo -n "\e[31m......\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots

setopt EXTENDED_GLOB
setopt NO_BEEP
export EDITOR="vi"
setopt ZLE
setopt AUTO_CD

##################
# Completion Stuff
##################
bindkey -M viins '\C-i' complete-word

# Faster! (?)
zstyle ':completion::complete:*' use-cache 1
# generate descriptions with magic.
zstyle ':completion:*' auto-description 'specify: %d'

# Don't prompt for a huge list, page it!
zstyle ':completion:*:default' list-prompt '%S%M matches%s'

# Don't prompt for a huge list, menu it!
zstyle ':completion:*:default' menu 'select=0'

# Have the newer files last so I see them first
zstyle ':completion:*' file-sort modification reverse

# color code completion!!!! Wohoo!
zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=36=31"

unsetopt LIST_AMBIGUOUS
setopt COMPLETE_IN_WORD

# Separate man page sections. Neat.
zstyle ':completion:*:manuals' separate-sections true

# Egomaniac!
zstyle ':completion:*' list-separator 'fREW'

# complete with a menu for xwindow ids
zstyle ':completion:*:windows' menu on=0
zstyle ':completion:*:expand:*' tag-order all-expansions

# more errors allowed for large words and fewer for small words
zstyle ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) )'

# Errors format
zstyle ':completion:*:corrections' format '%B%d (errors %e)%b'

# Don't complete stuff already on the line
zstyle ':completion::*:(rm|vi):*' ignore-line true

# Don't complete directory we are already in (../here)
zstyle ':completion:*' ignore-parents parent pwd

zstyle ':completion::approximate*:*' prefix-needed false

#}}}

export GREP_COLOR=31
alias grep='grep --color=auto'

#{{{ Prompt!
colors
host_color=cyan
history_color=yellow
user_color=green
root_color=red
directory_color=magenta
error_color=red
jobs_color=green

host_prompt="%{$fg_bold[$host_color]%}%m%{$reset_color%}"
jobs_prompt1="%{$fg_bold[$jobs_color]%}(%{$reset_color%}"
jobs_prompt2="%{$fg[$jobs_color]%}%j%{$reset_color%}"
jobs_prompt3="%{$fg_bold[$jobs_color]%})%{$reset_color%}"
jobs_total="%(1j.${jobs_prompt1}${jobs_prompt2}${jobs_prompt3} .)"
history_prompt1="%{$fg_bold[$history_color]%}[%{$reset_color%}"
history_prompt2="%{$fg[$history_color]%}%h%{$reset_color%}"
history_prompt3="%{$fg_bold[$history_color]%}]%{$reset_color%}"
history_total="${history_prompt1}${history_prompt2}${history_prompt3}"
error_prompt1="%{$fg_bold[$error_color]%}<%{$reset_color%}"
error_prompt2="%{$fg[$error_color]%}%?%{$reset_color%}"
error_prompt3="%{$fg_bold[$error_color]%}>%{$reset_color%}"
error_total="%(?..${error_prompt1}${error_prompt2}${error_prompt3} )"

case "$TERM" in
(screen)
function precmd() { print -Pn "\033]0;S $TTY:t{%100<...<%~%<<}\007" }
;;
(xterm)
directory_prompt="%{$fg[$directory_color]%}%~%{$reset_color%} "
;;
(*)
directory_prompt="%{$fg[$directory_color]%}%~%{$reset_color%} "
;;
esac

if [[ $USER == root ]]; then
post_prompt="%{$fg_bold[$root_color]%}%#%{$reset_color%}"
else
post_prompt="%{$fg_bold[$user_color]%}%#%{$reset_color%}"
fi
fg_light_gray=$'%{\e[0;34m%}'
PS1="${host_prompt} ${jobs_total}${history_total} ${error_total}${post_prompt} "
RPROMPT="%{$fg_bold[$user_color]%}<%{$reset_color%} ${directory_prompt}${fg_light_gray}[%*]%{$reset_color%}"
#}}}
#Type f to flush the console to history file
alias f="fc -W"

HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.history

setopt LIST_PACKED

#Append to history file instead of re-writing
setopt APPEND_HISTORY

#To share history between terminal, not what I want as I always have multiple terminals like one for generating packet, the other to receive them
#setopt SHARE_HISTORY

#Remove blanks
setopt hist_reduce_blanks
#Remove duplicates
setopt hist_ignore_all_dups
#Do not store commands in history starting with white space
setopt hist_ignore_space

#Init
autoload -U compinit promptinit zcalc zsh-mime-setup
compinit
promptinit
zsh-mime-setup