Archive for the ‘Ubuntu’ Category

How to create a PPPoE Server on Ubuntu?

March 30, 2011 10 comments

For one reason or another, I needed to setup a PPPoE Server on my Ubuntu machine. Unfortunately almost all the guides found were talking about setting a PPPoE client connected to a PPPoE Server. So I spend a few days testing and trying out different configurations, until I finally found how to set it up from scratch. The below instructions will look similar to the guide I referenced, but there are some extra steps to ensure that your connection will be able to access Internet properly.

Step #1: Topology Setup

First of all, the topology needs to be setup as followed:
PC --- PPPoE Server (Ubuntu) --- Internet
You can add your typical cable modem and/or router into the mix. The main issue here is to ensure that your PPPoE Server can access the Internet without any problems. To verify this, just do a quick ping test to or
> ping

PING ( 56*84) bytes of data.
64 bytes from ( icmp_req=1 ttl=52 time=36.9 ms
64 bytes from ( icmp_req=2 ttl=52 time=37.5 ms
64 bytes from ( icmp_req=3 ttl=52 time=34.3 ms
64 bytes from ( icmp_req=4 ttl=52 time=37.6 ms
-- ping statistics ---
4 packets transmitted, 4 received, 0% packet loss

If you cannot access this, check your interface. Most likely something is misconfigured there. There are several guides on how to enable your interface properly:
Network Configuration

Step #2: Install PPP and RP-PPPoE

You will need to install these components to get the PPPoE Server working. The first one is simple: just grab the ppp package from Ubuntu:
> sudo apt-get install ppp
The second package (rp-pppoe) requires you to build it on your own. Start by grabbing the package from this website (Roaring Penguin)
> wget
> tar -zxf rp-pppoe-3.10.tar.gz
> cd rp-pppoe-3.10/src
> ./configure
> make
> sudo make install


Step #3: Setup PPPoE Settings

Several files need to be created before we can start PPPoE Server. First, modify the /etc/ppp/pppoe-server-options and change it to the following:

# PPP options for the PPPoE Server
lcp-echo-interval 10
lcp-echo-failure 2

Next, add a username into the correct secrets file. Since we’re using require-chap, we will add it into /etc/ppp/chap-secrets. The syntax is simple: follow the example below to add a user (alice) with a simple password (1234).

# Secrets for authentication using CHAP
# client              server   secret                 IP addresses
"alice"               *        "1234"       

One note: make sure that the file has the correct permissions. Sometimes the PPPoE Server won’t start if the file isn’t restricted enough. A simple chmod command will do here:
> sudo chmod 600 /etc/ppp/chap-secrets
Last of all, setup the IP addresses to lease for the PPPoE Server. We’re giving IP addresses to


Step #4: Set PPPoE Scripts

We are ready to start PPPoE Server. Several things to worry about: the firewall needs to be set properly so that the PPPoE Server will be able to transfer traffic from one interface to the other, and IP forwarding needs to be enabled. Since these options will have to set every time Ubuntu reboots, they’re part of the start PPPoE script. It’s placed under /etc/ppp/start_pppoe.

# Simple script that starts PPPoE Server

# Enable IP Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Start PPPoE Server
pppoe-server -C isp -L -p /etc/ppp/ipaddress_pool -I eth1 -m 1412

# Set Firewall rules
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

The -m option for pppoe-server is needed so that the packets don’t go beyond MTU size after the PPPoE header is attached.

For complete purposes, below is a stop script to nicely tear down the PPPoE Server and revert any changes.

# Simple script that stops PPPoE Server

# Disable IP Forwarding
echo 0 > /proc/sys/net/ipv4/ip_forward

# Kill PPPoE Server
killall pppoe-server
killall pppd

# Flush the IPtable rules.
iptables -t nat -F POSTROUTING


Step #5: Automatically start/stop PPPoE Server

All we have to do is add them into the /etc/network/interfaces so that once the computer boots and detects the interface is connected, it’ll boot up the PPPoE Server. The PPPoE Server resides in eth1 in this example below:

auto eth1
iface eth1 inet manual
post-up /etc/ppp/pppoe_start
post-down /etc/ppp/pppoe_stop

That’s it! Once that’s completed, then the PPPoE Server will boot up automatically and start handling traffic.


Usually, there’s always some sort of issue getting the PPPoE Server working. I found that using wireshark makes it easier to debug the situation. However, usually the interface (eth1) isn’t up for wireshark to sniff. Make the modifications below to bring up the interface without assigning an IP address to it:


auto eth1
iface eth1 inet manual
up ifconfig $IFACE up
post-up /etc/ppp/pppoe_start
post-down /etc/ppp/pppoe_stop
down ifconfig $IFACE down

That should make it easier to debug.


How to do it yourself: PPPoE Server

Categories: Ubuntu

How do you install/mount a new drive in Ubuntu?

September 1, 2009 Leave a comment

These instructions focuses on Ubuntu, but it maybe possible to work on other distributions.

1. Physically install the drive into the machine (internally/externally).

Once this is done, use the following command:

# Scan the hardware, displays only disk class.
> sudo lshw -C disk

This will produce quite a few entries. Focus only on the ‘*-disk’ entries below to find the correct hardware (Note: only *-disk, not *-disk:0 or *-disk:1).

 description: ATA Disk
 product: WDC WD2500JB-00G
 vendor: Western Digital
 physical id: 0
 bus info: scsi@0:0.0.0
 logical name: /dev/sda
 version: 08.0
 serial: WD-WCAL77000695
 size: 232GiB (250GB)
 capabilities: partitioned partitioned:dos
 configuration: ansiversion=5 signature=7b56ae05

After verifying that this is the correct disk (in this example, it’s the WD 250GB IDE disk), the item of interest is the logical name (e.g. /dev/sda).

2. Setup partitions

If there is no need to setup partitions/format the disk, skip the step #4.

Fdisk is the proper tool to create partitions on the disk. Type the following command, replacing the example with the correct logical name:

# Ready to format the disk
> sudo fdisk /dev/sda

This will bring up a menu with several options:

Command (m for help): m
Command action
 a   toggle a bootable flag
 b   edit bsd disklabel
 c   toggle the dos compatibility flag
 d   delete a partition
 l   list known partition types
 m   print this menu
 n   add a new partition
 o   create a new empty DOS partition table
 p   print the partition table
 q   quit without saving changes
 s   create a new empty Sun disklabel
 t   change a partition's system id
 u   change display/entry units
 v   verify the partition table
 w   write table to disk and exit
 x   extra functionality (experts only)

To create a new partition, press ‘n’. If you want the format the whole thing, it’s probably better to type ‘o’ first to erase the whole partition table.

Once n is selected, it’ll ask you for primary or extended partition. There can only be 4 partitions in a disk; this is a hardware limitation. Extended partitions is a workaround since through one extended partition multiple partitions can be created. For simplicity sake, create only one partition here (select p):

Command action
e   extended
p   primary partition (1-4)
> p

Follow through with the instruction, and select 1.

Partition number (1-4): 1

Now comes the cylinder information. This determines how big the disk should be. For simplicity, select the default values (it will try to choose the largest size possible)

First cylinder (1-30401, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401):
Using default value 30401

The partition table is now created. To view the newly created partition, type ‘p’

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x24b47c92

 Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       30401   244196001   83  Linux

Type ‘w’ to save the settings. (q to quit without saving changes)

The partition table has been altered!

3. Format disk

If there is no need for formatting the disk, skip to step #4.

‘mkfs’ is the command used for formatting. It is possible to choose a specific filesystem (ext2, ntfs, fat32, etc.) when formatting. For Ubuntu, ext3/2 is probably the best, though ntfs should be better if the disk shares with Windows.

# Formats the disk (mkfs -t <filesystem> <partition>)
> sudo mkfs -t ext3 /dev/sda1

4a. Mount the drive (manually)

The simpliest way to mount the drive is to use the ‘mount’ command:

# Mount drive (mount <partition> <mount folder>)
> sudo mount /dev/sda1 /backup

When done, unmount the drive using ‘umount’ command:

# Unmount the drive
> sudo umount /backup

Note: /backup needs to exist for the mount to work; otherwise, it will complain.

4b. Mount the drive (bootup)

Most likely, the manual option is useless for almost all situations, especially internal hard drives. Another method is to mount it during bootup time. For that, /etc/fstab needs to be editted. Ubuntu uses UUID instead of logical names to mount the drives (though logical names are certainly supported). This is slightly better, since it is possible for logical names to associate to different hardware if the system’s hardware changes. UUID sticks to its hardware and does not change.

To determine the UUID of a drive, type the following command:

# Find the UUID of the WD disk.
> sudo vol_id -u /dev/sda1

Now, add that entry into the /etc/fstab file:

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sdc1
UUID=58a8346d-471a-4751-8fea-7456234bcdac /       ext3 defaults 0 1
# Backup media (IDE disk)
UUID=6486a213-45ad-2aa3-5c23-0d712a3465ds /backup ext3 defaults 0 1

When the system reboots, it should automatically mount the disk.

Note: the directory that the device is mounting to needs to exist for this to work. In this case, /backup had to be created manually first before it will mount. Otherwise, it will give an error and refuse to mount.

4c. Mount the drive (automatically)

The best way to mount a drive automatically other than bootup time is to still use /etc/fstab. If it’s a harddrive, the UUID method is still the best. However, each storage devices requires its UUID to be added into /etc/fstab, and this can become a tiresome hassle to do.

There are scripts to handle the auto-mounting (Ubuntu does a decent job if you brought the machine up to GUI level), but explaining it goes beyond the scope of this post.


Installing New HardDrive
Using UUID

Categories: Ubuntu

How to monitor CPU temperature through terminal prompt?

August 28, 2009 5 comments

This is an interesting problem when setting up an Ubuntu server. The room that temporary contains the server is not well air-conditioned and as such temperature is a major concern. However, since the machine is headless, it is a bit harder to figure out the CPU temperature without needlessly looking at the sensor all day. Below is instructions on how to setup the CPU monitor on the prompt so it becomes a bit easier to determine whether the computer is overheating.

1. Install/Setup lm-sensors

This is a simple process for in Ubuntu (and probably most distributions). The command to install them is:

# Install lm-sensors to the machine.
>sudo apt-get install lm-sensors

Next, run the command ‘sensors-detect’ and go ahead and say YES to all the options. This is needed in order to detect any hardware sensors on the machine. Reboot afterwards.

# Setup sensors so they register properly.
>sudo sensors-detect

Now, verify that lm-sensors is setup correctly by typing ‘sensors.’ There should be some information about CPU temp/fans/voltage.

# Display sensor information.
Adapter: SMBus I801 adapter at c400
V1.5:        +1.47 V  (min =  +0.00 V, max =  +3.32 V)
VCore:       +1.36 V  (min =  +0.00 V, max =  +2.99 V)
V3.3:        +3.39 V  (min =  +0.00 V, max =  +4.38 V)
V5:          +5.13 V  (min =  +0.00 V, max =  +6.64 V)
V12:        +12.31 V  (min =  +0.00 V, max = +15.94 V)
CPU_Fan:    2130 RPM  (min =    0 RPM)
fan2:          0 RPM  (min =    0 RPM)
fan3:          0 RPM  (min =    0 RPM)
fan4:       2712 RPM  (min =    0 RPM)
CPU Temp:    +40.0°C  (low  = -127.0°C, high = +127.0°C)
Board Temp:  +29.0°C  (low  = -127.0°C, high = +127.0°C)
Remote Temp: +29.0°C  (low  = -127.0°C, high = +127.0°C)
cpu0_vid:   +1.413 V

2. Write script to continually gather CPU temp.

This is a simple script that gets the CPU temperature out of the sensor data. It assumes that there is only one entry called ‘CPU Temp:’ Some systems may have more than one sensor that displays CPU Temp, so adjust the script accordingly.

#! /bin/bash
# Records the CPU temp and writes it to a temporary file.
while [ 1 ]; do
     sensors | grep "CPU Temp" | sed 's/.*:\s*+\(.*\)  .*(.*/\1/' >& \
sleep 5;

Not particularly fond with this hack script, but it works. Currently, it is set to scan the temperature every 5 seconds, though this can easily be adjusted from the sleep command. Five seconds should be sufficient enough to keep the temperature up-to-date without using too many CPU resources.

3. Tie the CPU temperature to the terminal prompt.

Since Ubuntu uses bash as the default shell, the below changes are for bash prompt. To determine what shell is running, use the follow commands:

# Find which shell is running right now.
>echo $0

For bash, it is simple by modifying the following environment variable PS1. Since Ubuntu has some default setting on terminal prompt, I tack the CPU monitor along with Ubuntu’s defaults. Different shells will have to use similar techniques to set the prompt.

# Default Ubuntu settings
# PS1=${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1='[`cat /tmp/.cpu_temp`] ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

Put this under ~/.bashrc so that everytime a terminal is created, it’ll run this command (for other shells, it’ll be a similar rc file such as cshrc, tschrc, etc).

4. Have the script start during bootup.

One more step to go: the script needs to run in the background for this to work. Just manually starting it through “./ &” will not survive if the machine needs a reboot.

First, move the above to /etc/cpu_temp/ It is possible to change it to another place, but make sure to edit the below script. Add the following code to the /etc/init.d/cpu_temp.


# Simple script to enable/disable CPU temperature monitor.

# Return 0, process already started.
# Return 1, start cpu_temp
        if [ -f $PIDFILE ]; then
                return 0
        $DAEMON &
        echo "$!" > $PIDFILE
        return 1

# Return 0, process not started.
# Return 1, kill process
        if [ ! -f $PIDFILE ]; then
                return 0
        kill -9 `cat $PIDFILE`
        rm $PIDFILE
        return 1

case "$1" in
        case "$?" in
                0) echo "$NAME already started." ;;
                1) echo "Started $NAME." ;;
        case "$?" in
                0) echo "$NAME has not started." ;;
                1) echo "Killed $NAME." ;;

        if [ ! -r "$PIDFILE" ]; then
                echo "$NAME is not running."
                exit 3
        if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
                echo "$NAME is running."
                exit 0
                echo "$NAME is not running but $PIDFILE exists."
                exit 1
        echo "Usage: $N {start|stop|status}" >&2
        exit 1

exit 0

(Note: I tried to make it as generic as possible so all distributions will work. This is why it isn’t using Ubuntu-specific commands).

Last of all, add it to the bootup script. The below command is specific debian-distributions:

# Add cpu_temp to startup sequence.
> sudo update-rc.d /etc/init.d/cpu_temp defaults

That should be it! When the computer reboots, it will automatically run the CPU temperature in prompt.

One final note: make sure that all the scripts are executable.

Categories: Ubuntu