http://wiki.freebsd.org/qemu

在freebsd手册里看到的一个例子,摘录出来,以便以后查找使用。

14.11.8.1.1 加强 POP3 服务的安全

  工作时, 有一个允许外来连接的 SSH 服务器。 同一个办公网络中有一个邮件服务器提供 POP3 服务。 这个网络, 或从您家到办公室的网络可能不, 或不完全可信。 基于这样的原因, 您需要以安全的方式来查看邮件。 解决方法是创建一个到办公室 SSH 服务器的连接, 并通过这个连接来访问 POP3 服务:

% ssh -2 -N -f -L 2110:mail.example.com:110 user@ssh-server.example.com
user@ssh-server.example.com's password: ******

  当这个通道连上时, 您可以把 POP3 请求发到 localhost 端口 2110。 这个连接将通过通道安全地转发到 mail.example.com

14.11.8.1.2 绕过严厉的防火墙

  一些大脑长包的网络管理员会使用一些极端的防火墙策略, 不仅过滤进入的连接, 而且也过滤连出的连接。 一些时候您可能只能连接远程机器 22 端口,以及 80 端口用来进行 SSH 和网页浏览。

  您可能希望访问一些其它的 (也许与工作无关的) 服务, 例如提供音乐的 Ogg Vorbis 流媒体服务器。 如果 Ogg Vorbis server 在 22 或 80 端口以外的端口播放音乐, 则您将无法访问它。

  解决方法是建立一个到您的网络的防火墙之外的网络上的 SSH 服务器, 并通过它提供的通道连接到 Ogg Vorbis 服务器上。

% ssh -2 -N -f -L 8888:music.example.com:8000 user@unfirewalled-system.example.org
user@unfirewalled-system.example.org's password: *******

  现在您可以把客户程序指定到 localhost 的 8888 端口, 它将把请求转发给 music.example.com 的 8000 端口, 从而绕过防火墙。

一直因不知道怎么设置geany的背景颜色,而引以为憾。

 今天在geany发现一个工具可以设置geany的背景颜色,地址: http://www.milliwatt-software.com/jmg/notes/geany.html#Syntax%20highlighting 。下载:http://www.milliwatt-software.com/jmg/files/set_geany_colors.tar.bz2

抓图: http://www.milliwatt-software.com/jmg/files/colorschemes.html

已经使用上了,这下可以彻底不用想editplus了。

PF

# cat /etc/pf.rules
gw1="xxx.xxx.xxx.111"
gw2="xxx.xxx.xxx.222"

pass in quick on xl0 reply-to ( xl0 $gw1 ) proto {tcp,udp,icmp} to any keep state
pass in quick on fxp0 reply-to ( fxp0 $gw2 ) proto {tcp,udp,icmp} to any keep state

pass out keep state

今天看到firefox3都出到3.0.1版本了。

想想也该换装新版本试试的时候了,于是到ports里make install一个。呵呵

整体感觉,比firefox2要舒服。尤其是中文字体方面,比之前好看的多了。

※ 来源:・BBS 水木清华站 bbs.net.tsinghua.edu.cn
发信人: Numb (麻木), 信区: Linux
标 题: FreeBSD Security HOWTO
发信站: BBS 水木清华站 (Sun Dec 20 05:14:30 1998)

FREEBSD SECURITY HOW-TO
o 前言
o 这份 HOW-TO 是必要的吗?

FreeBSD 是一个非常安全的作业系统。也正因为它的 source code 是可以免费的取得,
这个 OS 长久以来不断的有人改进加强。尽管 FreeBSD 一出厂就非常安全, 但是仍然
有更多加强安全性的措施, 来满足"偏执狂"的你 Smile 这份 HOW-TO 会教你一些步骤, 以
更加强你机器的整体安全。

o 这份文件会说明 tripwire, tcp_wrappers, cops, satan, 和其它的工具吗?

除了 SSH 之外, 不会。这是一份针对 FreeBSD 的文件 - 除此之外, 已经有很多文件
说明上述的工具了。目前呢, 我只想关心的是关於 BSD 的部份。

o 谁要读这份 HOW-TO?
任何想让他的系统更安全的人。这份 HOW-TO 包含了一些很基本的步骤, 和某些很复杂
的步骤。如果你有任何的疑问, 或者想要加以补充, 请 eMail 到维护人 jkb@best.com
又, 尽管大部份的内容是针对 FreeBSD 的, 但仍然会套用到其它的 Unix OSes 上面。
(特别是 OpenBSD 和 NetBSD)

o 这份 HOW-TO 还有其它语言的版本吗 ?
就我所知, 有俄语版:
http://www.etrust.ru/osa/security.html
和中文版:
http://water.ite.ntnu.edu.tw/doc/cfbhow2.txt

o TODO:
将包含 /etc/login.conf 和 login classes
将提及使用 X 的场合
将会有 html 版

o 网路
o inetd (Inet Daemon)
网路在系统安全上扮演了一个很重要的角色。FreeBSD 的根基是有着内建网路功能, 且
具有最稳最快的 TCP/IP stacks 的 4.4BSD。这个 stack 支援了非常多的协定像是
telnet, ftp, talk, rsh 等... 这些 service 的的主设定档便是 /etc/inetd.conf。
要编辑这个档, 请输入 "vi /etc/inetd.conf" (在这个例子里, 我使用 vi 。你可以
使用其它你较为上手的编辑器。或许你可以试试 pico)。如果你要使用 pico, 请在启
动它时加上 -w 选项:
-w 关掉自动断行。(因此可以容许超过 80 字元的行存在)

这选项在编辑 /etc/inetd.conf 时非常有用。
当然了, 你也可以使用 ee - 它随着 FreeBSD 一起 "出厂" 的, 而且也是 root 预设
的编辑器。不过, 请再 "echo $EDITOR" 确认一次。 开启了这个档案後, 你可以看
到里面怎麽描述每个 service 怎麽启动, 要以那位使用者执行等等的资讯。(man 5
inetd.conf)既然这个档案是许多 internet service 的主要设定档, 好好的设定它便
是一件十分重要的事。你要关掉一个 service的话,只消在那一行前面加个 "#" 符号。
基本的概念是, 关掉些你不熟悉的 services - 如果你不知道那个 service 是啥, 或
者不知道它可以干啥。理想状态下, 你不须要把所有的 service 都打开。例如, 你的
器只是要跑 web server。这种情况下, 你只要启动 ssh 和 httpd 便够了。关於啥是
ssh, 下面会说明。如果你啥 service 都不想跑, 最直接乾脆的方法是-关掉 inetd。
做法很简单, 只要编辑 /etc/rc.conf 并且把

inetd_enable="YES"

改成

inetd_enable="NO"

就可以了。
如此一来没人可以 telnet, rlogin, 或 ftp 到你的电脑。
如果你决定要启动你的 inetd 的话, 记得启动 log 选项, 并提高一个 service 每分
钟启动的上限数目。(预设值是 256, 我建议提高到 1024-自行叁照下面解说调整吧!)
为什麽要这麽做呢...? 就 modem user 或是低速专线用户是没什麽差别。但高速线路
的人, 上限值太低会蹦出一个 DoS attack(Denial of Service)。某个坏心的人可以简
单的用一个 shell script 同时搞出超过 256 个 connections, 这麽一来你的 inetd
会很不幸的阵亡。换句话说, 如果你想让每分钟每个 service 可接受的connection 数
多点, 记得做如下的设定, 不然来个坏心的人就可以搞垮你的电脑。因此, 在这行

inetd_enable="YES"

下面的

inetd_flags=""

要改成:

inetd_flags="-l -R 1024"

这会将连线的动作都 log 下来(-l 叁数)而且将同时最大连线数从预设的 256 增加到
1024。你还须要对你的 /etc/syslog.conf 作些修改, 这些等会儿会提到。

o SSH

在以下提到的案例中, 你完全不须要 run inetd。例如, 如果你只有跑 web, news, 或
是 nfs server, 那麽就没有必要在你的机器上再跑其它的services。但是你一定会问,
"我要怎麽控制我的机器啊!?" 嗯嗯, 所以现在要介绍 SSH。你可以透过 SSH (Secure
Shell) 来登入你的机器。Secure Shell 当初便是设计来取代 rsh, rlogin 等其它的
Berkeley r* 命令。相信你很快就会了解 SSH 是如何有用,而且开始使用它,来代替其
它的程式像是 telnet 和 ftp。SSH 具有很多功能,但是最为人知的是, 它的加密通讯
方式, 也就是防止你的密码和资料以明码的方式在网路上传输。如果你使用 telnet,你
的通讯内容可能会被"窃听": 传输中的资料被改变, 通讯内容被看到。(不是有 S/Key
可以解决吗? 很不幸的, 它还是有着插入资料和连接时被破解的问题) 我希望你可以完
全的关掉 inetd 而使用 SSH。如果你认为完全不靠 inetd 来启动某些 services,是完
完全全不可能的事, 那麽希望你至少启动 log 功能, 而且要增加每分钟同一个 servi-
ce 可启动的次数。 (原因上面有提到)
你可以从 ftp://ftp.funet.fi/pub/unix/security/login/ssh 下载 SSH。
若你想要更简单的方法:

