workaround for tcp privileged port run by non-root user

In Linux, non-root user is not allowed to bind to privileged port (1 – 1024). And for security reason or many others reason, we do not run service daemon with root user privilege.

This cause non-root user not able to bind to port 80 for example. There have some workaround or alternatives regarding to this problem.

1. Use iptables port redirection
2. Use stunnel peer in secured environment

It this article, I’d suggest to use iptables

1. login as root user
2.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080

3. save the redirection:

 iptables-save > /etc/sysconfig/iptables

You may access the localhost 8080 port from others server via port 80. To access from localhost, you still got to access via port 8080.

setup grub boot on a mirror harddisk

1. Assume you are running a mdadm mirror set and created two exactly same disk layout

sda1: /boot
md0(sda2,sdb2): /
md1(sda5,sdb5): /data
LABEL=/boot: /boot

2. first, clone the /boot partition, either “dd” or

mkfs.ext3 /dev/sdb1, mount /dev/sdb1 /boot.bak, cp -rfp /boot/. to /boot.bak/, then e2label /dev/sdb1 /boot

3. grub

root (hd1,0) ## Tell grub where is your boot disk
setup (hd1) ## install it

Continue reading “setup grub boot on a mirror harddisk”

Using imapsync to replicate email

1. Download and install the latest version of imapsync at http://www.linux-france.org/prj/imapsync/dist/. As of today, the latest version is 1.255.

2. imapsync requires Mail-IMAPClient 2.2.9. Most recent Linux distribution comes with version > 3.x, so you will need to manually download it at http://search.cpan.org/~djkernen/Mail-IMAPClient-2.2.9/.

3. Extract it, and install Mail-IMAPClient 2.2.9

wget http://search.cpan.org/CPAN/authors/id/D/DJ/DJKERNEN/Mail-IMAPClient-2.2...
tar xzf Mail-IMAPClient-2.2.9.tar.gz
cd Mail-IMAPClient-2.2.9
perl Makefile.PL
make install

4. You are set to go. The typical command to synchronize from imap mail to a courier imap mail server will be similar to this:

imapsync --host1 imap.source-mail.com --user1 me@source-mail.com --password1 mypassword \
    --host2 imap.dest-mail.com --user2 me@dest-mail.com --password2 mypassowrd \
    --syncinternaldates --prefix2 INBOX. --split1 100 --split2 100 \
    --exclude Trash|Junk

Disable IPv6 on RedHat/CentOS

Edit /etc/sysconfig/network and change

NETWORKING_IPV6=yes to
NETWORKING_IPV6=no

Edit /etc/modprobe.conf and add these lines (if they’re not in it):

alias net-pf-10 off
alias ipv6 off

Stop the ipv6tables service by typing:

service ip6tables stop

Disable the ipv6tables service by typing:

chkconfig ip6tables off

network boot install ubuntu with PXE

Here’s a brief overview of what you need and need to do to complete this;

