Paul’s Linux Blog

Just Another Uber-Geek

Set up VPN to a MS Exchange or VPN Server on Command line.

This method of using the VPN via a script works great in crunchbang and I hope other linux systems where the gui is either not available or you prefer to use scripts rather than heavy memory hogging gui's.

Install PPTP Client

First of all we need to install the pptp application:

 # sudo apt-get install pptp-linux

This script will configure everything for you, that's right no messing about no configuring files, just let the script do the hard work for you.

Copy and paste the following into your favorite editor, I used vi

 vi /usr/local/bin/vpnconnect.sh
#!/bin/bash
function routeadd {
   route add -host 61.xxx.xxx.xxx dev ppp0
   route add -host 62.xxx.xxx.xxx dev ppp0
   route add -host 63.xxx.xxx.xxx dev ppp0
}
function makepptp {
   echo pty \"pptp VPN.SERVER.COM --nolaunchpppd\" >> /etc/ppp/peers/pptpvpn;
   echo remotename PPTP >> /etc/ppp/peers/pptpvpn;
   echo require-mppe-128 >> /etc/ppp/peers/pptpvpn;
   echo file /etc/ppp/options.pptp >> /etc/ppp/peers/pptpvpn;
   echo ipparam pptpvpn >> /etc/ppp/peers/pptpvpn;
pppd call pptpvpn &
}
if [ -a /etc/ppp/chap-secrets ];
		then
		rm /etc/ppp/chap-secrets
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
else
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
fi
 
if [ -e /etc/ppp/peers/pptpvpn ];
	then
	rm /etc/ppp/peers/pptpvpn;
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
else
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
fi

Replace "VPN.SERVER.COM" with the name or ip address of the VPN Server you are connecting to.

Configure the Routing.

"route add -host 63.xxx.xxx.xxx dev ppp0" This will enable you to communicate with servers on these address. (host name or IP address)

For example your pc maybe on 192.168.1.10 but your work PC may be on 172.19.100.5 to ensure you can connect to this machine your pc needs to route it's packets (data) on the 172 network address, to do this we would need the routing to be 172.0.0.0.

You can add as many routes as required but be careful as it gets harder to work out any errors with multiple routes.

To see your configured routes type:

 # route -

or to see the full resolved route table (takes longer to display) type:

 # route

You can now save and close the file.

Make the new script executable:

 # chmod +x /usr/local/bin/vpnconnect.sh

Now the script has been completed we need to run it and test the connection.

Subsitute the username and password for your vpn username and password, this maybe your work pc login credentials.

 # sudo vpnconnect.sh your_username your_password

Hopefully no errors came up when you ran the script.
You can run some tests to see if it is connected as follows:

 # ifconfig pptp

To disconnect your vpn connection type:

 # killall pppd

You can use your Gmail account as a smart host to send all messages from your Linux computer.

You need to use a simple program called ssmtp. It accepts a mail stream on standard input with recipients specified on the command line and synchronously forwards the message to gmail.

This is great as all your messages look like they come from gmail and are saved in your sent items for reviewing later on.

Lets do the install.

Installing ssmtp

Type the following command under Debian / Ubuntu Linux: you could use yum under fedora.

 # apt-get update && apt-get install ssmtp

Configure gmail as a smarthost

Open /etc/ssmtp/ssmtp.conf, enter:

 # vi /etc/ssmtp/ssmtp.conf

Update file with the following to the end:

AuthUser=yourname@gmail.com
AuthPass=Your-Gmail-Password
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

Removing any old mail agents

Disable any other mail agents you have installed sendmail or postfix are most common, if you are using them:

To find out if they are installed type:

 # dpkg -l |grep mail
 # dpkg -l |grep post

If none are found skip this section and test your send mail.

Now stop the mail deamon if one was found:

 # service sendmail stop
 # service postfix stop

I like to use chkconfig or sysvconfig under debian so you may need to use apt-get install for these packages:

chkconfig is from my fedora and redhat days it is a cmd line program

sysvconfig is similar to ntsysv under redhat fedora again but it is in a tui or text user interface.

NOTE: If you must use a gui then install BootUpManager aka "apt -get install bum"

 # apt-get update && apt-get install checkconfig
 # chkconfig sendmail off

This removes the link to sendmail (note you won't need to do this if it was not installed previously)

 # rm /usr/sbin/sendmail

In debian type

 # ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

For other linux you may need to use:

 # ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

Send a TEST Mail

Now, you can use mail / mailx command to send email messages. You can also write a shell script to backup your files and email to somewhere else (see below). You can test settings using following syntax:

 # echo "This is a test" | mail -s "Test" me@gmail.com

NOTE: If the mail command is not found then install mailx as follows, and substitute mail for mailx in the test:

 # apt-get install mailx

Told you it was quick and easy :)

 # cp /boot/grub/menu.lst /boot/grub/menu/lst.20090729

There are times when you want to be able to start, stop, restart, reload and even permantly stop  services from running.

I always run through my system services and ensure I have turned off all the services I do not wish to be running, this serves several good reasons:

1) Reduce's the amount of memory used.
2 Can make an increase in system performance.
3) Why run a service you don't need, that could be a security risk.
4) PC will boot faster.

How do I manage my services?

There are many ways to manage services on linux.

The services that start reside in the init.d and rc?.d folders in /etc.

To start and stop a service for example networking you would use:

 # sudo apt-get install pptp-linux
 # sudo /etc/init.d/networking stop
 # sudo /etc/init.d/networking start

