iptables

有关iptables,这里有一篇非常全面的介绍

Linux iptables信息包过滤过程图

http://www-128.ibm.com/developerworks/cn/linux/network/s-netip/diagram1.jpg

查看已有的包过滤规则

# iptables -L

这将显示默认的表filters中的规则,如果想查看nat表或者mangle表,需要使用

# iptables -t nat -L
# iptables -t mangle -L

需要注意的是,rh linux 中有两个iptables 命令,一个是/sbin/iptables ,也是我们设置规则所使用的命令。另一个是/etc/rc.d/init.d/iptables ,用于保存设置的iptables 规则,或者重启动iptables 服务等等:

# /etc/rc.d/init.d/iptables save

 

iptables 命令所编辑的规则被保存到以下文件:

/etc/sysconfig/iptables

 

GnuPG(gpg)

验证一个使用GnuPG 签名(Signed)的文件,首先需要获得对此文件进行签名者的公钥(Pub Key),公钥一般可通过签名者的网站获得,是一个扩展名为 .asc 的文本文件。下载回来之后,先导入此公钥,并查看本地已经保存的公钥:

$ gpg --import filename.asc
$ gpg --list-key

验证文件 filename.tar.gz 的签名,filename.tar.gz.sig 是随着filename.tar.gz 一同发布的签名文件。

$ gpg --veriry filename.tar.gz.sig filename.tar.gz
gpg: Signature made Fri 15 Jul 2005 04:13:35 AM CST using DSA key ID 89E917F3
gpg: Good signature from "tcpdump.org (SIGNING KEY) <
tcpdump-workers@tcpdump.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 0227 54EB 4C30 9185 FD31  33A3 464D 3CEB 89E9 17F3

使用GnuPG 为自己建立用于签名的公钥与私钥

$ gpg --gen-key

然后按提示操作,将为你生成一对公钥与私钥,将公钥发布出去,私钥自己妥善保存。

使用私钥加密一个文件:

$ gpg --sign filename.txt

解密文件:

$ gpg filename.txt

参考 man gpg

curl

命令行下的Web 客户端 curl,读取一个链接,并把内容输出到标准输出,如果想查看 www.aiview.com 的首页,如下操作:

$ curl www.aiview.com |more

用于集线器(Hub) 环境的sniffer 工具 tcpdump,下载地址:www.tcpdump.org

top

top 命令不仅可以用于查询系统资源使用情况,还可以显示系统当前总计运行时间:

$ top
 19:46:28  up 5 days,  6:48,  2 users,  load average: 0.05, 0.04, 0.01
60 processes: 58 sleeping, 2 running, 0 zombie, 0 stopped
CPU states:   0.3% user   0.0% system   0.0% nice   0.0% iowait  99.6% idle
Mem:   255268k av,  238332k used,   16936k free,       0k shrd,   85536k buff
                    155172k actv,       0k in_d,    4148k in_c
Swap:  265000k av,       0k used,  265000k free                  126372k cached

free

free 命令相对于top 提供了更简洁的查看系统内存使用情况:

$ free
             total       used       free     shared    buffers     cached
Mem:        255268     238332      16936          0      85540     126384
-/+ buffers/cache:      26408     228860
Swap:       265000          0     265000
  • Mem:表示物理内存统计
  • -/+ buffers/cached:表示物理内存的缓存统计
  • Swap:表示硬盘上交换分区的使用情况,这里我们不去关心。

系统的总物理内存:255268Kb(256M),但系统当前真正可用的内存b并不是第一行free 标记的 16936Kb,它仅代表未被分配的内存。

我们使用total1、used1、free1、used2、free2 等名称来代表上面统计数据的各值,1、2 分别代表第一行和第二行的数据。

  • total1:表示物理内存总量。
  • used1:表示总计分配给缓存(包含buffers 与cache )使用的数量,但其中可能部分缓存并未实际使用。
  • free1:未被分配的内存。
  • shared1:共享内存,一般系统不会用到,这里也不讨论。
  • buffers1:系统分配但未被使用的buffers 数量。
  • cached1:系统分配但未被使用的cache 数量。buffer 与cache 的区别见后面。
  • used2:实际使用的buffers 与cache 总量,也是实际使用的内存总量。
  • free2:未被使用的buffers 与cache 和未被分配的内存之和,这就是系统当前实际可用内存。

