Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Assign Multiple IP's on Single NIC

Restart the network after creating the following file:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0-range0 
IPADDR_START=192.168.1.2
IPADDR_END=192.168.1.3
CLONENUM_START=0

Reverse DNS Lookup

Use nslookup or host command:
nslookup ipaddr
host ipaddr

Configuring Postfix with SASL

See Postfix SASL Howto and www.mysql-apache-php.com/.

This is for CentOS 4 http://www.hughesjr.com/content/view/14/29/

Here is another one with TLS http://wiki.centos.org/HowTos/postfix_sasl

When using TLS for postfix, make sure master.cf has
smtps     inet  n       -       n       -       -       smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_wrappermode=yes

Configure Squirrelmail

Change domain in /etc/squirrelmail/config.php:
$domain = 'mydomain.com';
so the email received will have user@mydomain.com

To use https on apache, add the following to /etc/httpd/conf.d/squirrelmail.conf:
<Location /webmail>RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}:443%{REQUEST_URI} [QSA,R=permanent,L]
</Location>


Finally, selinux settings:
setsebool -P httpd_can_network_connect=1

Dovecot Imaps Server setup

You can do this for pop/pops/imap as well, here I only wanted to configure imaps. Make the following changes to /etc/dovecot.conf:
protocols = imaps
login_process_size = 64 # for x86_64
imap_client_workarounds = delay-newmail outlook-idle netscape-eoh
.
Also remember to open the port 993 for imaps in the iptable configuration.

Configure postfix

If this is a web server, make sure you changed MX record with dns provider to point to your server (or you will not be able to receive mail). I have modified the following is /etc/postfix/mail.cf:
myhostname = mydomain.com
myorigin = $myhostname
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost

Use http://pingability.com to check your DNS setup.

Tunnel VNC over ssh

This will be faster than using VNC over X over ssh (i.e., ssh -X). Let us say we want to tunnel vnc from remote to local and the vncserver on remote is started on port 2 (5092).
local$ ssh -C -L 5902:127.0.0.1:5902  uid@remote

Then on remote start vncserver if it is not started
remote$ vncserver :2

Now on start vncviewer on local to connect to remote vnc server:
local$ vncviewer locathost:2

X over ssh

Use either -X or -Y option with ssh.
localhost$ ssh -X remotehost
remotehost$ xterm # this remotehost xterm will show on your local machine

Ssh Read from remote host remote.com: Connection reset by peer

My hosting company firewall seems to drop idle connections. When I do a who on the server, there are many ssh sessions that are already dropped on the client side. I add the following to the /etc/ssh/sshd_config, then restarted the sshd. Connection reset does not happen anymore. Had to adjust ClientAliveInterval a few times to half of the firewall's timeout value.
TCPKeepAlive yes
ClientAliveInterval 240

Also you can change this in the kernel:
# cat /proc/sys/net/ipv4/tcp_keepalive_time
7200
# echo 240 > /proc/sys/net/ipv4/tcp_keepalive_time

And make changes to /etc/sysctl.conf permanently.
net.ipv4.tcp_keepalive_time = 180

groupadd and useradd

Add a group 'friend' with a specific gid 600:
groupadd --gid 600 friend
Create a user with a specific gid 'friend':
useradd -g friend -m username
Add a existing user 'username' to a group 'friend'
usermod -a -G friend username
Change username's primary group to 'friend'
usermod -g friend username
Remove user's group
gpasswd --delete user group

Emacs Ediff Lose Focus

This seems to happen in emacs-21 and emacs-22, when I type next in the control panel, the cursor focus changes from control panel to one of the emacs diff buffers. I am not sure if this is relate to window manager (xfce) or emacs configuration. I have to change to it 'always on top' to fix the problem.

How to Undelete a Removed File on a NTFS File System

This is the instruction to recover a deleted file on a NTFS partition mounted on Linux. For windows, there are commerical software you can use to do the undelete. But if you have a Linux partition installed on your computer, you can recover/undelete the file in the NTFS partition under Linux for free.

