Monday, December 30, 2013

Configure NFS server on CentOS 6.4

I use two physical machines to conduct this experiment.
NFS Server IP: 192.168.0.21
NFS Client IP: 192.168.0.27

Install NFS Server (CentOS 6.4)

$ yum install nfs-utils -y
$ service nfs start
$ chkconfig nfs on

Configure NFS Server

$ mkdir /nfs_dir
$ chmod 777 /nfs_dir
$ vim /etc/exports
add this line into the file
/nfs-dir 192.168.0.27(rw.sync,root_squash)

These settings accomplish several tasks:
  • rw: This option allows the client server to both read and write within the shared directory

  • sync: Sync confirms requests to the shared directory only once the changes have been committed.

  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.

  • no_root_squash: This phrase allows root to connect to the designated director

$ exportfs -a
$ exportfs 
$ showmount -e

You may want to flush the IP Tables to allow the NFS connection
$ iptables -L 
$ iptables -F

Configure NFS Client

$ mkdir /nfs_mnt
$ mount -t nfs 192.168.0.21:/nfs_dir /nfs_mnt

Or you can set the /etc/fstab file, and this line into the file
192.168.0.21:/nfs_dir  /nfs_mnt   nfs4     defaults,acl        1 1

Show mount list
$ mount
$ df -h

If you have an error message:
# mount -a
mount: wrong fs type, bad option, bad superblock on 172.31.27.164:/nfs_meerkats,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try

       dmesg | tail  or so

Solution: You need to install nfs-utils on the client side. Also, you need to service rpcbind start


IP Tables

$ iptables -L [--list]
list all of the IP table rules

$ iptables -F [--flush]
flush all of the IP table rules

$ service iptables save
save current iptables to /etc/sysconfig/iptables


Good article from linuxwave blog

http://linuxwave.blogspot.com/2013/11/manually-manipulating-iptables-in.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Linuxwave+%28linuxwave%29


Manually manipulating iptables in CentOS and Redhat

The iptables rules in redhat based distro is being kept by default in /etc/sysconfig/iptables and /etc/sysconfig/ip6tables. To manipulate the firewall, just add or remove rules from this file, and restart iptables services. For example, we want to allow tftp port, which is port 69 udp:
  1. Edit /etc/sysconfig/iptables
    • # vi /etc/sysconfig/iptables
  2. Add the following lines, before the final LOG and DROP lines for INPUT chain:
    • -A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
  3. Save and close the file
  4. Restart iptables service:
    • # /etc/init.d/iptables restart
  5. Check your new iptables rules, where -L is to list all rules in the selected chain, and -n is for printing port in numeric output:
    • # sudo iptables -L -n
  6. And you can see that
    "ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:69"
    line is in the iptables file.

To block any particular port, you just need to edit /etc/sysconfig/iptables, remove the ACCEPT line that contain that port, and restart iptables, and you are done :)


Save IP tables on CentOS
/etc/init.d/iptables start or service iptables save


Remove IPtable rules by line
iptables -vnL --line-numbers
iptables -D INPUT 22


Tuesday, December 3, 2013

generate random number

use Linear_congruential_generator

http://en.wikipedia.org/wiki/Linear_congruential_generator

r = a X + c

X is the initail seed. we can use the TSC value for that. And we use the current random number to generate the next random number. The parameters of a and c are form:
Sourcem(multiplier) a   (increment) coutput bits of seed in rand() / Random(L)
Numerical Recipes23216645251013904223

Here is some code I wrote:

// Generate Random Number using Linear congruential generator
/*
#define MULTIPLIER 1664525
#define INCREMENT 1013904223

// save the seed in the SMRAM
// SMM_BASE + 0xFD00
unsigned int *saved_seed = (unsigned int*)(SMM_BASE + 0xFD00);

// Get a seed from tsc
//u32 initial_seed = (u32)(get_rdtsc() >> 32);
// *saved_seed = initial_seed;

u32 rand = 0xfff & (MULTIPLIER*(*saved_seed) + INCREMENT);
*saved_seed = rand;

// printk(BIOS_DEBUG,"rand is: %x\n", rand);
// the random number is resides in [1, 0xffff]

Monday, December 2, 2013

compile latex

two ways:
1. use pdflatex: compile latex to pdf
$latexpdf main.tex

this method does not work well with .eps images

2. use latex: compile latex to dvi; then use dvipdfm: compile dvi to pdf
$latex main.tex
$dvipdfm main.dvi

bibtex main.tex generates all of the .bbl. you can manually put it in the main.tex


sample Makefile for method 1
TARGETS = main

LATEX = pdflatex
BIBTEX = bibtex

all:    $(TARGETS) debug

$(TARGETS):
$(LATEX) $@
$(BIBTEX) $@ > $(BIBTEX)_out.log


debug:
-grep Warning *.log
clean:  

rm -f images/*.aux images/*~ images/*.log *.aux *.bbl *.blg *.log *.dvi *.bak *~ $(TARGETS:%=%.pdf)

sample Makefile for method 2
TARGETS = main

LATEX = latex
DVIPDFM = dvipdfm
BIBTEX = bibtex

all:    $(TARGETS) debug

$(TARGETS):
$(LATEX) $@
-$(BIBTEX) $@ > $(BIBTEX)_out.log
$(DVIPDFM) $@

debug:
-grep Warning *.log
clean:  

rm -f *.aux images/*.aux *.bbl *.blg *.log images/*.log *.dvi *.bak *~ $(TARGETS:%=%.pdf)





convert pdf to eps

$ pdftops -eps <pdf file> <eps file>