可以整理出如下等式:

total1 = used1 + free1
total1 = used2 + free2
used1 = buffers1 + cached1 + used2
free2 = buffers1 + cached1 + free1
buffer 与cache 的区别

A buffer is something that has yet to be "written" to disk. A cache is something that has been "read" from the disk and stored for later use.

更详细的解释参考:Difference Between Buffer and Cache

对于共享内存(Shared memory),主要用于在UNIX 环境下不同进程之间共享数据,是进程间通信的一种方法,一般的应用程序不会申请使用共享内存,笔者也没有去验证共享内存对上面等式的影响。如果你有兴趣,请参考:What is Shared Memory?

关闭不使用的服务

如果你正在运行一个Linux 服务器,那么关掉那些不常用或者永远不会用到的服务是个好主意。

使用如下命令检查当前系统设置了哪些服务在启动时运行(注意,这与当前系统运行了哪些服务有区别)

# chkconfig --list |grep 3:on

如果你的系统默认运行在命令行模式,使用“3:on”,如果默认运行了图形界面,使用“5:on”,这个数字代表了系统的启动级别,在/etc/inittab 中进行配置。

对于一些你很清楚的非必要服务,使用如下命令停止服务,并关闭其在所有级别的启动,如果仅希望关闭在某个级别的启动,使用参数 --level,具体请参考笔者第一篇笔记。

# service srvname stop
# chkconfig srvname off

对于不清楚的服务,参考:Linux Services, Devices, and Deamons

比如,对于一般不启动图形界面的Linux 服务器,以下服务均可关闭:

  • rawdevices 用于裸设备
  • pcmcia 笔记本的pc 卡设置
  • apmd 笔记本电池监测
  • gpm 鼠标支持
  • autofs 自动mount文件系统
  • isdn 设置isdn连接
  • portmap 为NFS 等服务提供RPC 支持
  • nfs 网络文件系统服务器,让别人通过网络mount 你的文件
  • nfslock 服务于nfs
  • sendmail 邮件传输
  • squid 用于FTP 与HTTP 服务的代理缓存,加快web 访问速度
  • winbind 用于UNIX 中同步NT 主机上的帐号信息,一般用于配合SMB 共享
  • smb 与Windows主机进行文件与打印机资源共享
  • xfs X 系统下的字体服务
  • vsftpd FTP服务器

Post a comment

mail.png


相似文章|Related Entries

最近更新|Recent Entries

不定期更新|Handy Entries

相似标签|Related Tags

Linux
Apache (3)
awstats (4)
Cluster (1)
eMule (1)
ext3 (1)
Gentoo (1)
hdd (7)
mount (1)
NAT (1)
PowerDesigner (4)
Redhat (1)
Samba (2)
Study notes (9)
T43 (0)
Thinkpad (9)
Ultra Slim (4)
WAS (1)
Websphere (1)
乱码 (1)
学习笔记 (14)
虚拟主机 (1)
部署 (1)
集群 (1)
Study notes
Database (12)
DB2 (13)
Linux (16)
MySQL (3)
学习笔记 (14)
数据库 (15)
学习笔记
Database (12)
DB2 (13)
J2ME (1)
Linux (16)
Oracle (2)
Python (1)
Shell (8)
Study notes (9)
保险 (2)
数据库 (15)

分类栏目|Categories

按月归档|By Month

2008
07
05
04
03
02
01
2007
12
10
07
06
05
04
03
02
01
2006
12
11
10
09
08
07
06
05
04
03
02
01
2005
11
10
09
08
07
04
03
2004
12
11
10
09
08
07
06
05
04
03
02
01
2003
12
10
09
08
06
2002
09
08
04
03
02
2001
12
09
07
06
05

站内链接|Site Links

Powered by
Movable Type 3.34