Building Linux RPM Package from Source Code

Sometimes for some reasons you might not be able to find RPM package that you needed on the Internet. In that case you have to build the binary by your own. Certainly an easy way is just build the binary and install it, but a better way is to build a RPM package so that it is distributable and can be under Linux package management. So below is the steps for building RPM package from source code, referencing from with some changes.

# Step: 1
# Install rpmbuild

yum install rpm-build

# Step: 2
# Create rpmbuild folders in your home directory

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Step: 3
# Download the source file

wget -P ~/rpmbuild/SOURCES ""
tar -xzvf ~/rpmbuild/SOURCES/git- -C /tmp

# Step: 4
# Prepare the .spec file, and made any necessary changes
# If the source file did not include .spec file, you have to prepare one by your own
ls -l /tmp/git-*.spec
cp -p /tmp/git- ~/rpmbuild/SPECS
vim ~/rpmbuild/SPECS/git.spec

# Step: 5
# Build rpm
# If you get any errors during build, it is usually because of dependencies. Simply
# install the dependencies with `yum install [dependency]` and run rpmbuild again.

rpmbuild -ba --define "_topdir %(echo $HOME)/rpmbuild" ~/rpmbuild/SPECS/git.spec

You can also find the above code at

Open Video File using omxplayer on Raspberry Pi without Terminal

I was trying to make Raspberry Pi running Raspbian OS to turn it as a media player with can play video without using a keyboard so that it is portable for a trip.

The only software that allow video playback on Raspbian is omxplayer. It is a command line tool and therefore need a keyboard to start playing video. Searched on the Internet and found that it is possible create an application, allowing you to play the video via right clicking the video file and choosing the application to open. However most of scripts included in the Internet are not working on my Raspbian. After a long research I finally figured out a working one.

Later on, I actually found that there other OS such as Raspbmc, OpenELEC which is actually designed turn Raspberry Pi to be a media center and I have another Raspberry Pi for that now. Anyway below are the steps to create applications for video playback on the LXDE desktop environment on Raspbian OS:

  1. Create a file with the following content at /usr/share/applications/omxplayer-hdmi.desktop. This will allow you to hear the sound output to HDMI.
    [Desktop Entry]
    Name=OMXPlayer (HDMI)
    Exec=lxterminal --command "sudo omxplayer -r -o hdmi %f"
  2. Create a file with the following content at /usr/share/applications/omxplayer-local.desktop. This will allow you to hear the sound output to the 3.5mm audio jack.
    [Desktop Entry]
    Name=OMXPlayer (3.5mm)
    Exec=lxterminal --command "sudo omxplayer -r -o local %f"

Workaround Inability in NAT Loopback on DD-WRT r15760 or above

Recently I found that my router running DD-WRT is not able to handle NAT loopback (Accessing router’s public IP from internal network). After searching through the Internet, I found this post mentioned that it is a problem in DD-WRT since revision r15760. It is stated that the problem will not be fixed. As a user, we can only apply workaround to the issue. Here are the steps:

  1. Make sure your DD-WRT version is r15760 or newer
  2. Navigate to your router administrator page
  3. Go to the Administrator section, Commands section
  4. In the Commands text box, input the following command:
    insmod ipt_mark
    insmod xt_mark
    iptables -t mangle -A PREROUTING -i ! `get_wanface` -d `nvram get wan_ipaddr` -j MARK --set-mark 0xd001
    iptables -t nat -A POSTROUTING -m mark --mark 0xd001 -j MASQUERADE
  5. Press the Save Firewall button. You should see the following screen:
    DDWRT NAT Loopback
  6. Reboot your router, the NAT loopback should be function now

Configure RedHat Linux as Router

In my case, because a normal router doesn’t come with support of 802.1x security and I only have 1 IP address, I got to set up a Red Hat Linux server as a router with perform NAT and packet forwarding function.


  1. Suppose your server is using static IP, your network interface is eth0, and there is another PC with IP address connected to the server directly
  2. Enable IPv4 packet forwarding on Linux
    echo 1 > /proc/sys/net/ipv4/ip_forward
  3. Enable SNAT
    # Example
    iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source
  4. (Optional) Enable DNAT (port fowarding) for services such as web server
    # Example
    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to


If you want to save the rules in iptables or restore them after edit, you can use these commands!

Edit 2013-05-08: The previous command were incorrect and has been updated.
Edit 2014-11-20: Added a command for persistent change on RedHat 5

# Save iptables rules to a file
iptables-save > /tmp/iptables.txt

# Restore iptables rules from a file
iptables-restore < /tmp/iptables.txt

# (For RedHat 5) Save the iptables rules so that changes is persistent (across reboot)
service iptables save


Edit 2014-11-20: I have more IP addresses now after moving to new office. So today I rollback the configuration.

  1. Edit the file at /etc/sysctl.conf and locate the following line:
    net.ipv4.ip_forward = 1

    Edit it to read as follows:

    net.ipv4.ip_forward = 0
  2. As the root user, run the following command to enable the change to the sysctl.conf file:
    sysctl -p /etc/sysctl.conf
  3. You can then verify the result by the following command, which should give you zero as output:
    cat /proc/sys/net/ipv4/ip_forward

Adding Red Hat Enterprise Linux 6.2 Installation Disc as YUM Package Repository

Notice: This guide is for Red Hat Enterprise Linux 6.2 only. It may not work on other versions of Red Hat.

There are times that after you have installed the OS and found that you have forgotten to install some of the packages during the initial set up. But for some reasons your only source of packages is only the installation disc you have. Here is the way to make the packages on the disc available as yum package repository.

Just create a new file under the directory /etc/yum.repos.d with any file name ended with extension .repo. For example:


and have the file configured to point to the installation disc. For example:

name=Red Hat Enterprise Linux Installation Disc
baseurl="file:///media/RHEL_6.2 x86_64 Disc 1"

Be sure to change the /media/RHEL_6.2 x86_64 Disc 1 with the path pointing to your installation disc in case it is different from the one here!

I was preparing to set up another new servers running RHEL6 with channel bonding and got a chance to retouch what I have wrote.

Hidden Base

Notice: The article is for Red Hat Enterprise Linux (RHEL) 5.7 and 6.2. It may also suitable for other newer version of Red Hat.

This article is inspired by this article.


  • You have a fresh installed server running RHEL
  • The server has two Ethernet interface eth0 and eth1
  • The server has no bond device set up before
  • You want to configure eth0 and eth1 to be load balancing or active-standby
  • You will use static IP for the network connection

Step 1: Add a bond device configuration file

2012-06-11 Edit 1: Till now I am still wondering if MACADDR or HWADDR should be specified in the configuration file because in sample configuration file in the Red Hat official document here it does not contain such fields. At this stage I would recommend not specifying both MACADDR and HWADDR unless you run into physical address conflict problem.

2012-06-11 Edit…

View original post 669 more words