Archive

Archive for the ‘Linux Tricks’ Category

How to Add Sicky Bit for a Directory in Linux

April 24th, 2010 No comments

First of all, let me explain, what the is. When set, it tells the operating system to retain the text segment of the application in swap space after the process exited. This speeds up subsequent executions as it allows the kernel to prevent multiple operations of moving the program from swap to real memory.

The most common use of the sticky bit today is related to directories. When the sticky bit is set, only the item’s owner, the directory’s owner, or the root can rename, delete, or modify files. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of owner. Typically this is set on the /tmp directory to prevent users from deleting or moving other users’ files.

In order to set the sticky bit, a simple command is used:

chmod +t /tmp

In order to check whether the sticky bit is set, here is another command:

ls -ld /tmp

If you r last bit is ‘t’, then the sticky bit is set to the directory. It is a common practice to protect this folder in such a way as many server applications store their temporary data in this directory. For example, default MySQL configuration is set to store its socket file in /tmp/mysql.sock. You can experience problems if you don’t set a sticky bit on your /tmp directory.

How to Use Dynamic DNS With a PPP Connection in Linux

February 2nd, 2010 No comments

Dynamic DNS represents a DNS management system, that allows to periodically update DNS records. Since almost any DNS server provides this functionality, dynamic DNS is used when updates need to be more frequent than usually and updated DNS becomes the most important point in user activity (more than speed, system stability, etc).

When you need to establish connection with a hostname, that has a dynamic IP address (most typical situation – a hostname, that has an unstable Internet connection), Dynamic DNS becomes a simple yet stable solution.

When a hostname obtains an IP address, it is automatically sent to Dynamic DNS system, but users are able to connect using a symbolic name, that remains unchanged (for example, hostname.com).  In order to prevent IP caching, Dynamic DNS records have low TTL values (e.g. 60 seconds).

We’re going to cover the process of using such a configuration with a pppd connection, this package is widely used in Linux with almost all types of Internet connections.

We will take dyndns.org as a Dynamic DNS provider (you’re welcome to select another one: there is no real difference between them). We won’t describe the process of signing up and creating DNS records, but you’re always welcome to follow this guide, and ask us if anything is unclear, though it should be.

We will use inadyn for our connections. It gives the possibility to have your own fixed hostname registered on the internet, although your IP might be changing. It checks periodically whether the IP address stored by the DNS server is the real current IP address of the machine that is running INADYN. Though there are some limitations, that are described here, it is a simple solution, that doesn’t require any specific knowledge. It is a free software, that allows to connect with many Dynamic DNS providers, and you can obtain it by following this link.

You will need to download it, unpack and compile using make.

We will use it in the following way:

inadyn is started when the connection is being established (pppd acquires an IP address and creates an interface). Immediately after that it tries to perform an update and then remains in memory to periodically check for updates. If inadyn is already present in memory, it will be terminated before running a new instance.

In order to do that, we need to touch /etc/ppp/ip-up.local file (create a new one if it doesn’t exist) with the following contents:

#!/bin/sh
kill `ps -A |grep inadyn |sed ‘s/[ |\t].*$//’`
sleep 1
/etc/ppp/inadyn -u login -p xxxxx -a lampdocs.dyndns.org –background –update_period_sec 3600

Replace xxxxx with your password, login with your username, obtained at dyndns.org and lampdocs.dyndns.org with a symbolic name you’ve set for your host with dynamic IP.

You can change kill `ps -A |grep inadyn |sed ‘s/[ |\t].*$//’` if you don’t like it. Here is another variant:

#!/bin/sh
pkill inadyn
sleep 1
/etc/ppp/inadyn -u login -p xxxxx -a lampdocs.dyndns.org –background –update_period_sec 3600

That’s enough for configuration. Inadyn will be automatically started when a new pppd connection is established. You might need to enable inadyn requests in firewall, so it could connect using http without any problems. Inadyn requires just 2 addresses to connect, and both of them have fixed IPs:

checkip.dyndns.org (IP 208.78.70.70)
members.dyndns.org (IP 204.13.248.112)

You can enable these requests by issuing the following commands:

iptables -t filter -I OUTPUT -p tcp -d 208.78.70.70 –destination-port 80 -j ACCEPT
iptables -t filter -I OUTPUT -p tcp -d 204.13.248.112 –destination -port 80 -j ACCEPT

Then you should input

iptables -t filter -I INPUT -p tcp -s 208.78.70.70 –source-port 80 -j ACCEPT
iptables -t filter -I INPUT -p tcp -s 204.13.248.112 –source-port 80 -j ACCEPT

Or

iptables -t filter -I INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

- they have the same functionality for our needs. That’s all, Dynamic DNS should be working for you. Note, that you will have to configure inadyn if you choose another Dynamic DNS provider, the configuration is not complicated and you can find it in inadyn documentation.

Please, let us know if you have any problems using Dynamic DNS.

How to enable GeoIP in Awstats using Cpan

February 2nd, 2010 No comments

It is very useful to see visitors’ country information when you’re watching awstats logs. Let me tell you what to do if you don’t have Geoip support enabled on your server.

First of all, we will need to download and install GeoIP. We will take free version, but if you really require good stats, you may buy one. Let’s switch to a temporary directory to issue the following commands:

wget http://maxmind.com/download/geoip/api/c/GeoIP.tar.gz;
tar xzvf GeoIP.tar.gz;
cd GeoIP-1.4.6;
./configure;
make;
make install;

You might need to replace 1.4.6 with your version of Geoip, as 1.4.6 is the latest one for today.

Then we need to using cpan. I suppose, that you are already familiar with cpan, that’s why I won’t describe initial span setup procedure here. In order to install it, we need to enter cpan from command line. Then issue the following command:

install Geo::IP

Then type quit. And the final stage: we will add Geoip support to awstats.conf. You’re welcome to do it with any editor you like, here is a command line variant using sed.

sed -i ‘s/#LoadPlugin=”geoip GEOIP_STANDARD \/pathto\/GeoIP.dat”/LoadPlugin=”geoip GEOIP_STANDARD \/usr\/local\/share\/GeoIP\/GeoIP.dat”/’ /etc/awstats/*.conf

You’re done now. Have fun with your updated awstats!

Rar Part Files Are Not Recognized: How to Fix in Linux

February 1st, 2010 No comments

Though RAR provides its own interface to create multipart archives, sometimes users prefer to use another file splitting options. An example could be HJSPLIT, that provides the ability to split files of any type. Since archives are used to economize space and traffic, splitting an archive into multiple parts may be useful when there are attachment limits, or any other cases that are related to limited space.

How do those files usually look like? For example, there was archive.rar before. When it is splitted into 3 parts, we will have archive.rar.000, archive.rar.001, archive.rar.002. How do we join them together?

There is a simple command line solution for this:

cat archive.rar.* > archive.rar

This will join all the parts to a single rar file. Then you fill be able to unrar it. No matter, what was the file type, this is the easiest way to join files together, if they were splitted before.