Tuesday, September 28, 2010

how to turn on your machine remotely (wake on lan)

This feature should be supported by both your motherboard and network adapter.

First of all, search the BIOS for the appropriate entry and enable it. It should look like this "PCI wake up".

Then, using ethtool (included in the ethtool package), you should determine if wol is supported by the network adapter and if it is enabled:

myrina:~# ethtool eth0 | grep Wake
Supports Wake-on: g
Wake-on: d

The output means that wake on is supported (g) but disabled (d). For more detailed information about the ethtool abbreviations take a look at the man page.

In order to enable this feature run:

# ethtool -s eth0 wol g

This setting will be reset once the machine gets restarted. Thus, it should be run on startup by a appropriate script.

In order to wake up the machine remotely the MAC address is required. The MAC address can be retrieved using the #ifconfig eth0 command.

On the client-side, a utility such as wakeonlan is required in order to send magic packets to the target machine. The syntax is very simple: $wakeonlan MACADDRESS

If you want to turn on a machine via the internet, you should use something like this

$wakeonlan -p (port) -i (external ip address) (macaddress)

I haven't tried to wake my machine via the internet but that should work. The router should be configured to forward traffic that reaches the port specifed in the command above. The default port for magic packets is 9.

set up PPTP VPN server (debian linux)

On the server side:
  • First of all, you need to install the PPTP package (apt-get install pptpd).
  • Then, you need to configure PPTP. In the /etc/pptpd.conf file add the following lines:
localip 192.168.1.2
remoteip 192.168.1.20-25

The localip address is the ip of the machine that pptpd runs on and the remoteip is the range of ips that will be used by the clients.

  • The DNS server should be added in the /etc/ppp/pptpd-options file. The entry should look like this:
ms-dns 194.219.227.2
ms-dns 193.92.150.3
(use your isp's dns servers)


  • The vpn users should be declared in /etc/ppp/chap-secrets
# client server secret IP addresses
username pptpd password *

  • In order to avoid the error described in this bug report, in /etc/pptpd.conf comment the logwtmp line
  • Ip forwarding needs to be enabled in /etc/sysctl.conf ; uncomment the net.ipv4.ip_forward=1 line.
  • Restart pptpd (/etc/init.d/pptpd restart) and networking (/etc/init.d/networking restart)
  • You should use a service like dyndns to get a hostname (unless you have a static ip anyway) and configure your router to forward port 1723 traffic to the server machine.
On the client side:

  • Install the following packages: pptp-linux, network-manager-pptp , network-manager-pptp-gnome
  • Open "edit connections" on network manager.
  • On the VPN tab add a new PPTP connection.
  • The gateway should be set to the external ip of the server machine (e.g. dyndns host account). The username and the password should be set as in the /etc/ppp/chap-secrets file
  • In the Advanced options, enable the "use point-to-point encryption (MPPE)" option and MSCHAP and MSCHAP2 authentication methods.



















  • You should be able to connect now.

Saturday, August 7, 2010

Debian: How to apt-pinning

I am currently using debian testing but in some cases I needed to install newer versions of some packages which were only available in unstable (e.g. nvidia's driver). Therefore, I had to set up apt-pinning.

First of all you need to add the unstable repos in the /etc/apt/sources.list

deb http://ftp.debian.org/debian/ unstable main contrib non-free

Then edit /etc/apt/apt.conf and add the following line:

APT::Default-Release "testing";

Edit the /etc/apt/preferences file and add:

Package: *
Pin: release a=testing
Pin-Priority: 700

Package: *
Pin: release a=unstable
Pin-Priority: 500

For more info about the preferences take a look at apt_preferences man page.

Finally, run apt-get update

You can now install packages from unstable using the -t unstable option. For example,

apt-get install -t unstable iceweasel

You must be very careful while doing this and watch out for the dependencies that may be installed in order to avoid breaking packages already installed from testing. It may be useful to run apt-get install -t unstable -s iceweasel which just simulates the installation of the package without affecting the system to review any dependencies and upgrades.


Debian: How to mount a windows samba share

A couple of days ago I was trying to use file space that my university provides on my laptop running debian linux. This guide does not only apply for the so-called "H: drive" of Imperial College but for all windows shares.

First of all, you need to install the following packages: smb-client and smbfs. Create a directory in your home directory that will be used for mounting the samba share. (mkdir ~/samba)

Then edit the /etc/fstab file by adding a row like this:

serverURL mountPoint smbfs username=XXXX,user,noauto 0 0

The username=XXXX part is for logging in to the remote sever. If no login is requred then it can be ommited. The user option allows for mounting the directoy without root privileges and noauto specifies that it won't be mounted automatically during startup.
The line should look like this:

//server/myDirectory/ /home/antonis/samba smbfs username=XXX,user,noauto 0 0

Then you can mount the directory using mount ~/samba. If a password is required you will prompted to type it. Once done unmount it by: umount ~/samba

Note: to access you Imperial H drive you should use the VPN service.

Thursday, July 8, 2010

Find duplicate entries in oracle database

In order to find column values that occur more than once in a table:

SELECT column, COUNT(column)
FROM table
GROUP BY column
HAVING COUNT(column) > 1

(where column is the field of interest).

Wednesday, June 30, 2010

Imperial College printing from linux laptop

Well, this does not work perfectly for me and some problems may come up (e.g. when printing multiple pdf pages in a single page) but generally it works well. Strangely enough, there are instrunctions for this on the DoC's CSG old site but I couldn't find them on the new one. The old site's link is http://www.doc.ic.ac.uk/csg-old/ . click on the lab printers section and follow the instructions on the bottom of the screen. Basically, all you need to do is add the following lines at /etc/cups/printers.conf (replace username with your IC username): (https://www.doc.ic.ac.uk/csg-old/labprinters/printers.conf)

Restart cups and that should do the trick. The site suggests to also install the PPD file, you can do that, but as I metioned, I still got issues from time to time.
(tested on debian testing)

How to: Debian and nokia smartphone as modem

The following has been tested for Debian Testing (Squeeze), Nokia E51 and usb connection.

You will need to install wvdial (#apt-get instal wvdial). Then add the following lines to /etc/wvdial.conf (create it if it does not already exist)

[Dialer vfuk]
Modem = /dev/ttyACM0
Modem Type = USB Modem
Baud = 460800
New PPPD = yes
Password = web
Username = pass
Phone = *99#
Stupid Mode = 1
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","Internet"

Note that you should adjust the password, username and access point ("Internet") (under Init3) to comply with your mobile network settings. The settings above are for Vodafone UK. For example, for Cosmote Greece the configuration file should look like this:

[Dialer cote]
Modem = /dev/ttyACM0
Modem Type = USB Modem
Baud = 460800
New PPPD = yes
Password = user
Username = pass
Phone = *99#
Stupid Mode = 1
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","Internet"

Before trying to connect to the internet, stop any network connection manager (e.g. wicd, #/etc/init.d/wicd stop) and disable the rest of the network interfaces (e.g. ifconfig wlan0 down). This is to ensure that all the network traffic will be routed via the mobile phone.

Finally in order to connect run: wvdial vfuk (replace vfuk with the name of the dialer specified in the configuration file). Confirm that this connection is actually used by viewing the routing table information (route -n).