Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, April 25, 2011

Using RPM to find large packages in Linux

Here's how to use RPM to find the largest packages on your Linux system:
rpm -qa --queryformat '%10{SIZE}\t%{NAME}\n' | sort -k1,1n

Wednesday, June 9, 2010

Limiting Network Bandwidth Using Linux

Just enter these two commands to establish a rate limit of 2kbps on eth0.

tc qdisc add dev eth0 root handle 1:0 netem delay 10ms
tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 2kbit buffer 1600 limit 3000

OR

More recently I found the following single command will effectively restrict bandwidth to 2kbps
tc qdisc add dev eth0 root tbf rate 2kbit latency 1ms burst 1540
or
tc qdisc add dev eth0 root tbf rate 15mbit latency 1ms burst 20m

Friday, January 30, 2009

Simulating Network Delay Using Linux

In a previous blog post I documented how to create a router using Linux:
http://purefinity.blogspot.com/2008/10/making-linux-router-or-gateway.html

Now that we have that setup, we can use it to emulate WAN latency using netem. If you're running a 2.6 kernel you should already have it installed.

Keep in mind that this only works for outbound traffic, so choose your network interface accordingly.

To add 100ms to all outbound traffic on eth0
tc qdisc add dev eth0 root netem delay 100ms

To check status
tc -s qdisc

To remove the delay from eth0
tc qdisc del dev eth0 root

You can also use netem to simulate packet loss, variable delay and rate control. For more information on netem:
http://www.linuxfoundation.org/en/Net:Netem

If you're looking for an easy to use tool to test throughput and latency that is more sophisticated than ping, I recommend QCheck. You can install it on two Windows machines and test between those two points, or install QCheck on a Windows machine and an Ixia Endpoint on a Linux machine. Both QCheck and the Endpoint were available for free at the time this article was written.
http://www.ixchariot.com/downloads.html

I would like to note that my first choice to emulate network latency was to use tcmon from the Windows resource kit, but I quickly found the tool to be poorly documented, unsupported on Windows Server 2003, and only provided rate control on Windows XP. It's sad when a command line tool for Linux is simpler and easier to use than a GUI tool from Microsoft.

Tuesday, December 23, 2008

Basic Linux find command syntax

# find . -name foo

Finds files in the current dir+subdir named foo

# find . -name \*foo

Finds files in the current dir+subdir ending in foo

Monday, November 3, 2008

Adding a Linux swap partition

I'm putting this howto in my blog to make it easier to find later when I need it again. I typically use it to resize swap partitions. I tested these instructions with RHEL 4.

To add a swap partition (assuming /dev/hdb2 is the swap partition you want to add):

  1. Turn off all the swap space on the hard drive with the swapoff command.

  2. Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:

    • At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.

    • At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.

    • At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.


      Warning

      Changes take place immediately; be careful when you type.

    • Exit parted by typing quit.

  3. Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:

    mkswap /dev/hdb2
  4. To enable the swap partition immediately, type the following command:

    swapon /dev/hdb2
  5. To enable it at boot time, edit /etc/fstab to include:

    /dev/hdb2               swap                    swap    defaults        0 0

    The next time the system boots, it will enable the new swap partition.

  6. After adding the new swap partition and enabling it, make sure it is enabled using the free command.

Friday, October 31, 2008

Making Linux a Router or Gateway

Here's an example of how to set up simple routing on a Linux box.

Setup:

A Linux box with two NICs
Two network switches
Two or more additional computers

1. Add this line to your /etc/sysctl.conf file and comment everything else out
net.ipv4.ip_forward = 1

2. Modify the following files in /etc/sysconfig/network-scripts

ifcfg-eth0
DEVICE=eth0
IPADDR=192.168.80.138
NETMASK=255.255.255.0
GATEWAY=192.168.80.1

ifcfg-eth1
DEVICE=eth1
IPADDR=192.168.49.132
NETMASK=255.255.255.0
GATEWAY=192.168.49.2

route-eth0
GATEWAY0=192.168.49.132
NETMASK0=255.255.255.0
ADDRESS0=192.168.49.0

route-eth1
GATEWAY0=192.168.80.138
NETMASK0=255.255.255.0
ADDRESS0=192.168.80.0

3. Setup your other machines so that their gateway is 192.168.49.132 or 192.168.80.138

Use the GUI in Windows or use the following command in Linux:
route add default gw 192.168.80.138


Test from windows client:
>ipconfig

Windows IP Configuration
IP Address. . . . . . . . . . . . : 192.168.80.142
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.80.138

>tracert 192.168.49.130

Tracing route to 192.168.49.130 over a maximum of 30 hops
1 1 ms <1 style="font-weight: bold;">

Tuesday, September 16, 2008

Setting the date in Linux

For handy reference I decided to post this tiny bit of syntax in my blog. This was tested in Redhat Linux. (The date command as part of coreutils)

date -s "09/16/2008 11:52:00"