# cd /usr/ports/security/ssh
# make install

如果你有不是使用 Unix 的使用者, 那麽可以从下面的站台抓到 win32 SSH 程式:
http://fox.doc.ic.ac.uk/~ci2/ssh/
http://www.zip.com.au/~roca/ttssh.html
http://bmrc.berkeley.edu/people/chaffee/winntutil.html
http://public.srce.hr/~cigaly/ssh
SecureCRT from http://www.vandyke.com


o inetd (part II)

o telnetd

好吧, 你仍然执意要使用 inetd。那麽我们来看看在 inetd.conf 有那些选项, 可以增
进你的系统安全。在攻击某系统之前, 攻击者都会先收集该系统的相关资讯。就 teln-
etd 而言, 你可以试试在 telnetd 那行後面加个 -h:

telnet stream tcp nowait root /usr/libexec/telnetd telnetd -h

从 telnetd 的 man page 可以知道:

-h Disable the printing of host-specific information before login
has been completed.

当有很多管道可以获得系统资讯的同时, 这招和下面的那招是个不错的解决方案。如果
你认为跑 telnet daemon 是没有必要的, 那麽只消加个 "#" 在该行的最前面就行了:

#telnet stream tcp nowait root /usr/libexec/telnetd telnetd

有个极不错的措施是, 你可以拒绝没有完整 FQDN 的人来连线。要做到这点, 也只要加
个 -U 选项到 telnetd 後面:

telnet stream tcp nowait root /usr/libexec/telnetd telnetd -h -U

这是个小动作, 但是对你的系统安全有莫大的助益。

o ftpd

现在来看看 ftp。 对於 ftp FreeBSD 已经做了一些 log 的动作 。 可以看到在
/etc/inetd.conf 里面 ftpd 那一行已经加了 "-l"。然而, 你还是要设定你的syslogd
, 使它可以接受 ftp daemon 产生的 log。从 man page 可以得知:

