linux 和 window 上route命令使用

Thursday, October 9, 2008

linux:
route add -net 192.168.81.0 netmask 255.255.255.0 gw 172.168.100.2
window:
route add 192.168.81.0 mask 255.255.255.0 172.168.100.2 -p

Posted by Michael.Ding at 6:12 PM 0 comments

freebsd ports 使用http代理

ee /etc/make.conf
添加
FETCH_ENV?=HTTP_PROXY=http://user:password@proxyurl:proxyport

Posted by Michael.Ding at 5:46 PM 0 comments

iptables的ipp2p模块加载

Tuesday, October 7, 2008

reference:
http://wiki.centos.org/HowTos/I_need_the_Kernel_Source
http://sourceforge.net/project/showfiles.php?group_id=80085
http://blog.chinaunix.net/u/28814/showart.php?id=1220921
http://linux.chinaunix.net/bbs/thread-1032941-1-1.html
http://linux.chinaunix.net/bbs/viewthread.php?tid=914377

出现error
重启机器后发现dmesg
e1000 device eth0 does not seem to be present, delaying initialization.
处理方式
depmod -a
modprobe e1000
lsmod
service network restart

补充命令:lspci
本文介绍在Linux下使用lspci命令查看PCI设备详细信息,也可以认为是lspci命令的功能介绍。

当前很多常用硬件都是PCI(Peripheral Component Interconnect)设备,如声卡、网卡、USB控制器等,稍老一点的显卡一般也是PCI设备。很可能由于要安装驱动或其它的需要查看PCI设备的详细信息。linux中的lspci命令方便地实现了这一点。

lspci最简单的使用方法是:

$lspci

它显示出通常对我们最有用的信息。

如果要更的详细信息,可以:

$lspci -v
$lspci -vv
$lspci -vvv

如果有的项目不能正常翻译成人能理解的文字,可以

$update-pciids

请确认您已连到互联网,能访问国外网。

Posted by Michael.Ding at 1:41 PM 0 comments

Freebsd下普通用户使用sudo执行命令

cd /usr/ports/security/sudo
make install clean

ee /usr/local/etc/sudoers
修改
# %wheel ALL=(ALL) NOPASSWD: ALL

%wheel ALL=(ALL) NOPASSWD: ALL

这样whell组用户就可以通过sudo执行所有命令,且不需要输入密码。

给普通用户使用bash
cd /usr/ports/shells/bash
make install clean

默认bash路径为/usr/local/bin/bash
在用户home目录下建立.bash_profile和.bashrc提高用户使用bash的方便程度
ee .bash_profile
添加
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

ee .bashrc
添加
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -lA'

source .bash_profile
source .bashrc

顺便提一下freebsd默认的csh是不带tab补全的,使用起来十分不方便,可以通过修改/etc/csh.cshrc
添加
set autolist

Posted by Michael.Ding at 11:46 AM 0 comments

使用chkrootkit工具保护服务器(转)

Saturday, October 4, 2008

在保护linux 服务器时除了Tripwire 这样强大工具外,还有一个简单又好用的工具–chkrootkit。chkrootkit 顾名思义是监测系统是否被安装了rootkit 的一个安全工具。

安装chkrootkit,你可以自己去 http://www.chkrootkit.org/download/ 下载源码包,然后自己编译,也可以和我一样偷懒用别人做好的二进制包.

centos 下用非官方源安装chkrootkit:
首先添加dag 源for centos(我的系统是centos5.2)

# vi /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

# rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

yum 安装chkrootkit
# yum update
# yum install chkrootkit

chkrootkit的应用
chkrootkit 的使用非常简单直接运行 chkrootkit 命令,然后会有如下输出

ROOTDIR is `/’
Checking `amd’… not found
Checking `basename’… not infected
Checking `biff’… not found
Checking `chfn’… not infected
Checking `chsh’… not infected
Checking `cron’… not infected
Checking `crontab’… not infected
Checking `date’… not infected
Checking `du’… not infected
Checking `dirname’… not infected
Checking `echo’… not infected
Checking `egrep’… not infected
Checking `env’… not infected
.
.
.

如果有rootkit会报“INFECTED” 所以可以直接用chkrootkit -n|grep ‘INFECTED’更直接一些。

定时检测并在出问题时给管理员发邮件。
创建如下脚本chkrootkit.sh并放入crontab 定时运行。

# cat chkrootkit.sh
#!/bin/bash
PATH=/usr/bin:/bin

TMPLOG=`mktemp`

# Run the chkrootkit
/usr/bin/chkrootkit > $TMPLOG

# Output the log
cat $TMPLOG | logger -t chkrootkit

# bindshe of SMTPSllHow to do some wrongs
if [ ! -z "$(grep 465 $TMPLOG)" ] && \
[ -z $(/usr/sbin/lsof -i:465|grep bindshell) ]; then
sed -i ‘/465/d’ $TMPLOG
fi

# If the rootkit have been found,mail root
[ ! -z "$(grep INFECTED $TMPLOG)" ] && \
grep INFECTED $TMPLOG | mail -s “chkrootkit report in `hostname`” root

