pptp forword setting

2015年5月30日 09:04

1. 设置允许转发
sysctl -w net.ipv4.ip_forward=1 (这步一般文档都有)
2. 设置ppp0 -> eth0的跳转
iptables --insert FORWARD 1 --source 192.168.0.0/24 --destination 0.0.0.0/0.0.0.0 --jump ACCEPT

测试:

tcpdump -n -i ppp0 icmp and src host 192.168.0.234 and dst host 8.8.8.8
3. 设置Target-> eth0 的返回
iptables --table nat --append POSTROUTING --out-interface eth0 --jump MASQUERADE

测试:

tcpdump -n -i eth0 icmp and dst host 8.8.8.8
4. 设置ppp0 -> eth0 的返回
iptables --insert FORWARD 1 --source 0.0.0.0/0.0.0.0 --destination 192.168.0.0/24 --jump ACCEPT --out-interface ppp0

测试:

tcpdump -n -i eth0 icmp and src host 8.8.8.8

继续阅读 »

Linode VPN

2014年12月16日 23:33

sudo iptables --insert FORWARD 1 --source 192.168.0.0/24 --destination 0.0.0.0/0.0.0.0 --jump ACCEPT

继续阅读 »

Monit tomcat run or not on Linux

2014年1月21日 14:28

#!/bin/bash  
#  
# Keep watch at tomcat's status,   
# automatically restart it if it dead or out of memory. 

tomcat_port=":80";
tomcat_port_pattern="/:80$/";
tomcat_base_dir="/share/tomcat80";
check_page_url=http://127.0.0.1/LotteryHome3/run.jsp;
pid_file_pattern="tomcat80";
guarder_dir="/share/monitor";
log_file="/share/monitor/tomcat_run_log.log";
d=$(date +%F" "%T);

#email config
[email protected]

#139mail can send a short message to me
#but the short message just display subject
mail_to(){
  echo "$1" | mail -s "$1" $to
}

#init log file
touch ${log_file}

do_restart_tomcat(){
  # first try to shutdown it anyway
  ${tomcat_base_dir}/bin/shutdown.sh

  # second, check if the tomcat pid still exist,if exist then kill it!
  if ps -ef | grep ${pid_file_pattern} | grep -v grep
  then
    kill -9 $(ps -ef | grep ${pid_file_pattern} | grep -v grep | awk '{print $2}')
  fi

  #run start tomcat
  ${tomcat_base_dir}/bin/startup.sh
  echo "$d success restart tomcat ,the new pid id is " >> ${log_file}
  ps -ef | grep ${pid_file_pattern} | grep -v grep | awk '{print $2}' >> ${log_file}
  echo >> ${log_file}
  mail_to "$d success restart tomcat"
}

# first, check if the tomcat si listen on the port
runingcount=$(netstat -ant | awk "\$6 == \"LISTEN\" && \$4 ~ $tomcat_port_pattern" | wc -l)
if [ "$runingcount" == "1" ];
then
  #init the check result file
  if [ -e ${guarder_dir}/checkResult.tmp ] 
  then
    cat /dev/null > ${guarder_dir}/checkResult.tmp
  else
    touch ${guarder_dir}/checkResult.tmp
  fi

  # try to get the check result
  wget -b -o wget.log -O ${guarder_dir}/checkResult.tmp ${check_page_url}
  # wait 5 second to let the get check result job done.
  sleep 5

  # check the result
  workflag=$(cat ${guarder_dir}/checkResult.tmp | grep ServerStillWorking)
  memoryflag=$(cat ${guarder_dir}/checkResult.tmp | grep LessOfMemory)

  if [ "$workflag" == "" ]; then
    echo "$d can not found [ServerStillWorking] in the check result, try to restart tomcat ......" >> ${log_file}
    do_restart_tomcat
  elif [ "$memoryflag" == "" ]; then
    echo "$d can not found [LessOfMemory] in the check result, the tomcat server may out of memory, try to restart it ......" >> ${log_file}
    do_restart_tomcat
  else
    echo "$d tomcat$port is running ......" >> ${log_file}
  fi
else
  echo "$d found the tomcat not listen on ${tomcat_port}, try to restart it ......" >> ${log_file}
  do_restart_tomcat
fi

继续阅读 »

Top 10 Unix Command Line Utilities

2013年6月18日 17:37

原文链接

0> tr

tmp > echo "adbdc" | tr "abc" "123"
1d2d3
tmp > echo "Hello" | tr "A-Za-z" "a-zA-Z"
hELLO
tmp > echo $PATH | tr ":" "\n" | sort
    /Users/oliver/.cabal/bin
    /Users/oliver/.rvm/bin
    /Users/oliver/.rvm/gems/ruby-1.9.3-p0/bin
    /Users/oliver/.rvm/gems/ruby-1.9.3-p0@global/bin
    /Users/oliver/.rvm/rubies/ruby-1.9.3-p0/bin
    /Users/oliver/local/node/bin
    /Volumes/macbox_cs/dev/android-sdk-macosx/platform-tools/
    ...

1> sort

tmp > du /bin/* | sort -n -r | head -4
1320    /bin/ksh
1264    /bin/sh
1264    /bin/bash
592     /bin/zsh

sort will take multiple files as input and will merge and sort all of the files for you. Some of the most used options include -r for sorting in reverse order and -f for sorting case-insensitive.

2> uniq

Want to get rid of duplicate lines? uniq solves this problem efficiently. Note that it will only compare adjacent lines for equality, so you might want to sort before you use uniq.
Nice options: -c will prepend the count of equal elements before a line, -u will only output lines that are not repeated and -i does the whole thing case-insensitive.

Here is an example that combines tr, sortand uniq such that you can get the frequency of all words in a wikipedia article:

tmp > curl http://en.wikipedia.org/wiki/Minimum_spanning_tree \
      | tr -cs "A-Za-z" "\n" | tr "A-Z" "a-z" \
      | sort | uniq -c | sort -n -r

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 93342  100 93342    0     0   279k      0 --:--:-- --:--:-- --:--:--  323k
1031 a
 568 span
 442 href
 435 class
 308 li
 300 b
 284 title
 229 wiki
 211 the
 209 cite
 206 id
 192 spanning
 184 i
 169 tree
 166 minimum
 ...

继续阅读 »

What's the difference between .bashrc, .bash_profile

2013年5月28日 10:26

/bin/bash
       The bash executable
/etc/profile
       The systemwide initialization file, executed for login shells
~/.bash_profile
       The personal initialization file, executed for login shells
~/.bashrc
       The individual per-interactive-shell startup file
~/.bash_logout
       The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
       Individual readline initialization file

继续阅读 »