Entries Tagged as 'Linux'

Record My Desktop

It’s actually an application named recordmydesktop, which can be installed by sudo apt-get install recordmydesktop.

There are various kinds of purpose to use, but for me, I would like to present or show some mock-up to other people. I made a simple file

#!/bin/bash
recordmydesktop -windowid $( xwininfo -frame | awk ‘/Window id:/ {print $4}’ )

After running this script, there is a cross cursor which allows you to select a window. As soon as the window is selected, the recording start. To end the recording, simply type Ctrl+C. After several lines of screen output, there is a .ogv file generated.

You can use Movie Player to view the file if you are using Linux. However, you can still view this file by using VLC, which can be installed to both Mac and Windows.

How to Calculate Memeory Usage

Normally we don’t calculate memory usage by ourselves. We can get percentage from system performance in Windows or System Monitor on GNOME. However, I am curious about how the percentage is calculated from back end.

We are all familiar with “top” or “htop” command in any Linux distribution. The memory usage is actually calculated from the raw data gotten from top command. The following screen shot is top running on my desktop.

As you can see that, I have 2G physical memory. I also have almost 4G swap memory which system allocated on hard disk for me. The physical memory is used 1769636K, which is actually divided to two parts. One parts is for all processes running on the system, the other part is for caching. We all know that Linux actively collect free physical memory to cache some instruction used by CPU. The idea behind caching is that it takes longer for your CPU to access data on the hard drive than it does to access data that is present in the main memory. So caching using the main memory effectively speeds up the system.

Therefore, we come up with two formula:

Cached Memory Usage = Cached Memory / Physical Total Memory

Program Memory Usage = (Used Physical Memory – Cached Memory ) / Physical Total Memory

The System Monitor on GNOME provide these two memory usage, which make us more clear about our desktop performance.

Terminator – Emacs-like Terminal

Since I am always working on Linux Terminal, I am looking forward some tools can be an Emacs-like environment. Recently, I noticed a tool named Terminator, which was written by Chris Jones on Jan 5 2008. Luckily I got this tool at the end of 2008, not so late. :)

It’s easy to install the tool by

sudo apt-get install terminator

Then, we may get menu by right click mouse. The menu includes “split vertically” and “split horizontally”.

We can split the panel horizontally.

Or, we can split sub panel vertically.

So, we don’t bother to arrange many terminal windows later on.

TCL Expect Script to Bring Lab Up

My Lab enviornment is running on a server with around 10 router-simulators. Without script, I have to login server by using SSH session first, then TELNET to dynagen session to interact with router simulator. This job is tedious. So, I came up with some script to automate my routing job.

First, we need a Tcl script for each connection.

#!/usr/bin/expect

spawn ssh root@10.2.111.198
expect “password:”
send “d7j3f8g8\n”
expect “root@common-server”
send “telnet 127.0.0.1 2000\n”
interact

There are two key parts. One is “expect “password:”. TCL Expect has a nice feature that you can send a password to interact with shell command. The other is “interact” command. Without it, we cannot interupt TCL session.

Then, we can put all start router-simulator script to a bash shell.

gnome-terminal -e ./open_router_sim.tcl

Simulate a Slow Link by Linux Bridge

To simulate the real world slow link network, sometimes network equipment is not enough. For example, LAN Switch can do rate-limit on each egress port, but it cannot allow packet forwarding delay, or, it cannot setup packet loss rate. The four major elements of QoS are: Bandwidth, Delay, Packet Loss and Jitter. So, in order to achieve the real situation, we can use Linux bridge plus traffic control (tc) features.

Setup Linux Bridge

Two NICs cannot be a bridge unless we install a bridge utility. “yum -y install bridge-utils” can be applied. Sorry I didn’t mention in Ubuntu distribution since I am always working on Fedora Core. Then, we need to plan which two NICs to be the member of the bridge. In my case, I use eth1 and eth2. So, make sure there is no ip on both of Ethernet cards first. Then, we need to type the following commands:

ifconfig eth0 0.0.0.0 up
ifconfig eth1 0.0.0.0 up
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
ifconfig br0 up

We can assign an IP address to br0, like we assign vlan interface IP address in LAN Switch.