# chmod 700 chkroot.sh
# mv chkrootkit /etc/cron.daily

这样系统会每天运行chkrootkit 检测系统,并在检测到rootkit 时给root 发一封邮件。

把给root 用户的系统邮件转发的管理员的gmail 邮箱

虽然可以登陆到系统去看系统邮件,但显然能用gmail 查看是更方便的选择。
1.安装sendmail 邮件转发要用到sendmail,
# yum sendmail
# /etc/intit.d/sendmail start (sendmail服务)
2.设置转发,编辑/etc/aliases,在文件最后加入
root: youname@gmail.com 然后运行newaliases 命令更新aliases
这样系统就会把给root 的邮件转发的你gmail 邮箱里去了。

本文中严重参考入侵监测系统的构建( chkrootkit ) 一文,感谢该文作者的工作。

Posted by Michael.Ding at 1:40 AM 0 comments

CentOS5取得 kernel source

Monday, September 29, 2008

Posted by Michael.Ding at 8:52 PM 0 comments

CentOS 5 上安装crond服务

Monday, September 22, 2008

最小安装的CentOS5上安装crond服务

# yum install crontabs(Root crontab files used to schedule the execution of programs.)
# yum install vixie-cron(The Vixie cron daemon for executing specified programs at set times.)

linux下的定时执行工具crontab(转贴自百度)
reference:http://hi.baidu.com/monobao/blog/item/01e9ecdcbc6a14a1cc11665b.html
cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业。由于Cron 是Linux的内置服务,但它不自动起linux 定时 crontab可以用以下的方法启动、关闭这个服务:

  /sbin/service crond start //启动服务

  /sbin/service crond stop //关闭服务

  /sbin/service crond restart //重启服务

  /sbin/service crond reload //重新载入配置

  你也可以将这个服务在系统启动的时候自动启动:

  在/etc/rc.d/rc.local这个脚本的末尾加上:

  /sbin/service crond start

  现在Cron这个服务已经在进程里面了,我们就可以用这个服务了,Cron服务提供以下几种接口供大家使用:

  1.直接用crontab命令编辑

  cron服务提供crontab命令来设定cron服务的,以下是这个命令的一些参数与说明:

  crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数

  crontab -l //列出某个用户cron服务的详细内容

  crontab -r //删除没个用户的cron服务

  crontab -e //编辑某个用户的cron服务

  比如说root查看自己的cron设置:crontab -u root -l

  再例如,root想删除fred的cron设置:crontab -u fred -r

  在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root -e

  进入vi编辑模式,编辑的内容一定要符合下面的格式:*/1 * * * * ls >> /tmp/ls.txt
这个格式的前一部分是对时间的设定,后面一部分是要执行的命令,如果要执行的命令太多,可以把这些命令写到一个脚本里面,然后在这里直接调用这个脚本就可以了,调用的时候记得写出命令的完整路径。时间的设定我们有一定的约定,前面五个*号代表五个数字,数字的取值范围和含义如下:

  分钟 (0-59)

  小时 (0-23)

  日期 (1-31)

  月份 (1-12)

  星期 (0-6)//0代表星期天

  除了数字还有几个个特殊的符号就是"*"、"/"和"-"、",",*代表所有的取值范围内的数字,"/"代表每的意思,"*/5"表示每5个单位,"-"代表从某个数字到某个数字,","分开几个离散的数字。以下举几个例子说明问题:

  每天早上6点

  0 6 * * * echo "Good morning." >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。

  每两个小时

  0 */2 * * * echo "Have a break now." >> /tmp/test.txt

  晚上11点到早上8点之间每两个小时,早上八点

  0 23-7/2,8 * * * echo "Have a good dream:)" >> /tmp/test.txt

  每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点

  0 11 4 * 1-3 command line

  1月1日早上4点

  0 4 1 1 * command line

  每次编辑完某个用户的cron设置后,cron自动在/var/spool/cron下生成一个与此用户同名的文件,此用户的cron信息都记录在这个文件中,这个文件是不可以直接编辑的,只可以用crontab -e 来编辑。cron启动后每过一份钟读一次这个文件,检查是否要执行里面的命令。因此此文件修改后不需要重新启动cron服务。

  2.编辑/etc/crontab 文件配置cron

  cron服务每分钟不仅要读一次/var/spool/cron内的所有文件,还需要读一次/etc/crontab,因此我们配置这个文件也能运用cron服务做一些事情。用crontab配置是针对某个用户的,而编辑/etc/crontab是针对系统的任务。此文件的文件格式是:

  SHELL=/bin/bash

  PATH=/sbin:/bin:/usr/sbin:/usr/bin

  MAILTO=root //如果出现错误,或者有数据输出,数据作为邮件发给这个帐号

  HOME=/ //使用者运行的路径,这里是根目录

  # run-parts

  01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本

  02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本

  22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本

  42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本

  大家注意"run-parts"这个参数了,如果去掉这个参数的话,后面就可以写要运行的某个脚本名,而不是文件夹名了。

Posted by Michael.Ding at 12:38 PM 0 comments