Category Archives: linux

Moving up levels in directory tree easily

In Linux if you are in a directory level and want to jump for example 2-3 folders in one step, as far as I know there is no built-in command. If there is one, I would be very happy to know. There is a very nice command in Juniper’s JUNOS CLI which is “up” which moves you up in the configuration hierarchy. I wanted to do the same via a bash script like below;

After giving execution permission to the file, I put it under /bin folder BUT the point is I can’t simply run it like;

and expect to move 4 directory levels up. I must run it inside the current shell I am in without forking any other process and here is the handy command “.” comes in. If I am in the following directory for example;

running the command the following way;

will move us up to the /usr/libexec/gcc folder. The argument 2 here stands for in which directory we want to be above our working directory.

Although there may be a built-in bash command which already does this, I think it is good to see how “.” command can be this handy!

Hard link and soft link?

I would like to give some examples to describe practical meaning of hard links,soft links and cache in memory in a linux system. I will start creating two ramdisk partitions:

Now lets look at the free memory usage of my PC;

According to this output, my cache data is 658MB. As you might know, cached amount isn’t actually used by processes actively but kernel keeps them in memory as they might be referenced. Instead of keeping them in the secondary storage (e.g hard disk), as long as memory is available, kernel caches them in the memory. Now we will increase this number sharply.

Continue reading

How to use ulimit utility to restrict users?

You can use ulimit command to prevent users from abusing system resources. Below I will touch two of the options;

Continue reading

Reverse SSH connection

Imagine that you have a host (named A) somewhere that has no publicly reachable IP address but you would like to connect it via SSH. If this host A can reach outside, then you can reverse SSH into it. Here is the scenario;

Host A (192.168.1.1) —  INTERNET —- Host C (10.10.10.1)

On host A, run the following command;

Once you authenticate yourself, this opens a tunnel from Host C to Host A but
from port 2025 to 22. If you want to connect from Host C to Host B back you can simply run;

Can you see that as if you are connecting to localhost? but indeed connection is tunneled towards the Host A

Traffic shaping with TC in Linux

Traffic shaping is a method to control the rate at which packets are sent and Linux does a pretty good job in doing this. I am currently developing a shell-like interface for TC in python and the following script is the framework for the application. I will update this post as I have more experience with TC. Here is the script with descriptions for which I also used tc manual;

#tc qdisc add dev eth1 root handle 1:0 htb

#tc class add dev eth1 parent 1: classid 1:1 htb rate 2mbit ceil 2mbit

Classful qdiscs contain classes which allows us to set rate limits. Class 1:1 is the root class here

Continue reading

Generic/TCP Segmentation Offload and Wireshark

Before reading this post you may have a look at the link http://en.wikipedia.org/wiki/Large_segment_offload which is the main motive of this post. While I was trying to troubleshoot some TCP communication, I wanted to investigate something which I have ignored so far. Maybe one screenshot is more than many words;

Have a look at total length field of this IP packet. It is 2948 on a link whose MTU is 1500. I asked myself how could that happen? A little search showed that it is because of segmentation offload in the network adapter. Normally TCP segmentation is handled by the host CPU with which wireshark displays reasonable lengths. However if segmentation is handed over to network adapter, host machine instead of doing segmentation itself, it sends chunk of segment to network adapter for segmentation at which wireshark captures this transmission and displays a header length which you don’t expect. TSO is definitely an improvement on host resource usage but for demonstration and testing it really makes things difficult. We can display current setting for tso/gso via;

root@rtoo:~# ethtool -k eth0

We can turn this feature off via;

After turning it off, if you take another capture, wireshark will display what you expect indeed.If your tcp-segmentation-offload is also on, turn it off via

For some more info on TSO/GSO check the links below:
GSO: http://www.linuxfoundation.org/collaborate/workgroups/networking/gso
TSO : http://www.linuxfoundation.org/collaborate/workgroups/networking/tso