Redhat uses these locations to start and stop services but also offers a shell command that can mange these services so they stay on or off permanently.

chkconfig - This command alows you to see all the services in a list and which of them are on or off in any runlevel.

NOTE:  A run level is the level the system is operating at this list is a guide to the levels not necessarily the setup that your linux uses.

1 - Single user mode
2 - Not used
3 - Full system no GUI
4 - Not used
5 - Full system with GUI

To find out what your default runlevel is you can look at the /etc/inittab file.

Using chkconfig

To see which services are configured as system services use:

 # sudo chkconfig --list

To turn off a service use:

 # sudo chkconfig --levels 345 sshd off

NTSYSV

Redhat also provides a command called ntsyv.

ntsysv - This is a text user interface that function as the above command.

It can be used to configure the running runlevel as follows:

 # sudo ntsysv

or for other runlevels use:

 # sudo ntsysv --level 345

What if I'm running Crunchbang.

In crunchbang these utilities are not installed, you will need to install them yourself if you wish to configure you services manually.

Use the following commands to install the above commands.

 # sudo apt-get install chkconfig

crunchbang does not have ntsysv but it does have a similar command called sysvconf.

 # sudo apt-get install sysvconf

I need a GUI not command line

If you really need that gui tool then use the humorously named BootUpManager aka BUM

 # apt-get install bum

This tool allows you to manage all your services as above but in a graphical way.

Remember when playing with services you need to be root, use sudo in front of all the commands before running them.

There are many posts on the web about installing firefox 3.5, I have tried several methods some failed and one worked but did not install as expected so I ended up with 2 versions, this guide will get you a working version easily.

To install the latest version of firefox (3.5 at time of writting)  copy and paste the following at the end of:
/etc/apt/sources.list

Use vi or gedit to edit the file which ever you prefer.

vi /etc/apt/sources.list

Copy and paste the 2 lines below to the end of the file.

deb http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu jaunty main

Then add the Launchpad PPA GPG key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 247510BE

Install Firefox

sudo apt-get update && sudo apt-get install firefox-3.5

Once Firefox has been installed it will automaticly update when a new version is available in the mozilla repo.'

To manually do this run:

sudo apt-get update && sudo apt-get upgrade

Fix old Firefox link

After I had done this I noticed firefox 3.0 was still opening as the default browser.

To fix this I removed the current firefox link and replaced it with a new one as follows.

sudo rm /usr/bin/firefox

Add the new link

sudo ln -s /usr/bin/firefox /usr/bin/firefox-3.5

Remove old Firefox versions

Note: when you type firefox and tab it out you may notice other versions installed.

To remove these after you have tested 3.5 works with your profile use the following to list the installed ones first.

dpkg -l | grep firefox

Then remove the old versions as below:

sudo apt-get remove firefox-3.0

I did notice a few addons failed to work with 3.5 but the majority did, some just had to be reinstalled again such as the dictionary.

Hopefully all will be good :)

I thought I would share another of my trial and errors to manage and play Radio1 on my PC.

Why not just tune in on the radio I hear you say well, I no longer live in the UK, but miss Radio 1 so much I had to find a way to listen to it from the other side of the world.
I have never been a huge fan of mplayer, not sure why maybe it's because everyone raves about it so much, so I tended to use vlc instead, but vlc is a gui application and I am trying so hard to use command line when I can I just had to figure it out, I realised shortly that perhaps mplayer is pretty good, after all I now use it everyday to listen to the Radio.

Biggest problem is Radio1 insist on playing the music through the iplayer using flash this not not good for us on linux, after many hours of googling I discovered the best kept secret of where to find the Radio1 streams in ram format, and best bit is mplayer does a great job at playing them.

Getting Radio on your computer

First off make sure you have mplayer installed. If not use:

# apt-get install mplayer 

or use synaptic what ever floats your boat. :)

Next go to this site and find the stream you wish to listen too.
iplayerconvertor

Find the program you would like to listen too such as Radio 1 Chart Show, 26/07/2009
On the right is the link to the stream it's called something like b00lsltb, you need to copy or make a note of the url and then substitute for following command:

# mplayer "-playlist" http://www.iplayerconverter.co.uk/pid/b00lsltb/stream.aspx

mplayer will start to buffer the stream and by magic it will start to play.
To kill the stream use ctrl + c

You may wish that the stream runs constantly in the background, in that case run it as,

# nohup mplayer "-playlist" http://www.iplayerconverter.co.uk/pid/b00lsltb/stream.aspx &

Keep an eye on the nohup.out file in your current dir as it can grow large if left for a long time.

If you want to listen to Radio1 LIVE then use the following:

# mplayer "-playlist" http://www.bbc.co.uk/radio1/realaudio/media/r1live.ram

Recording the stream

To record the Radio stream use the following command it will start the stream and save it, you will need to convert it to mp3 if you then want it on your mp3 player.

mplayer -dumpstream "-playlist" http://www.bbc.co.uk/radio1/realaudio/media/r1live.ram -dumpfile Radio1.dump -vc dummy -vo null

Controlling the volume

I found I had no way to control the volume so I used a package called aumix.

# apt-get install aumix

This program allows you to change the volume by a command line interface and the cursor keys it's nice small and does the job.I will be trying to get some other method to control the volume using hotkeys but at this time the above method works.

Powered by WordPress Web Design by SRS Solutions © 2010 Paul’s Linux Blog Design by SRS Solutions