Linux Tips and Tricks

Tips and tricks for some of the more or less unusual problems in the context of the Linux operating systems are collected here to save me (or you) some time if it occurs again.

Activating NAT with Netfilter/iptables

First, enable forwarding:

echo "1" > /proc/sys/net/ipv4/ip_forward

Then, load the needed netfilter modules:

modprobe ip_tables
modprobe nf_conntrack
modprobe nf_conntrack_ftp
modprobe nf_conntrack_ipv4

Finally, all tables are flushed (optional) and the all outgoing packets (from eth0) are masqueraded by iptables:

iptables -F
iptables -F -t nat

iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE

All of the above instructions are also included in a small script.

Number of File Handles

As of Linux 2.6 (and probably 2.4) you can have as much file descriptors as you like. The global number of handles is set writing the wished value to

/proc/sys/fs/file-max

which has a default number of 206401 on my system. A simple "echo 1048576 > /proc/sys/fs/file-max" increases this to 220.

For the users to use more than 1024 open files, the limit has to be increased which is done by editing /etc/security/limits.conf. As an example, just add

username              hard    nofile          4096

and the user username can now open 4096 files at the same time.