To recover a deleted file on a NTFS partition use ntfsundelete (yum install ntfsprogs). For example, to recover abc.xls. First check the file deleted within a day (assume you deleted the file today, then recover the file with inode specified(in this case 106).
# ntfsundelete /dev/sda5 -t 1d
Inode Flags %age Date Size Filename
---------------------------------------------------------------
106 FN.. 100% 2008-10-14 14848
4477 FN.. 100% 2008-10-14 14848

Files with potentially recoverable content: 2

#
ntfsundelete /dev/sda5 -u -i 106 -o abc.xls
Inode Flags %age Date Size Filename
---------------------------------------------------------------
106 FN.. 0% 2008-10-14 14848

Undeleted '(null)' successfully.


Also see instruction for undeleting a file on an ext3 file system.

How to Undelete a Removed File on an ext3 File System

If you accidentally delete a file on ext3, you can recover it using ext3grep. Below is an example where I am trying to restore the file test/tt.
# ext3grep  --dump-names /dev/sda10
Running ext3grep version 0.8.0
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set. This either means that your partition is still mounted, and/or the file system is in an unclean state.
Number of groups: 258
Minimum / maximum journal block: 1546 / 35888
Loading journal descriptors... sorting... done
....

test
test/.tt.swp
test/tt

# ext3grep --restore-file 'test/tt' /dev/sda10
Running ext3grep version 0.8.0
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set. This either means that your partition is still mounted, and/or the file system is in an unclean state.
Number of groups: 258
Loading group metadata... done
Minimum / maximum journal block: 1546 / 35888
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1223927674 = Mon Oct 13 13:54:34 2008
Number of descriptors in journal: 25686; min / max sequence numbers: 198274 / 210642
Writing output to directory RESTORED_FILES/
Loading sda10.ext3grep.stage2... done
Restoring test/tt
# cat RESTORED_FILES/test/tt
abc

Also see instruction on how to undelete a file on NTFS partition.

Also, you can try foremost and scalpel packages.

How to Undelete a File on Reiserfs and XFS

There are more work to recover a file on Reiserfs and XFS than either NTFS or ext3.

For reiserfs, see http://antrix.net/journal/techtalk/reiserfs_data_recovery_howto.comments

For xfs, see http://linuxwebdev.blogspot.com/2005/06/xfs-undelete-howto-how-to-undelete.html

Swappiness

Desktop with 3G RAM: vm.swappiness = 10
Laptop with 1G RAM: vm.swappiness = 0
Server with 1G RAM: vm.swappiness = 50

Domain Ownership Lookup with whois command

$ whois somedomain.com

Monitoring Network Stats with vnstat

$ vnstat
Database updated: Tue Oct 7 14:30:01 2008

eth0

received: 13.54 MB (81.2%)
transmitted: 3.67 MB (18.8%)
total: 17.20 MB

rx | tx | total
-----------------------+------------+-----------
today 13.54 MB | 3.67 MB | 17.20 MB
-----------------------+------------+-----------
estimated 21 MB | 4 MB | 25 MB

To enable the monitoring, uncomment the following line from /etc/cron.d/vnstat
 */5 * * * *  vnstat /usr/sbin/vnstat.cron

crontab

User create crontab files to be executed by crond:
crontab -l: list current crontab entries.
crontab -e: edit crontab entries
crontab -r: remove the crontab file

crontab files are located in /var/spool/cron

cron will also run scripts in
cron.monthly/ cron.daily/ cron.hourly/ cron.weekly/

Auto Reboot after Kernel Panic

Add panic=5 to the kernel boot parameter in grub. Kernel will reboot 5 secs after kernel panic. For example,
kernel /vmlinuz-2.6.26.5-45.fc9.x86_64 ro root=LABEL=/1 rhgb quiet panic=5


Alternatively, add kernel.panic=5 in /etc/sysctl.conf. This will be loaded after next reboot or you can manually load it sysctl -p. To check,
# sysctl -a |grep kernel.panic
kernel.panic_on_unrecovered_nmi = 0
kernel.panic_on_oops = 1
kernel.panic = 5
.

Monitor and Restart Processes

monit can be used to monitor and restart server processes such as apache. See the link below for more info:

Monitor and restart Apache or lighttpd webserver when daemon is killed

RHEL and CentOS monit rpm can be downloaded here. Install on CentOs:
# rpm -Uvh monit-4.10.1-7.el5.i386.rpm
# vi /etc/monit.conf
# chkconfig --level 345 monit on
# /etc/init.d/monit start