ifconfig br0 192.168.50.50 netmask 255.255.255.0 gw 192.168.50.254

However, since there is no routing over the bridge. we can just leave it as pure bridge.

Brief Introduction of TC

Traffic Control (TC) is a tool that do egress traffic shaping on every port. The primitive purpose to create a module named shaper.o is to slow down interface. It didn’t measure traffic instead, it was only able to decrease interface speed by suing PWM (Pulse Width Modulation). For example, you can transfer power equal to 12V from 36V by switching supply off for 2ms then switch on for 1ms. PWM has one advantage that it didn’t require much cpu usage.

Then, the CBQ (Class Based Queue) is appeared. It can classify traffic but it works in the same way as PWM.

Then, the HTB (Hierarchy Token Bucket) is coming. It controls traffic per packet instead of time slots. It allows to implement very precise control in expense of higher CPU usage.

The detailed description is available in tc manual.

Create a Delay Network

To make a simple work, we don’t need to use classes. We only need to add delay to root. However, very important, each time we have to clear “queue discipline”.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root

Then, we setup a 500 mini second delay.

tc qdisc add dev eth1 root handle 1:0 netem delay 500msec
tc qdisc add dev eth2 root handle 1:0 netem delay 500msec

Create a Low Bandwidth Network

Still, I didn’t compose any fancy shell script, instead I just use only two lines to achieve a 128K link.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root
tc qdisc add dev eth2 root tbf rate 128kbit burst 1024kbit latency 50ms
tc qdisc add dev eth1 root tbf rate 128kbit burst 1024kbit latency 50ms

So far I only got this level. I saw quite a lot blogs and tutorials in the web, which have more complicated network.

Process States in Linux

To help me memorize, I list all process states for Linux, which is actually from UNIX.

  • R – runnable which means the process has done a context switch and has the kernel.
  • S – sleeping which means the process is waiting on I/O completion (blocked), a pipe, memory, etc.
  • T – process has been stopped – sent a SIGSTOP usually with ctrl/z
  • Z – zombie – a process that has a process image in memory but no context, ie., not swappable.
  • O – means the process is the one that currenlty has the cpu

RADIUS Server on Fedora

RADIUS Server is commonly used in network AAA. It provides authentication by UDP port 1812, accounting by UDP port 1813 and proxy by UDP 1814. To setup RADIUS Server on Fedora is simply.

First, we need install Free Radius to Fedora

sudo yum -y install freeradius

Then, we need to configure client.conf file

vi /etc/raddb/client.conf

client 192.168.50.60/24 {
secret = 1a2b3c4d
shortname = freeradius
}

Then, we need assign user name and password

vi /etc/raddb/users

“John Smith” ClearText-Password := “cowsgomoon”

Later on, we can start radius deamon by -X option for debugging purpose.

radiusd -X

Of course, you can start radius server by using service command

service radiusd start

FTP Active Mode vs. Passive Mode

Since we need to deal with firewall between FTP clients and server, the following diagram shows that two modes of FTP. So, we can design more accuracy firewall policy by applying different modes.

FTP Active vs. Passive

The following is quoted the pros and cons:

Active FTP is beneficial to the FTP server admin, but detrimental to the client side admin. The FTP server attempts to make connections to random high ports on the client, which would almost certainly be blocked by a firewall on the client side. Passive FTP is beneficial to the client, but detrimental to the FTP server admin. The client will make both connections to the server, but one of them will be to a random high port, which would almost certainly be blocked by a firewall on the server side.

vsftpd put “553 Could not create file” solution

I set up a new FTP server by using vsftpd. I observed that I could get file but failed to upload file. After investigation, I found out there are three points I should concern about.

First, write_enable=YES in /etc/vsftpd/vsftpd.conf

Second, system-config-firewall to enable command port 21 and data port 20.

Last, system-config-selinux to set Boolean ftp_home_dir to 1

After service vsftpd restart, I can get and put file in my home directory.

tftpboot directory changed in FC9

One change in FC9 is tftpboot directory. In the previous release, after installed tftp-server, it created /tftpboot directory. In FC9, the directory change to /var/lib/tftpboot/. The reason I guess is to keep root directory more clear.