-l Each successful and failed ftp(1) session is logged using syslog
with a facility of LOG_FTP. If this option is specified twice,
the retrieve (get), store (put), append, delete, make directory,
remove directory and rename operations and their filename argu-
ments are also logged. Note: LOG_FTP messages are not displayed
by syslogd(Cool by default, and may have to be enabled in syslogd(Cool's
configuration file.
每个成功或是失败的 ftp 登入尝试, 都会以 LOG_FTP 机制纪录起来。如
果这个选项被指定了两次, 所有的下载 (get), 上载(put), 新增, 删除,
建立目录, 及更名的动作和档案名字都会被纪录下来。 又: LOG_FTP 讯
息预设是不会被 syslogd(Cool 纪录下来的。你还要在 syslogd(Cool 的设定
档里面启动这个功能才行。

让我们开启 syslogd 纪录 ftpd log 的功能吧~ 这个档案是 /etc/syslog.conf (别忘
了顺便看看 man 5 syslog.conf)。把下面这一行加到这个设定档里:

ftp.* /var/log/ftpd

也不要忘了执行这个指令 "touch /var/log/ftpdlog", 因为 syslogd 不能写入到一个
没有被开启过的档案。如果你想要你的 ftpd 提供你更多的 log 讯息, 那麽就在 ftp
那一行多加个 "-l" 吧:

ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l -l

如果你想要确定你的使用者们都用 scp (Secure Copy, 附属在 SSH 里面), 但是又想
要提供 anonymous ftp 服务, 也只消加个 "-A" 在 ftp 那行後面就行了:

ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l -A

你也可以编辑 /etc/ftpwelcome, 说明目前接受 anonymous ftp 登入, 但是系统内的
使用者就得使用 rcp 了。如果你有提供 anonymous ftp, 你可以使用 -S 选项来记录
传输的情形:

ftp stream tcp nowait root /usr/libexec/ftpd ftpd -A -S

o fingerd

Finger 服务预设值还算安全: 它不容许不带 user name 的 query。这是一件不错的事
(tm)。然而, 就是有些人无论如何也不想 run fingerd。这种情形下, 你只要简单的给
它加个 "#" 在这行的最前面就可以了。又, 你想要 log 住谁来 finger 的话, 加个
"-l" 也就行了:

finger stream tcp nowait nobody /usr/libexec/fingerd fingerd -s -l

Fingerd 产生的 log 资讯预设是写到 /var/log/messages。如果你想要这些资讯写入
到特定的档案里去, 那麽就在 /etc/syslog.conf 加入这一行:

daemon.notice /var/log/fingerd

/* !fingerd anyone? */

$ man 5 syslog.conf

除了 ftp, telnet 和 finger 之外, 你实在不须要在 /etc/inetd.conf 中再多启动任
何东西了。通常我都会关掉 talk 及 comsat等我个人不须要的东西。如同我之前讲的,
如果你不知到某个 servcie 是干嘛用的, 而且你也不须要它, 那麽就关掉它。一些和
网路有关而且很有用的 man page 是: inetd, ftpd, telnetd, fingerd, syslogd,
comsat, talkd, rshd, rlogind, inetd.conf。并且记得要看 man page 的"SEE ALSO"
部份, 以获得更多的相关资讯。

o ipfw (IP FrewWall)

IP FireWall 做的是 packet 过滤的工作。没错, 就是只有这样。然而, 你要考虑的事
是, 你的 kernel 要有支援 ipfw。 通常在我管的机器上, 我都会重编核心使其支援
ipfw。大概看起来是这样:

options IPFIREWALL #finger the net
options IPFIREWALL_VERBOSE #log the net
options IPFIREWALL_DEFAULT_TO_ACCEPT

第一行表示最其本的 IP FireWall 支援。第二行让 ipfw 可以把接受或拒绝 packets
的纪录 log 起来。第三行非常重要, 让 ipfw 预设值是接受任何地方来的 packets 。
如果你不这样做, 预设值拒绝任何地方来的 packets。我个比比较喜欢後者, 但我又认
为在我自己的工作站上, 或一个让人登入的工作站, 预设拒绝任何 packets 不是一件
太好的事。

********** NOTE ************
如果你搞不清楚自己在做啥事, 那就不要用这个选项。
就设定 firewall 而言, 这是不甚正确的。预设任何东西都该被挡掉才是正确的。如果
你是要建置一台高安全性的系统, 或一台 firewall 的话,那就千万不要加入这个选项:

options IPFIREWALL_DEFAULT_TO_ACCEPT

记住一件事: 要预设拒绝任接受任何 packets, 然後再加入 rule 来设定你想要接
受那些 packets。查看 /etc/rc.firewall 以得到更多的资讯。再一次提醒你, 不要使
用这个 option, 除非你只是想要防止 DoS attacks 或暂时把某些 port/network ban
掉。
*****************************

o log_in_vain

你也可以透过 sysctl 命令, 来改变一些有用的系统变数:

# sysctl -w net.inet.tcp.log_in_vain=1
# sysctl -w net.inet.udp.log_in_vain=1

这会把尝试向你的机器要求你没有的服务的 connections log 起来。例如, 如果你在
你的机器没有跑 DNS server, 而又有个人想要向你的机器要求 DNS 服务, 这时候你就
会看到

Connection attempt to UDP yourIP:53 from otherIP:X
(X 是某个 high port #)

你用 "dmesg" 命令就可以看到这一行。Dmesg 秀出的是系统的 kernel message
buffer。然而, 这个 buffer 的空间是有限的, 所以系统也会把这些讯息写入到
/var/log/messages 里面去:

# tail -1 /var/log/messages
Jun 12 19:36:03 ugh /kernel: Connection attempt to UDP yourIP:53 from otherIP:X

o final notes
理论上呢, 你的系统现在已经比你装好它时更安全些了。你现在可以做一些事来确定你
目前的更动:

$ netstat -na | grep LISTEN

这会告诉你那些 service 在那些 port 跑。越少越好 Smile 又, 再跑一些其它的 port
scanners (strobe, nmap) 来找出你开了那些 port。
而要确要你的 syslogd 已经开始纪下你刚刚想要 log 的事件, 可以这麽做:

# cd /var/log
# tail -10 fingerd ftpd messages

在 log 档里面没看到任何东西的话, 记得重新启动 inetd 和 syslogd:

# kill -HUP `cat /var/run/syslog.pig` `cat /var/run/inetd.pid`

o Filesystem

既然 Unix 把什麽东西都当作档案来看待, 好好的保护你的档案系统便是很重要的事。
有件事是在你安装作业系统前便要完成的: 必须要计划并设计好你的 partition 该怎
麽切割。有几个很重要的原因让你要这麽做: 一个是你可以 mount 不同的档案系统以
赋与不同的选项 (下面有几个例子)。别一个是,如果你想要把你的 filesystem export
出去, 你须要更加细微的控制。如果你是一个从 Linux 转入 FreeBSD 的使用者, 你会
发现 Linux 是把任何东西都往 root partition "/" 塞, 而 FreeBSD 预设便要 "/",
"/usr", 和 "/var"。这也使得要使用如 dump 般的工具较容易。且让我们来讨论 se-
curity 吧! 有一件事我通常会做的是, 我会把一般 users 可以写入的 partition 分
开来割, 而这些 partitons 便可以用 "nosuid" 的方式来 mount。从 mount 的 man
page 可以知道:

nosuid Do not allow set-user-identifier or set-group-identifier
bits to take effect. Note: this option is worthless if a
public available suid or sgid wrapper like suidperl is
installed on your system.

让 suid 或 sgid bit 失效。又: 对於像 suidperl 这些公开使用
的程式, 设这个选项便没用。

因此你会有个 partition 给一般使用者使用: /home 或 /usr/home。然後你可以另外
开个 partion 给 /var/tmp 然後再把你的 /tmp 指到这里:

# rm -rf /tmp
# ln -s /var/tmp /tmp

你可以叁考这个例子:

# cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/sd0s1b none swap sw 0 0
/dev/sd0s1a / ufs rw 1 1
/dev/sd0s1g /usr ufs rw 2 2
/dev/sd0s1h /usr/home ufs rw 2 2
/dev/sd0s1f /var ufs rw 2 2
/dev/sd0s1e /var/tmp ufs rw,nosuid 2 2
proc /proc procfs rw 0 0

现在你可以确定一般 users 可以写入的目录不是以 "-nosuid" 的方式被 mount, 就是
没有可以写入。现在你还要关心的就是 /var/spool/uucppublic"。
你可以把 "/var" 以 "-nosuid" 的方式来 mount , 或下这个命令:

# chmod o-w /var/spool/uucppublic

如果你想要找出你所有的可写入目录, 下这个命令:

# find / -perm -0777 -type d -ls

如同 man page 指出的, 具有 suid/sgid 的程式会让你的 nosuid 失效。找出那些程
式是 suid 或 sgid 的吧:

# find / -perm -2000 -ls
# find / -perm -4000 -ls

同时你不止可以用 "-ls" 而只是知道有那些程式。你可以把不是很有用的程式 "chmod
000"。像是 uustat, uucico 等, 如果你从来不碰 uucp 的话。或是 ppp 和 pppd, 如
果你绝不会用到他们。又, 你不会去用到印表机的话, 把 lpr lprd 也 chmod 000 吧!
也许改天会有个人写个 shell script 来问你那些东西要 chmod 000 掉。

现在你也许想问, 有什麽方式可以防止攻击者重新以非 "-nosuid" 的方式 mount 你的
filesystem ? Well, 没有, 除非你改变你的 securelevel。

o securelevel

FreeBSD kernel 有个观念叫 securelevel。当还有人在争论这是不是够完美时,这个
机制已经够防止大部份的 "script kiddiez"。Securelevel 是指你的 kernel 在执行时
的安全等级。每一个等级具有不同的保护和检查机制。这些是 init(Cool 的 man page:

The kernel runs with four different levels of security. Any superuser
process can raise the security level, but only init can lower it. The
security levels are:
Kernel 可以以四种不同的安全等级来执行。任何 superuser process 可以提高安全
等级, 但是只有 init 可以降低它。这四种等级分别是:

-1 Permanently insecure mode - always run the system in level 0 mode.
永远不安全模式 - 切换到 level 0 吧!

0 Insecure mode - immutable and append-only flags may be turned off.
All devices may be read or written subject to their permissions.
不安全模式 - "不可更动"和"只能附加"这两个旗标(flag)可以被改变。所有的
devices 可以照着它们的读写权限被读写。

1 Secure mode - the system immutable and system append-only flags may
not be turned off; disks for mounted filesystems, /dev/mem, and
/dev/kmem may not be opened for writing.
安全模式 - "不可更动"和"只能附加" 的旗标不能被取消; mount 上来的档案系
统, /dev/mem, 和 /dev/kmem 不能写入。

2 Highly secure mode - same as secure mode, plus disks may not be
opened for writing (except by mount(2)) whether mounted or not.
his level precludes tampering with filesystems by unmounting them,
but also inhibits running newfs(Cool while the system is multi-user.
高安全模式 - 和安全模式一样, 又多加了不管硬碟有没有被 mount 起来,
除了 mount(2) 之外都不能写入。它防止一个档案系统在 umount 的时候被
搞乱。而且在这个等级也禁止在 multi-user 时执行 newfs(Cool

如果安全等级最初是 -1, 那麽 init 就会保持原状。否则在 single user mode 时,
init 会把安全等级调到 0, 而在 multiuser mode 时会以 1 来跑。如果你希望在
multiuser 模式是以等级 2 在跑, 你可以先进入 single user mode, 编辑 /etc/rc,
使用 sysctl 来更动。

若是你的系统只拿来跑 web server 之类的, 你可以放心的将 securelevel调高到2。
但若是你要跑 X server, 把你的 securelevel 调至 1 或更高会导致一些问题。因为
X server 必须要写入 /dev/mem 和 /dev/kmem, 而 securelevel 1 不允许你这麽做。
有一个解决的方法是, 在启动 X server 後再调高 securelevel。但我的意见是, 如果
你跑 X server 的话, 你已经有了其它的安全问题须要考量, 而不止是 securelevel。
以下这个指令会显示出你目前的 securelevel 设定值。

# sysctl kern.securelevel


如果要提高你的 securelevel:
# sysctl -w kern.securelevel=X
X 可以是 0, 1 或 2。

又在 securelevel 是 1 的话, 你在 "make world" 时也会有些问题。因为 "make
install" 时会在 kernel 上加上 immutable flag:

# ls -lo /kernel
-r-xr-xr-x 1 root wheel schg 1061679 Jun 30 01:27 /kernel

"schg" flag 会防止你安装新的 kernel:

nfr# id
uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem)

nfr# sysctl kern.securelevel
kern.securelevel: 2

nfr# rm -rf /kernel
rm: /kernel: Operation not permitted

nfr# mv /kernel /tmp/
mv: rename /kernel to /tmp//kernel: Operation not permitted

如果你在 securelevel 1 或 2, 那麽 schg flag 是不能被改变的。

# chflags noschg /kernel
chflags: /kernel: Operation not permitted

值得留意的是, /boot.config 可以改变你开机时的系统设定,要预防有心人篡改
你应该这麽做:

# touch /boot.config
# chflags schg /boot.config

你可以看看系统预设还有那些执行档是有 schg flag 的。

# ls -lo /sbin | grep schg
-r-x------ 1 bin bin schg 204800 Jul 19 20:38 init
# ls -lo /bin | grep schg
-r-sr-xr-x 1 root bin schg 192512 Jul 19 20:36 rcp

再回过头来谈谈锁定系统这件事吧! 既然刚刚谈到了 immutable flags, 何不试着把整
个 /sbin 和 /bin 都设成 schg flag 呢 !? 这会给想 crack你系统的人一点小挫折。
(假设你的系统也正以适当的 securelevel 运作中)

# chflags schg /bin/*
# chflags schg /sbin/*

不过 /sbin 可能被改成别的名字,再重新创造一份新的 /sbin ,所以改变 /sbin 与
/bin 的 schg flag 是很合理的想法,我们可以依照以下的方式改变 /sbin 和 /bin
的 schg flag:

# chflags schg /bin/*
# chflags schg /sbin/*

这些 schg flag 的档案会让你在 "make world" 时有问题。
("make installworld" 也是)

无论如何 ,最好是以 single user 模式来 "make world"。有关 "makr world" 的相
资讯, 还有为什麽要这麽做, 到下面这个网页来看看:

http://www.nothing-going-on.demon.co.uk/FreeBSD/make-world/make-world.html

现在你已经适当的锁定你的系统, 也以只跑必要的的 service, 而档案系统也适当的
mount 上来, 且也以适合的 kernel securelevel 运作中。
与以上所述的相关 man pages 有: init(Cool, chflags(1), sysctl(Cool

o Logging

系统纪录是很重要的。如果你的统被人攻击, 透过它你可以找到一些蛛丝马迹。Unix的
标准 log 动作是透过 syslogd(Cool 来达成的。它从 /etc/rc 中被启动, 一直执行到系
统关机为止。你可以用以下的方式确定你的系统上是否正在执行 syslogd:

$ ps -axu | grep syslogd

Syslogd 会在启动时读取 /etc/syslogd.conf。这个档案很重要, 因为它告诉 syslogd
要纪录那些东西, 而这些东西又该放在那里。你也许想看看 syslod 和 syslod.conf
的 man pages:

$ man syslogd ; man 5 syslog.conf

既然 Unix 当初就是设计作为网路作业系统, syslogd 可以而且预设值也接受其它系统
的纪录。它自己也是可以把纪录透过网路送到其它的电脑去。想当然耳, 它可以纪录下
自己系统发生的每件事 - 而这也正是预设值。因为 syslogd 使用 UDP - 所以资料是
可以被伪造的。你至少可以作一件事: 不要让你的 syslogd 接受来自其它电脑的纪录
讯息。在 /etc/rc.conf 加个 "-s" 就可以了:

syslogd_flags="-s" # Flags to syslogd (if enabled).

如果你有接受特定机器之纪录的必要 (像是你的 router, 或是 web server), 使用
"-a" 来指定特定的 hosts, domains, 或 subnets。
下次你重新启动你的系统时, syslogd便会拒绝来自其它地方的纪录讯息。如果有人尝
试送资料进来, syslogd 将会加以纪录。

如果你不想重新启动你的系统, 那麽只要把 syslogd kill -9, 然後再以 root 的身份
启动 syslogd 便可以了。记得加上 "-s"这个叁数。
如果有人尝试攻击你的系统而且失败了, 你的系统纪录便不会被伪造。但如果你的系统
己经被攻陷了, 而且 /var/log 整个被干掉了呢 !?还是有方法可以防止的。 其一便是
在你的网路系统中再架一台机器拿来纪录整个网路中发生的事, 而且也不要再干其它的
事了。除了 UDP port 514 之外, 其它的也都不用再开了。这样子一来你便可以纪录下
所有机器 (routers, firewalls, serves, workstations) 发生的所有事。你可以只送
敏感的讯息给它, 或者任何你觉得重要的。这台机器可以是老旧 486, 但有颗大大的硬
碟。记得要设定好正确的 "-a" 选项, 免得搞出没收到纪录的乌龙事。你也可以接台老
旧的点阵印表机给它, 以印出敏感的事件(像是失败的登入尝试)。如果你把系统纪录印
到纸上, 一位攻击者要清除它是很困难的(除非有内奸, 哈哈!)。还有其它的方法,例如
透过 serial port (cuaaN) 或是 parallel port (lpN) 送出纪录到别台机器上。

每个人都有不同的记录需求。但是有一件事我通常会做的是在 /etc/syslog.conf 加入
这一行:

auth.* /var/log/authlog

FreeBSD 出厂时便包含了 newsyslog。这玩意会定时压缩纪录档并清除掉旧的纪录。设
定档位於 /etc/newsyslog.conf - 请看一下 man page 以得到更多的资讯:

% man newsyslog

不像 syslogd, newsyslog 不是一直都在执行的。它是从 crontab 启动的:

% grep newsyslog /etc/crontab
0 * * * * root /usr/sbin/newsyslog
%

你可以修改 /etc/newsyslog.conf 以符合你的需求。我通常会改变它预设的档案模式,
从 664 改成 660 - 因为没有必要让一般的使用者去查看你的系统纪录。你应该这麽
做:

# cd /var/log
# chmod g-w,o-r * ; chmod a+r wtmp

这会防止一般使用者读取纪录档, 除非它们在适当的 group (wheel 或之类的)。还有,
记得把记录档的 group 都改成 wheel -- 这纯粹只是为了方便: 如果你是在 wheel 这
个 group; 你当然是可以 su(1) 到 root 然後读记录档。但是这麽做以後你便可以直
接读记录档了, 岂不方便乎!?
你还要在 /etc /newsyslog.conf 中加入 "root.wheel":

/var/log/maillog root.wheel 640 7 100 * Z
/var/log/authlog root.wheel 640 7 100 * Z
/var/log/messages root.wheel 640 7 100 * Z

这会在记录档达到 100K 时将它压缩并加以编号, 将 mode 改成 640, chown 成
root.wheel, 并将旧的记录档干掉 - 这就是我们要的。

当然,标准的 Unix 还有其他不同的 syslog 程式可供选择,其中之一是 CORE EDI 的
ssyslog (secure syslog). 可以在以下的地方找到:

http://www.core-sdi.com/ENGLISH/CoreLabs/ssyslog/download.html

另外还有 nsyslog (new syslog),这是写 bpfilter 那一伙人写出来的,你可以在
http://cheops.anu.edu.au/~avalon/nsyslog.html 找到这个程式。

不管你选用那一种程式 (标准的 syslog , ssyslog ,或 nsyslog),你应该也去看看
一些帮你分析系统 log 的程式,帮你省下去用 grep 查询 log file 的麻烦。

其中之一是 logcheck , 可以在这个地方下载:
http://www.psionic.com/abacus/abacus_logcheck.html

另外一个类似的程式叫做 logsurfer , 你可以从这个网页下载:
http://www.cert.dfn.de/eng/team/wl/logsurf/


o Misc. hints and tips

o LKM

在正式提供服务的系统上, 也许该关掉 LKM。为什麽? 请看:
Phrack Magazine Volume 7, Issue 51 September 01, 1997, article 09
要关掉 LKMs, 在 kernel 设定档中加入这一行:

options NOLKM


o Portmap

FreeBSD 出厂的预设值会将 portmap 这项功能打开。如果你不需要它的话,把它关掉。
如果你没有跑任何需要呼叫 RPC 的程式的话,你就不需要跑这个程式。如果要关掉
portmap 这个程式,你可以去修改 /etc/rc.conf , 把

portmap_enable="YES" # Run the portmapper service (or NO).

改成

portmap_enable="NO" # Run the portmapper service (or NO).


o Sendmail

FreeBSD 出厂的预设值也会执行 sendmail 的功能。从很久以前 sendmail 就以不安全
且漏洞百出闻名。最近人们努力的将 sendmail 中的错误清除,但是由於 sendmail是一
个很肥大的程式,要将所有的错误都抓出来相当的困难。换句话说:如果你不需要它的话
,最好把它关掉。如果你真的需要它的话,最好到 sendmail 的网站去看看有没有新的
patches 或是 hacks, sendmail 的网站在 http://www.sendmail.org
此外,如果你的 sendmail 版本是 8.8 以後的版本,请设定好你的系统,以防止 spammer
利用你的系统去干坏事。设定 anti-spam 的资讯可以在
http://www.sendmail.org/antispam.html 下找到。

如果你决定要把 sendmail 关掉的话,只要去修改 /etc/rc.conf (没错,又是它)中的:

sendmail_enable="YES" # Run the sendmail daemon (or NO).

改成

sendmail_enable="NO" # Run the sendmail daemon (or NO).


o Ports and Packages

在一台高安全性的系统上, 最好不要使用 ports 或 packakges。 你不会真正知道是不
是安装 suid 的程式进你的系统 -- 而且你不会想再多这些 suid 的东西了, 相信我。
尽管你在 pkg_add 时可以使用不同的选项(如 "-v" 或 "-n"), 最好还是自己来: 抓回
它的 source code, 自己 compile, 再手动安装完成。

o Filesystem quota

如果你的系统是 "shell" type server,你可能希望设定使用者的 quota (可用空间)。
如此一来可以保护你的系统免受 Denial of Service 攻击方式的侵扰(不论是有意或
是无意的)。在未设定 quota 的系统上使用者可以随意的灌爆你的硬碟。要把 quota
这项功能打开,你可以修改 /etc/rc.conf 中的这项设定:

check_quotas="NO" # Check quotas (or NO).

改成

check_quotas="YES" # Check quotas (or NO).


请先看看以下的 man page,这些文件说明如何使用 quota 的各项设定,并且有一些设定
的范例: quotaon, edquota, repquota, quota
请确定在 /etc/fstab 中有加入 "userquota" , 详见 man 5 fstab。


o Crontab

如果你使用了 /etc/crontab 的话,这项功能有可能提供入侵者一些额外的资讯。
请确定你做过 "chmod 640 /etc/crontab"


o BPF

BPF 是 berkeley packet filter 的缩写,要使用这项功能前你必须修改 kernel,以达
成监听网路的目的。像 tcpdump 和 NFR 这些程式都使用 BPF。然而 BSD的监听程式
也都透过 BPF 来达成,如果有人拿到你系统的 root 权限的话,在系统上设定 BPF 功
能反而帮助他们更容易的监听你的网路。如果没有必要的话,不要设定 kernel 中 BPF
的功能。 FreeBSD 出厂的设定值是将这个功能关闭起来的。


o CVSup, CVS, 等等

如果你是使用 CD-ROM 安装你的系统的话,很有可能当你拿到你的 CD-ROM时,已经发现
某些程式有错误存在了。在大部份的情况下(我们希望如此),这些错误与系统安全无关
。然而,我建议你将你的系统升级到最新的 -current (或是 -stable,视你的喜好而定)
版本。如此你可以确定你系统上的的是最新版本的系统原始码。
你需要的资讯在这边可以找到:

http://www.freebsd.org/handbook/handbook264.html#508

在更新你作业系统的原始码後你必须去 "make world",详细的文件在:

http://www.nothing-going-on.demon.co.uk/FreeBSD/make-world/make-world.html



o SSH

使用 ssh 以代替 telnet, ftp, rlogin, rsh 等的重要性, 再怎麽强调都是不够的。
对於使用慢速线路的人 (dial-up, 56K frame), ssh 有 -C 选项:

-C Requests compression of all data (including stdin,
stdout, stderr, and data for forwarded X11 and
TCP/IP connections). The compression algorithm is
the same used by gzip, and the "level" can be con-
trolled by the CompressionLevel option (see below).
Compression is desirable on modem lines and other
slow connections, but will only slow down things on
fast networks. The default value can be set on a
host-by-host basis in the configuration files; see
the Compress option below.
将资料压缩後再传出去, 包括了 stdin, stdout, stderr
还有透过 X11 还有 TCP/IP。压缩的演算法同 gzip, 而且
可以指定压缩的 level。对於 moden users 和使用慢速线
路的人, 这功能是不错的。 但有高速线路的人, 这麽搞只
会拖慢速度。在主机对连时可以设预设值, 请再叁照文件。

这会让你用起来快一点 Smile 总之就是用 SSH 就对了啦! 拜托, 拜托, 使用 ssh。 如果
你硬是不信邪, 再也没什麽安全措施可以帮助你了 !!

o Related URLs

FreeBSD Hardening Project:
http://www.watson.org/fbsd-hardening/

FreeBSD ipfw Configuration Page:
http://www.metronet.com/~pgilley/freebsd/ipfw

FreeBSD Security advisories:
ftp://ftp.freebsd.org/pub/FreeBSD/CERT/advisories/

FreeBSD Security web page:
http://www.freebsd.org/security/security.html

Security tools in FreeBSD:
http://www.samag.com/archive/0705/feature.html

o Thanks

对於这份仍在赶工的文件我有许多的感谢。你的批评, 指教, 才让这份文件得以问世。

This post is intented to help those trying to install PHP with Oracle support on FreeBSD. I’ll just note that this setup was tested and implemented in FreeBSD 6.2-STABLE. I also assume that your ports location is /usr/ports.

1. Install necessary FreeBSD ports

  1. Oracle instant client: /usr/ports/databases/linux-oracle-instantclient-basic/
    You’ll need to download a Linux version of instant client from http://www.oracle.com/technology/tech/oci/instantclient/index.html and put it in /usr/ports/distfiles/oracle. The exact version will depend on the freshness of your port revision. At the moment of writing it is “instantclient-basic-linux32-10.2.0.2-20060331.zip”.
  2. Oracle instant client SDK: /usr/ports/databases/linux-oracle-instantclient-sdk/
    Another file for download from Oracle (location and destination are the same like in step 1). File name at the moment of writing is “instantclient-sdk-linux32-10.2.0.2-20060331.zip”.
  3. Oracle8-client: /usr/ports/databases/oracle8-client/
    Unofficial port of Linux version Oracle client. After doing “make install” go to /usr/local/oracle8-client/freebsd. Execute redefine-syms.sh, then - make, make patch and make install. If make fails with redefinition of gethostbyname_r function error, open oci8stub.c for editing and delete the declaration of this function in this file. Now it should compile correctly. After doing make install, symlink /lib/liboci8stub.a to /usr/local/oracle8-client/lib.

2. Environment setup

  1. (optional) Set linker options. If you’re using bash, type: export LDFLAGS=”-lcompat -lpthread”
  2. Set ORACLE_HOME location. If you’re using bash, type: export ORACLE_HOME=”/usr/local/oracle8-client”

3. Install PHP5

  1. Install PHP5 base from /usr/ports/lang/php5 (make && make install)
  2. Install PHP5 extensions from /opt/ports/lang/php5-extensions (make - for typical ncurses menu - simple but very convenient) NOTE: you won’t find OCI8 or other database extensions here - they are located in the other location
  3. Install PHP5-OCI8 extension from /usr/ports/databases/php5-oci8 (you’ll find all other available PHP5 database extensions in /usr/ports/databases)

4. Tips

  1. It is mandatory that ORACLE_HOME environment variable is set to /usr/local/oracle8-client during startup of Apache (or any other web server of your choice).
  2. If you want to use tnsnames.ora then put it into /usr/local/oracle8-client/network/admin. Adjust necessary settings in sqlnet.ora as well.
  3. In some cases setting TNS_ADMIN environment variable to /usr/local/oracle8-client/network/admin is necessary.

Feel free to comment if you encounter any problems with this tutorial.

May 25 14:37:01 www16 postfix/smtpd[88473]: sql_select option missing
May 25 14:37:01 www16 postfix/smtpd[88473]: auxpropfunc error no mechanism available
May 25 14:41:00 www16 postfix/smtpd[88741]: sql_select option missing
May 25 14:41:00 www16 postfix/smtpd[88741]: auxpropfunc error no mechanism available
May 25 14:42:10 www16 postfix/smtpd[88907]: sql_select option missing
May 25 14:42:10 www16 postfix/smtpd[88907]: auxpropfunc error no mechanism available
May 25 14:42:10 www16 postfix/smtpd[88908]: sql_select option missing
May 25 14:42:10 www16 postfix/smtpd[88908]: auxpropfunc error no mechanism available
May 25 14:48:32 www16 postfix/smtpd[89400]: sql_select option missing
May 25 14:48:32 www16 postfix/smtpd[89400]: auxpropfunc error no mechanism available
May 25 14:51:32 www16 postfix/smtpd[89610]: sql_select option missing
May 25 14:51:32 www16 postfix/smtpd[89610]: auxpropfunc error no mechanism available
May 25 14:59:59 www16 postfix/smtpd[90073]: sql_select option missing

系统日志 出现大量的类似日志,虽然不影响使用,但是却扰乱日志记录。

修改smtpd.conf文件的配置,配置如下:

 # cat /usr/local/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
mech_list: plain login
allow_plaintext: true
auxprop_plugin: mysql
authdaemond_path:/var/run/authdaemond/socket
sql_hostnames: localhost
sql_user: postfix
sql_passwd: postfix
sql_database: postfix
sql_select: select password from mailbox where username='%u'

EM64T本质上和AMD64一样都是IA-32的增强版本,Xeon借助于EM64T可实现高达1TB(40bit)的物理内存寻址和256TB (48bit)的虚拟内存寻址,并且良好地支持现有32位x86代码的执行,这一点跟AMD64无异,同时也是Intel开发EM64T的出发点—让现有的x86指令集能够执行64位代码,而继续保持对32位代码的良好兼容。但由于多方面的限制,无论是EM64T还是AMD64均只能实现比32位指令集更大内存空间的寻址,而无法真正做到纯64位指令集的1PB(50bit)和16EB(64bit)的物理内存和虚拟内存寻址(IA-64就能做到这一点),其关键在于EM64T和AMD64本质上仍是基于32位的x86指令集,只是Intel和AMD分别采用不同的技术手段对x86指令集进行扩展,从而实现对64位的支持

和AMD64一样,EM64T由于要在同时运行32位和64位程序,因此会针对不同的需要运行于不同的操作模式,同时其引入的多种操作模式之间的切换较为成功地解决了32位程序在64位操作系统下的运行效率问题,当中包括了传统模式、兼容模式和纯64位模式。

-----传统模式(Legacy Mode)-----

这种模式是为了令64位Xeon能没有障碍地执行现有的32位和16位程序而设计的,实际上就是32位x86时代的IA-32模式,此时现有 x86程序无需作任何的改变,和我们目前使用着的32位环境一模一样。因为Nacona Xeon的核心仍然是沿着32位设计的,所以这个模式只是把所有为64位计算而新增的运算机制都屏蔽起来。

-----兼容模式(Compatibility Mode)-----

兼容模式允许64位操作系统(如Windows XP x64 Edition)良好地运行基于32位和16位代码的程序,此时32位程序无需重编译即可以保护模式运行,而16位程序则要依赖于操作系统和驱动程序是否支持保护模式,情况类似于32位环境下的IA-32虚拟实模式。和传统模式相同,兼容模式允许程序利用物理内存扩展实现64GB的物理内存寻址,但这并非纯64位模式的准64位寻址。

-----纯64位模式(Full 64bit Mode)-----



此模式是三种模式当中最为高效的,同时可充分发挥EM64T的威力,但这种模式需要纯64位环境的支持,包括64位操作系统和64位应用程序。在64位操作系统和相应驱动程序的支持下,系统和应用程序能够访问EM64T所支持最大容量的扩展内存,这时Xeon平台的性能可得到最充分的发挥,当然运行于此模式下的程序需要修改其微代码以便支持64位指令操作。

可以预见,在未来相当长的一段时间里,在64位操作系统下我们最常用的是兼容模式,因为现存的大量32位应用程序不可能在短期内为x86-64指令集而重新开发,为了保证现有的32位程序能够继续在Xeon平台上顺利执行,EM64T提供了一种出色的解决方案。而对于传统的32位操作系统和应用程序, Xeon平台当然可以百分百地相容运行,本来EM64T就是扩展的32位x86指令集,兼容32位程序是件很自然的事。

EM64T在64位的实现方式上跟AMD64指令集有很多相似之处,但在关键的地方两者还是有很大差别,而Intel追加的大多数64位指令与AMD64 指令集相兼容,因此Microsoft就不用为两家公司的64位处理器开发各自的64位操作系统。目前Microsoft推出的Windows XP x64 Edition操作系统(Beta)可同时支持EM64T和AMD64,能够兼容几乎所有的32位应用程序和大部分新增64位应用程序。

浅谈 EM64T技术和AMD64区别

X86-64 (AMD64 / EM64T)

AMD公司设计,可以在同一时间内处理64位的整数运算,并兼容于X86-32架构。其中支持64位逻辑定址,同时提供转换为32位定址选项;但数据操作指令默认为32位和8位,提供转换成64位和16位的选项;支持常规用途寄存器,如果是32位运算操作,就要将结果扩展成完整的64位。这样,指令中有 “直接执行”和“转换执行”的区别,其指令字段是8位或32位,可以避免字段过长。

x86-64(AMD64)的产生也并非空穴来风,x86处理器的32bit寻址空间限制在4GB内存,而IA-64的处理器又不能兼容x86。AMD充分考虑顾客的需求,加强x86指令集的功能,使这套指令集可同时支持64位的运算模式,因此AMD把它们的结构称之为x86-64。在技术上AMD在 x86-64架构中为了进行64位运算,AMD为其引入了新增了R8-R15通用寄存器作为原有X86处理器寄存器的扩充,但在而在32位环境下并不完全使用到这些寄存器。原来的寄存器诸如EAX、EBX也由32位扩张至64位。在SSE单元中新加入了8个新寄存器以提供对SSE2的支持。寄存器数量的增加将带来性能的提升。与此同时,为了同时支持32和64位代码及寄存器,x86-64架构允许处理器工作在以下两种模式:Long Mode(长模式)和Legacy Mode(遗传模式),Long模式又分为两种子模式(64bit模式和Compatibility mode兼容模式)。该标准已经被引进在AMD服务器处理器中的Opteron处理器。

而今年也推出了支持64位的EM64T技术,再还没被正式命为EM64T之前是IA32E,这是英特尔64位扩展技术的名字,用来区别X86指令集。 Intel的EM64T支持64位sub-mode,和AMD的X86-64技术类似,采用64位的线性平面寻址,加入8个新的通用寄存器(GPRs),还增加8个寄存器支持SSE指令。与AMD相类似,Intel的64位技术将兼容IA32和IA32E,只有在运行64位操作系统下的时候,才将会采用 IA32E。IA32E将由2个sub-mode组成:64位sub-mode和32位sub-mode,同AMD64一样是向下兼容的。Intel的 EM64T将完全兼容AMD的X86-64技术。现在Nocona处理器已经加入了一些64位技术,Intel的Pentium 4E处理器也支持64位技术。

应该说,这两者都是兼容x86指令集的64位微处理器架构,但EM64T与AMD64还是有一些不一样的地方,AMD64处理器中的NX位在Intel的处理器中将没有提供。

一个小孩说:
AMD 的AM2 X2就是用AM2接口的双核处理器;AMD X2就是以939为接口的双核处理器,AMD的AM2 CPU是AM2接口的单核处理器

Core(酷睿)微体系架构,其针对桌面、笔记本和服务器推出的产品代号分别是,Conroe、Merom和Woodcrest,都拥有64位处理能力,并且是双核产品。
(Conroe扣肉
Merom猫肉
Woodcrest服务器上用的)
These `-m' options are defined for the i386 and x86-64 family of computers:

-mtune=cpu-type
Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions. The choices for cpu-type are:

generic
Produce code optimized for the most common IA32/AMD64/EM64T processors. If you know the CPU on which your code will run, then you should use the corresponding -mtune option instead of -mtune=generic. But, if you do not know exactly what CPU users of your application will have, then you should use this option.

As new processors are deployed in the marketplace, the behavior of this option will change. Therefore, if you upgrade to a newer version of GCC, the code generated option will change to reflect the processors that were most common when that version of GCC was released.

There is no -march=generic option because -march indicates the instruction set the compiler can use, and there is no generic instruction set applicable to all processors. In contrast, -mtune indicates the processor (or, in this case, collection of processors) for which the code is optimized.
native
This selects the CPU to tune for at compilation time by determining the processor type of the compiling machine. Using -mtune=native will produce code optimized for the local machine under the constraints of the selected instruction set. Using -march=native will enable all instruction subsets supported by the local machine (hence the result might not run on different machines).
i386
Original Intel's i386 CPU.
i486
Intel's i486 CPU. (No scheduling is implemented for this chip.)
i586, pentium
Intel Pentium CPU with no MMX support.
pentium-mmx
Intel PentiumMMX CPU based on Pentium core with MMX instruction set support.
pentiumpro
Intel PentiumPro CPU.
i686
Same as generic, but when used as march option, PentiumPro instruction set will be used, so the code will run on all i686 family chips.
pentium2
Intel Pentium2 CPU based on PentiumPro core with MMX instruction set support.
pentium3, pentium3m
Intel Pentium3 CPU based on PentiumPro core with MMX and SSE instruction set support.
pentium-m
Low power version of Intel Pentium3 CPU with MMX, SSE and SSE2 instruction set support. Used by Centrino notebooks.
pentium4, pentium4m
Intel Pentium4 CPU with MMX, SSE and SSE2 instruction set support.
prescott
Improved version of Intel Pentium4 CPU with MMX, SSE, SSE2 and SSE3 instruction set support.
nocona
Improved version of Intel Pentium4 CPU with 64-bit extensions, MMX, SSE, SSE2 and SSE3 instruction set support.
core2
Intel Core2 CPU with 64-bit extensions, MMX, SSE, SSE2, SSE3 and SSSE3 instruction set support.
k6
AMD K6 CPU with MMX instruction set support.
k6-2, k6-3
Improved versions of AMD K6 CPU with MMX and 3dNOW! instruction set support.
athlon, athlon-tbird
AMD Athlon CPU with MMX, 3dNOW!, enhanced 3dNOW! and SSE prefetch instructions support.
athlon-4, athlon-xp, athlon-mp
Improved AMD Athlon CPU with MMX, 3dNOW!, enhanced 3dNOW! and full SSE instruction set support.
k8, opteron, athlon64, athlon-fx
AMD K8 core based CPUs with x86-64 instruction set support. (This supersets MMX, SSE, SSE2, 3dNOW!, enhanced 3dNOW! and 64-bit instruction set extensions.)
k8-sse3, opteron-sse3, athlon64-sse3
Improved versions of k8, opteron and athlon64 with SSE3 instruction set support.
amdfam10, barcelona
AMD Family 10h core based CPUs with x86-64 instruction set support. (This supersets MMX, SSE, SSE2, SSE3, SSE4A, 3dNOW!, enhanced 3dNOW!, ABM and 64-bit instruction set extensions.)
winchip-c6
IDT Winchip C6 CPU, dealt in same way as i486 with additional MMX instruction set support.
winchip2
IDT Winchip2 CPU, dealt in same way as i486 with additional MMX and 3dNOW! instruction set support.
c3
Via C3 CPU with MMX and 3dNOW! instruction set support. (No scheduling is implemented for this chip.)
c3-2
Via C3-2 CPU with MMX and SSE instruction set support. (No scheduling is implemented for this chip.)
geode
Embedded AMD CPU with MMX and 3dNOW! instruction set support.

While picking a specific cpu-type will schedule things appropriately for that particular chip, the compiler will not generate any code that does not run on the i386 without the -march=cpu-type option being used.
-march=cpu-type
Generate instructions for the machine type cpu-type. The choices for cpu-type are the same as for -mtune. Moreover, specifying -march=cpu-type implies -mtune=cpu-type.
-mcpu=cpu-type
A deprecated synonym for -mtune.
-mfpmath=unit
Generate floating point arithmetics for selected unit unit. The choices for unit are:

`387'
Use the standard 387 floating point coprocessor present majority of chips and emulated otherwise. Code compiled with this option will run almost everywhere. The temporary results are computed in 80bit precision instead of precision specified by the type resulting in slightly different results compared to most of other chips. See -ffloat-store for more detailed description.

This is the default choice for i386 compiler.
`sse'
Use scalar floating point instructions present in the SSE instruction set. This instruction set is supported by Pentium3 and newer chips, in the AMD line by Athlon-4, Athlon-xp and Athlon-mp chips. The earlier version of SSE instruction set supports only single precision arithmetics, thus the double and extended precision arithmetics is still done using 387. Later version, present only in Pentium4 and the future AMD x86-64 chips supports double precision arithmetics too.

For the i386 compiler, you need to use -march=cpu-type, -msse or -msse2 switches to enable SSE extensions and make this option effective. For the x86-64 compiler, these extensions are enabled by default.

The resulting code should be considerably faster in the majority of cases and avoid the numerical instability problems of 387 code, but may break some existing code that expects temporaries to be 80bit.

This is the default choice for the x86-64 compiler.
`sse,387'
Attempt to utilize both instruction sets at once. This effectively double the amount of available registers and on chips with separate execution units for 387 and SSE the execution resources too. Use this option with care, as it is still experimental, because the GCC register allocator does not model separate functional units well resulting in instable performance.


-masm=dialect
Output asm instructions using selected dialect. Supported choices are `intel' or `att' (the default one). Darwin does not support `intel'.
-mieee-fp
-mno-ieee-fp
Control whether or not the compiler uses IEEE floating point comparisons. These handle correctly the case where the result of a comparison is unordered.
-msoft-float
Generate output containing library calls for floating point. Warning: the requisite libraries are not part of GCC. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation.

On machines where a function returns floating point results in the 80387 register stack, some floating point opcodes may be emitted even if -msoft-float is used.
-mno-fp-ret-in-387
Do not use the FPU registers for return values of functions.

The usual calling convention has functions return values of types float and double in an FPU register, even if there is no FPU. The idea is that the operating system should emulate an FPU.

The option -mno-fp-ret-in-387 causes such values to be returned in ordinary CPU registers instead.
-mno-fancy-math-387
Some 387 emulators do not support the sin, cos and sqrt instructions for the 387. Specify this option to avoid generating those instructions. This option is the default on FreeBSD, OpenBSD and NetBSD. This option is overridden when -march indicates that the target cpu will always have an FPU and so the instruction will not need emulation. As of revision 2.6.1, these instructions are not generated unless you also use the -funsafe-math-optimizations switch.
-malign-double
-mno-align-double
Control whether GCC aligns double, long double, and long long variables on a two word boundary or a one word boundary. Aligning double variables on a two word boundary will produce code that runs somewhat faster on a `Pentium' at the expense of more memory.

On x86-64, -malign-double is enabled by default.

Warning: if you use the -malign-double switch, structures containing the above types will be aligned differently than the published application binary interface specifications for the 386 and will not be binary compatible with structures in code compiled without that switch.
-m96bit-long-double
-m128bit-long-double
These switches control the size of long double type. The i386 application binary interface specifies the size to be 96 bits, so -m96bit-long-double is the default in 32 bit mode.

Modern architectures (Pentium and newer) would prefer long double to be aligned to an 8 or 16 byte boundary. In arrays or structures conforming to the ABI, this would not be possible. So specifying a -m128bit-long-double will align long double to a 16 byte boundary by padding the long double with an additional 32 bit zero.

In the x86-64 compiler, -m128bit-long-double is the default choice as its ABI specifies that long double is to be aligned on 16 byte boundary.

Notice that neither of these options enable any extra precision over the x87 standard of 80 bits for a long double.

Warning: if you override the default value for your target ABI, the structures and arrays containing long double variables will change their size as well as function calling convention for function taking long double will be modified. Hence they will not be binary compatible with arrays or structures in code compiled without that switch.
-mmlarge-data-threshold=number
When -mcmodel=medium is specified, the data greater than threshold are placed in large data section. This value must be the same across all object linked into the binary and defaults to 65535.
-mrtd
Use a different function-calling convention, in which functions that take a fixed number of arguments return with the ret num instruction, which pops their arguments while returning. This saves one instruction in the caller since there is no need to pop the arguments there.

You can specify that an individual function is called with this calling sequence with the function attribute `stdcall'. You can also override the -mrtd option by using the function attribute `cdecl'. See Function Attributes.

Warning: this calling convention is incompatible with the one normally used on Unix, so you cannot use it if you need to call libraries compiled with the Unix compiler.

Also, you must provide function prototypes for all functions that take variable numbers of arguments (including printf); otherwise incorrect code will be generated for calls to those functions.

In addition, seriously incorrect code will result if you call a function with too many arguments. (Normally, extra arguments are harmlessly ignored.)
-mregparm=num
Control how many registers are used to pass integer arguments. By default, no registers are used to pass arguments, and at most 3 registers can be used. You can control this behavior for a specific function by using the function attribute `regparm'. See Function Attributes.

Warning: if you use this switch, and num is nonzero, then you must build all modules with the same value, including any libraries. This includes the system libraries and startup modules.
-msseregparm
Use SSE register passing conventions for float and double arguments and return values. You can control this behavior for a specific function by using the function attribute `sseregparm'. See Function Attributes.

Warning: if you use this switch then you must build all modules with the same value, including any libraries. This includes the system libraries and startup modules.
-mpc32
-mpc64
-mpc80
Set 80387 floating-point precision to 32, 64 or 80 bits. When -mpc32 is specified, the significands of results of floating-point operations are rounded to 24 bits (single precision); -mpc64 rounds the the significands of results of floating-point operations to 53 bits (double precision) and -mpc80 rounds the significands of results of floating-point operations to 64 bits (extended double precision), which is the default. When this option is used, floating-point operations in higher precisions are not available to the programmer without setting the FPU control word explicitly.

Setting the rounding of floating-point operations to less than the default 80 bits can speed some programs by 2% or more. Note that some mathematical libraries assume that extended precision (80 bit) floating-point operations are enabled by default; routines in such libraries could suffer significant loss of accuracy, typically through so-called "catastrophic cancellation", when this option is used to set the precision to less than extended precision.
-mstackrealign
Realign the stack at entry. On the Intel x86, the -mstackrealign option will generate an alternate prologue and epilogue that realigns the runtime stack. This supports mixing legacy codes that keep a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility. The alternate prologue and epilogue are slower and bigger than the regular ones, and the alternate prologue requires an extra scratch register; this lowers the number of registers available if used in conjunction with the regparm attribute. The -mstackrealign option is incompatible with the nested function prologue; this is considered a hard error. See also the attribute force_align_arg_pointer, applicable to individual functions.
-mpreferred-stack-boundary=num
Attempt to keep the stack boundary aligned to a 2 raised to num byte boundary. If -mpreferred-stack-boundary is not specified, the default is 4 (16 bytes or 128 bits).

On Pentium and PentiumPro, double and long double values should be aligned to an 8 byte boundary (see -malign-double) or suffer significant run time performance penalties. On Pentium III, the Streaming SIMD Extension (SSE) data type __m128 may not work properly if it is not 16 byte aligned.

To ensure proper alignment of this values on the stack, the stack boundary must be as aligned as that required by any value stored on the stack. Further, every function must be generated such that it keeps the stack aligned. Thus calling a function compiled with a higher preferred stack boundary from a function compiled with a lower preferred stack boundary will most likely misalign the stack. It is recommended that libraries that use callbacks always use the default setting.

This extra alignment does consume extra stack space, and generally increases code size. Code that is sensitive to stack space usage, such as embedded systems and operating system kernels, may want to reduce the preferred alignment to -mpreferred-stack-boundary=2.
-mmmx
-mno-mmx
-msse
-mno-sse
-msse2
-mno-sse2
-msse3
-mno-sse3
-mssse3
-mno-ssse3
-msse4.1
-mno-sse4.1
-msse4.2
-mno-sse4.2
-msse4
-mno-sse4
-msse4a
-mno-sse4a
-msse5
-mno-sse5
-m3dnow
-mno-3dnow
-mpopcnt
-mno-popcnt
-mabm
-mno-abm
These switches enable or disable the use of instructions in the MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4A, SSE5, ABM or 3DNow! extended instruction sets. These extensions are also available as built-in functions: see X86 Built-in Functions, for details of the functions enabled and disabled by these switches.

To have SSE/SSE2 instructions generated automatically from floating-point code (as opposed to 387 instructions), see -mfpmath=sse.

These options will enable GCC to use these extended instructions in generated code, even without -mfpmath=sse. Applications which perform runtime CPU detection must compile separate files for each supported architecture, using the appropriate flags. In particular, the file containing the CPU detection code should be compiled without these options.
-mcx16
This option will enable GCC to use CMPXCHG16B instruction in generated code. CMPXCHG16B allows for atomic operations on 128-bit double quadword (or oword) data types. This is useful for high resolution counters that could be updated by multiple processors (or cores). This instruction is generated as part of atomic built-in functions: see Atomic Builtins for details.
-msahf
This option will enable GCC to use SAHF instruction in generated 64-bit code. Early Intel CPUs with Intel 64 lacked LAHF and SAHF instructions supported by AMD64 until introduction of Pentium 4 G1 step in December 2005. LAHF and SAHF are load and store instructions, respectively, for certain status flags. In 64-bit mode, SAHF instruction is used to optimize fmod, drem or remainder built-in functions: see Other Builtins for details.
-mrecip
This option will enable GCC to use RCPSS and RSQRTSS instructions (and their vectorized variants RCPPS and RSQRTPS) instead of DIVSS and SQRTSS (and their vectorized variants). These instructions will be generated only when -funsafe-math-optimizations is enabled.
-mveclibabi=type
Specifies the ABI type to use for vectorizing intrinsics using an external library. Supported types are acml for the AMD math core library style of interfacing. GCC will currently emit calls to __vrd2_sin, __vrd2_cos, __vrd2_exp, __vrd2_log, __vrd2_log2, __vrd2_log10, __vrs4_sinf, __vrs4_cosf, __vrs4_expf, __vrs4_logf, __vrs4_log2f, __vrs4_log10f and __vrs4_powf when using this type and -ftree-vectorize is enabled. A ACML ABI compatible library will have to be specified at link time.
-mpush-args
-mno-push-args
Use PUSH operations to store outgoing parameters. This method is shorter and usually equally fast as method using SUB/MOV operations and is enabled by default. In some cases disabling it may improve performance because of improved scheduling and reduced dependencies.
-maccumulate-outgoing-args
If enabled, the maximum amount of space required for outgoing arguments will be computed in the function prologue. This is faster on most modern CPUs because of reduced dependencies, improved scheduling and reduced stack usage when preferred stack boundary is not equal to 2. The drawback is a notable increase in code size. This switch implies -mno-push-args.
-mthreads
Support thread-safe exception handling on `Mingw32'. Code that relies on thread-safe exception handling must compile and link all code with the -mthreads option. When compiling, -mthreads defines -D_MT; when linking, it links in a special thread helper library -lmingwthrd which cleans up per thread exception handling data.
-mno-align-stringops
Do not align destination of inlined string operations. This switch reduces code size and improves performance in case the destination is already aligned, but GCC doesn't know about it.
-minline-all-stringops
By default GCC inlines string operations only when destination is known to be aligned at least to 4 byte boundary. This enables more inlining, increase code size, but may improve performance of code that depends on fast memcpy, strlen and memset for short lengths.
-minline-stringops-dynamically
For string operation of unknown size, inline runtime checks so for small blocks inline code is used, while for large blocks library call is used.
-mstringop-strategy=alg
Overwrite internal decision heuristic about particular algorithm to inline string operation with. The allowed values are rep_byte, rep_4byte, rep_8byte for expanding using i386 rep prefix of specified size, byte_loop, loop, unrolled_loop for expanding inline loop, libcall for always expanding library call.
-momit-leaf-frame-pointer
Don't keep the frame pointer in a register for leaf functions. This avoids the instructions to save, set up and restore frame pointers and makes an extra register available in leaf functions. The option -fomit-frame-pointer removes the frame pointer for all functions which might make debugging harder.
-mtls-direct-seg-refs
-mno-tls-direct-seg-refs
Controls whether TLS variables may be accessed with offsets from the TLS segment register (%gs for 32-bit, %fs for 64-bit), or whether the thread base pointer must be added. Whether or not this is legal depends on the operating system, and whether it maps the segment to cover the entire TLS area.

For systems that use GNU libc, the default is on.
-mfused-madd
-mno-fused-madd
Enable automatic generation of fused floating point multiply-add instructions if the ISA supports such instructions. The -mfused-madd option is on by default. The fused multiply-add instructions have a different rounding behavior compared to executing a multiply followed by an add.

These `-m' switches are supported in addition to the above on AMD x86-64 processors in 64-bit environments.

-m32
-m64
Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture. For darwin only the -m64 option turns off the -fno-pic and -mdynamic-no-pic options.
-mno-red-zone
Do not use a so called red zone for x86-64 code. The red zone is mandated by the x86-64 ABI, it is a 128-byte area beyond the location of the stack pointer that will not be modified by signal or interrupt handlers and therefore can be used for temporary data without adjusting the stack pointer. The flag -mno-red-zone disables this red zone.
-mcmodel=small
Generate code for the small code model: the program and its symbols must be linked in the lower 2 GB of the address space. Pointers are 64 bits. Programs can be statically or dynamically linked. This is the default code model.
-mcmodel=kernel
Generate code for the kernel code model. The kernel runs in the negative 2 GB of the address space. This model has to be used for Linux kernel code.
-mcmodel=medium
Generate code for the medium model: The program is linked in the lower 2 GB of the address space but symbols can be located anywhere in the address space. Programs can be statically or dynamically linked, but building of shared libraries are not supported with the medium model.
-mcmodel=large
Generate code for the large model: This model makes no assumptions about addresses and sizes of sections.
# Example smsd.conf. Read the manual for a description

devices = GSM1
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
incoming = /var/spool/sms/incoming
#sent = /var/spool/sms/sent
mypath = /usr/local/bin
logfile = /var/log/smsd.log
loglevel = 7
#alarmhandler = /usr/local/bin/alarmevent
alarmlevel = 4
delaytime = 10
errorsleeptime = 10
blocktime = 3600
#eventhandler = /usr/local/bin/smsevent
#stats = /var/log/smsd_stats
#stats_interval = 3600
#stats_no_zeroes = no
#blacklist = /etc/smsd.black
#whitelist = /etc/smsd.white
#checkhandler = /usr/local/bin/smscheck
receive_before_send = no
# autosplit 0=no 1=yes 2=with text numbers 3=concatenated
autosplit = 3

[queues]
# Commented lines are examples for germany
# D1 = /var/spool/sms/D1
# D2 = /var/spool/sms/D2
# O2 = /var/spool/sms/O2
# EPLUS = /var/spool/sms/EPLUS
# QUAM = /var/sppol/sms/QUAM
# MOBILCOM = /var/spool/sms/MOBILCOM
OTHER = /var/spool/sms/OTHER

[provider]
# Commented lines are examples for germany
# D1 = 49160, 49170, 49171, 49175, 49151
# D2 = 491520, 49162, 49172, 49173, 49174
# O2 = 49176, 49179, 49159
# EPLUS = 49163, 49177, 49178, 49157
# QUAM = 49150
OTHER = 0,1,2,3,4,5,6,7,8,9

[GSM1]
#init = ATE0+CPMS="SM"+CNMI=2,0,0,2,1
# Windows: /dev/com1, Solaris: /dev/cua/a, Linux /dev/ttyS0
device = /dev/cuad0
#device = /dev/ttyS0
incoming = no
queues = OTHER
#You don't need a PIN for mobile phones
#pin = 1111
#mode = old
mode = new
#smsc = 8613800100500
baudrate = 9600
#baudrate = 19200
rtscts = yes
cs_convert = yes
report = no
memory_start = 1
#eventhandler = /usr/local/bin/smsevent

 

使用gnome当桌面的时候,普通用户不能关机。

#chmod +s /sbin/halt
这样,普通用户使用 /sbin/halt -p能够关机了。可是,在gnome的注销里面还是没有关机的选项,如下动作可以添加:
#mkdir -p /var/run/console
#touch /var/run/console/USERNAME

近日在调试6.3下bind9。发现怎么性能竟然下降了一半不止,搞的很郁闷。

经过多次重新编译安装,发现竟然是线程搞的鬼。加了 --enable-threads 参数编译,在6.3下,bind9的性能下降60%左右。测试时,只有1400qps/s左右。而不加线程参数,4000qps/s左右。

差异非常大。

同样的测试,在FreeBSD7.0下,开启线程要增加10%左右的性能。

1:问题的提出:

  经常出现:

  calcru: runtime went backwards from 8370817 usec to 8370811 usec for pid 435 (vmware-guestd)

  
 
经查找,得到解决办法:
2:问题产生原因:
The problem is likely that WMware doesn't correctly simulate the
timer we use to tickle softclock.

3:解决办法:
"sysctl kern.timecounter.hardware=TSC" may help you, if kernel uses ACPI-fast as a timecounter.

4:效果:
使用root执行了以下命令:

#sysctl kern.timecounter.hardware=TSC

kern.timecounter.hardware: ACPI-safe --> TSC
现在,系统不再出现calcru的提示了。

之前2.3.x版本不能上QQ,今天发现ports已经更新到2.4.0版本。就升级到最新版本。

尝试性的登录下QQ,竟然登录上去了。呵呵

等待,等待TX再次封QQ。

1 2 3 4 5  下一篇»