1. One Windows based (XP/2000) to host TFTP Server, network enabled
2. One PC to have Ubuntu installed on to, with Intel PXE Boot capability
3. DHCP & TFTP Server (download Tftpd32 (http://tftpd32.jounin.net/) (freeware)
4. Download Ubuntu netboot.tar.gz (http://archive.ubuntu.com/ubuntu/dists/edgy/main/installer-i386/current/images/netboot/)
5. Live Internet Connection preferably via xDSL (broadband)
6. If you have a ADSL modem “router” with DHCP enabled, then you must temporarily disable the DHCP. You will only have a “router” if you have the capability to run more than one PC on your home network.

Setup your network environment
This procedure is a rough guide as a lot of home environments are different, you DO NOT need to do this if your network is configured with static IP Addresses (which means you are not using DHCP on your router aka where IP Address are Dynamically Allocated to PC’s on your network)
1. Start > Run > type CMD > OK
2. At the command prompt type ipconfig /all
3. Copy down the following details: IP Address, Subnet Mask, Default Gateway, DNS Servers
– Your IP Address should look something like 192.168.1.3
4. Log onto your router via the web interface (most ADSL routers have this)
– Normally you can do this by typing the Default Gateway address into your web browser
5. Locate the section that relates to the DHCP Server, disable the DHCP server, save changes.
6. Now setup your Windows PC with a static IP Address
Start > Control Panel > Network Connections > right-click Local Area Network > select Properties from floating menu
NB: If you’re using wireless networking, instead of Local Area Network, select Wireless Network Connection, then right-click and select Properties.
7. On General tab, scroll down and select Internet Protocol (TCP/IP)
8. Click Properties
9. Select Use the following IP Address
10. In IP Address type the IP Address you wrote down eg 192.168.1.2
11. Enter the Subnet Mask you wrote down eg 255.255.255.0
12. Enter the Default Gateway eg 192.168.1.5
13. Select Use the following DNS Server addresses
14. Enter the DNS Server Address you wrote down (most likely the same as Default Gateway) eg 192.168.1.5
15. Click OK to set changes to TCP/IP
16. Click OK to close network settings.
NB: We will revert these changes later.

Download & Configure DHCP/TFTP Server
1. Once you have downloaded the TFTPd32 Software, create a directory on the server PC. eg C:\tftpd32
2. Extract the TFTPd32 software to the directory you created
You should have 3 files: tftpd32.exe, TFTPD32.HLP, uninst.exe
3. Run the tftpd32.exe which will start the DHCP/TFTP Server for Windows
4. Select the DHCP Server Tab
5. In IP Pool starting address enter an IP Address greater than the one you gave your Windows machine. eg if your windows machine was 192.168.1.2 enter 192.168.1.3
6. In Size of Pool enter the number of machines you intend on having Ubuntu installed on (each machine will need an IP Address)
7. In Boot File enter pxelinux.0
8. In WINS/DNS Server enter your DNS Server Address you wrote down eg 192.168.1.5
9. Enter the same number in Default router
10. Enter the number you wrote down for Subnet Mask in Mask
11. In Lan enter lan – doesn’t matter what you enter here really
12. You must have this software running when you reboot the other PC(s) for PXE to pick-up the Ubuntu install.
13. If your other PC has Windows on it, it might be a good idea to ensure that the DHCP is working.

If the settings you copied down are correct, then your second PC should get an IP Address, DNS Server, Gateway IP Address etc and you should be able to surf the net. It is imperative that you can surf the net, because the Ubuntu installer gets the install files from the net for the installation.

If you can’t, then one of your IP addresses may be incorrect or the network card might not be functioning correctly. Unfortunately troubleshooting is beyond the scope of this howto.

Extract & Configure Ubuntu Image
1. Download and use WinZip to extract the files from netboot.tar.gz
2. Copy the ubuntu-installer directory and it’s contents to your TFTP directory eg C:\tftpd32\ubuntu-installer
3. Also copy the entire contents of \ubuntu-installer\i386\ directory to the TFTP directory C:\tftpd32\
This is duplication I realise, but for some reason you must have some or all of these files duplicated this way for the install to boot. I didn’t have time to figure out which one needs to be there, so I just duplicated the lot… how lazy am I?!

Running the Ubuntu Install
1. Have your Windows machine running, with the TFTP Server running and connected to the local network (by wire or wireless, doesn’t matter)
2. Reboot the machine you want to install Ubuntu on and enter the BIOS (normally requires the user to hit an F key eg F2)
3. Locate the Boot sequence in the BIOS and change the priority so that LAN boot is first, then HDD.
4. Save changes and exit, reboot.
5. The PXE Boot should appear and attempt to first retrieve an IP Address, then it should begin loading the Ubuntu installer. Wow!
6. Run through the install as documented…

Clean Up
1. Once the install is completed, you can close the TFTP/DHCP Server
2. Delete the directory and files you created for the TFTP Server eg Delete the directory C:\Tftpd32
3. Re-enable DHCP on your router (follow the instructions for “Setup your network environment” steps 1-5)
4. Re-enable DHCP for your Windows machine (TFTP Server) (Follow the instructions for “Setup your network environment” steps 6-16 however where Select “Use the following IP Address/DNS Server Addresses” was written, select the option “Obtain an Address Automatically”

Quoted from http://ubuntuforums.org/archive/index.php/t-327597.html