Fedora 15 的 hostname 问题

December 29th, 2011

今天在 Fedora 15 上编译 java 应用,报下面的错误:

Failed to get local hostname java.net.UnknownHostException: tmypc: tmypc: Name or service not known
......

我的 /etc/sysconfit/network 文件中的 HOSTNAME=tmypc,但是 /etc/hosts 文件里没有 tmypc 的配置,加上就一切正常了,如下:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 tmypc
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 tmypc

在 Fedora 12 下没有这个问题,默认会吧 tmypc 加到 /etc/hosts 下,Fedora 15没有加,不知是 Bug 还是我的安装配置有问题。

Tags:
Posted in Technology | No Comments »

ssh 服务连接慢的问题

December 27th, 2011

新配的一台 Centos 6.2 服务器,通过 ssh 对其进行连接时很慢,如果成功登录,后面的操作就一切正常了。
先打开 Verbose 看下在慢在那一步:

[tommy@tmypc ~]$ ssh -v -l tommy 192.168.0.1
.....
debug1: SSH2_MSG_SERVICE_ACCEPT received

上面这句等待的时间最长,google 了一下,在服务器上做如下修改:

[tommy@t ~]# sudo vi /etc/ssh/sshd_config 
#查找 UseDNS,改为
UseDNS no
 
#此外如果你有下面的提示
Address 192.168.0.1 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
可以把 sshd_config 中的 GSSAPIAuthentication 改为
GSSAPIAuthentication no

重启 ssd 服务

[tommy@t ~]# sudo service sshd restart

Tags:
Posted in Technology | No Comments »

在 RHEL 6 上为 Cisco ASA 配置日志服务器

December 27th, 2011

最近 CISCO ASA 偶尔出现 inside , outside 同时阻塞的情况,需要配一个日志服务器来记录 ASA的日志,以便我分析问题的原因。配置服务器端,操作系统为 rhel 6.0。
在 /var/log 目录创建一个 ASA 使用的日志文件。

[tommy@t ~]$ sudo touch /var/log/cisco-asa.log

修改 rsyslog.conf

[tommy@t ~]$ sudo vi /etc/rsyslog.conf
 
# Provides UDP syslog reception
$ModLoad imudp.so
$UDPServerRun 514
 
# Cisco ASA Logging
:fromhost-ip, isequal, "x.x.x.x" /var/log/cisco-asa.log
& ~

上边语句第一部分,只需要打开两行注释,让其监听 UDP 的 514 端口,第二部分要增加到文件中,x.x.x.x 是防火墙的 IP,别漏了 & ~,很关键。

修改防火墙配置,放行 UDP 514

[tommy@t ~]$ sudo vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m udp -p udp --dport 514 -j ACCEPT

重启服务

[tommy@t ~]$ sudo service iptables restart
[tommy@t ~]$ sudo service iptables rsyslog

看看是否开始正常监听端口

[tommy@t ~]$ sudo lsof -i:514

配置 CISCO ASA

ASA-IDC# conf t
ASA-IDC(config)# logging enable
ASA-IDC(config)# logging host inside x.x.x.x
ASA-IDC(config)# logging trap 3
ASA-IDC(config)# exit
ASA-IDC# wr m

上面的 inside 日志发出的接口名称, x.x.x.x 是日志服务器的 IP,如果不嫌日志量大,可以改为 trap 4级别。

最后登录到日志服务器,看看日志是否已经过来了。

[tommy@t ~]$ tail -f /var/log/cisco-asa.log

参考文档
~~~~~~~
[1] http://blog.migrationking.com/2011/02/configure-red-hat-enterprise-linux-6.html
[2] http://www.ehow.com/how_6628293_configure-5505-use-syslog-server.html

Tags: ,
Posted in Technology | No Comments »

Android 手机

October 25th, 2011

前几天关注了一下 android 4 发布, 勾起了我对这个系统的兴趣, 周末一冲动去中关村淘了一个 naxus s 回来, 全部2400, 兄弟们都说划算。手机默认装的是 android 2.3.3,配好 wifi,自动升级到 2.3.6,之后就一直在网上商店逛,下载了不少有趣的应用。昨天更是买了一个联通的 3g 号,打算彻底加入 3g行列。

由于之前用的手机一直是几百块钱的飞利浦待机王,总是夸自己的手机有个性,实用性强,并坚持不用智能手机,所以同事对我的转变分析结果就是,外面有情债,所以打着换手机得名义换手机号!!其实之前不用智能手机的主要原因就是费电,经常忘记充电,耽误了不少事,这次买 naxus s 一口气买了 1个车载充电器, 2条usb充电线, 再加上自带的充电器一共4个,应该够用了。

对于 android 我最喜欢的是邮件管理功能,对于我这种邮箱超多,邮件超多的人来说简直是太方便了,通讯录与gmail的地址簿同步的也非常好。此外还装了一个 ssh 工具,方便我处理突发的服务器问题。
希望开源的 android 的越走越好。

Tags:
Posted in Inspire | No Comments »

Cisco ASA 5520 上的 MSS 超限问题

September 23rd, 2011

前段时间给公司换了新的防火墙 Cisco ASA 5520,发现 Webmail 有时会出现无法发送邮件的问题。ASA 上的日志记录如下:

Sep 22 2011 18:05:36: %ASA-4-419001: Dropping TCP packet from outside:1.1.1.1/43403 to inside:2.2.2.2/80, reason: MSS exceeded, MSS 1380, data 1428

1.1.1.1 是 client,2.2.2.2 是 Mail Server,说明从 client 到 server发送了一个 MSS 大小为 1428 的 tcp 包,超过了防火墙规定的 MSS 最大值 1380。在解决这个问题之前,先给自己普及一下网络基础知识。

  • MTU : Maxitum Transmission Unit 最大传输单元,大部分设备的 MTU 都是 1500,包括我们目前使用的 Cisco ASA 和 Mail Server。
  • MSS : Maxitum Segment Size 最大分段大小,也就是TCP数据包每次能够传输的最大数据分段。为了达到最佳的传输效能 TCP 协议在建立连接的时候通常要协商双方的 MSS 值,这个值TCP 协议在实现的时候往往用 MTU 值代替(需要减去IP数据包包头的大小 20Bytes 和 TCP 数据段的包头 20Bytes)所以往往 MSS 为1460。通讯双方会根据双方提供的 MSS 值得最小值确定为这次连接的最大MSS值。

我们的 ASA 使用默认的 Tunneled MSS ,大小为 1380 (MTU-120),如果是普通的 Ethernet MSS 应该是 1460 (MTU-40)。通过 ping -l 测了一下 1.1.1.1 的 MSS 是 1428, 2.2.2.2 的 MSS 是 1460,进行 TCP 通讯时,1.1.1.1 发送一个 1428 大小的包应该是合法的,注意我们的应用要求不能分片(DF),当这个包通过防火墙时,由于防火墙的 MSS 是 1380,所以根据默认的策略会直接被 drop 掉。

可以通过如下方法解决这个问题:
让防火墙不做检测,即使有 MSS 大于 1380的包,也直接放行。在 ASA 上做如下设置

ASA-IDC(config)# access-list MSS_Exceeded_ACL extended permit tcp any any
ASA-IDC(config)# tcp-map mss-map
ASA-IDC(config-tcp-map)# exceed-mss allow
ASA-IDC(config-tcp-map)# exit
 
ASA-IDC(config)# class-map MSS_Exceeded_MAP
ASA-IDC(config-cmap)# match access-list MSS_Exceeded_ACL
ASA-IDC(config-cmap)# exit
 
ASA-IDC(config)# policy-map global_policy
ASA-IDC(config-pmap)# class MSS_Exceeded_MAP
ASA-IDC(config-pmap-c)# set connection advanced-options mss-map
ASA-IDC(config-pmap-c)# end
 
ASA-IDC(config)# wr m

或者设置 2.2.2.2 的 MSS 值,让它小于 1380,这样 1.1.1.1 在与它协商后,会发送 MSS 小于 1380 的包。

参考文档
~~~~~~~
[1] http://www.cisco.com/en/US/products/ps6120/products_configuration_example09186a008081e621.shtml
[2] http://www.cisco.com/en/US/products/hw/vpndevc/ps2030/products_tech_note09186a00804c8b9f.shtml#wa
[3] http://www.scotech.com/kb/?id=1231299060
[4] http://infotech.blog.51cto.com/391844/123859

Tags: ,
Posted in Technology | No Comments »

Fedora 上安装支持 IPSec 的 VPN 客户端

September 2nd, 2011

之前在 PIX 525 上一直使用 pptp 来做 VPN,近期打算换防火墙,目前 Cisco 的主流防火墙是 ASA 5500 系列,
这个防火墙的 ios 都在 7.2 以上,不知为什么,之后的版本已经不再支持 pptp 协议了,也许是安全性的问题吧。
只能使用 Cisco ASA 推荐的 IPSec VPN 隧道。目前在 linux 上支持 IPSec 的 VPN 客户端主要有 vpnc 和 vpnclient。

vpnc
~~~~~~~
一款评价很高的开源工具,个人感觉安装配置简单,使用方便,Fedora 下安装只需一条命令

[tommy@tmypc ~]$ sudo yum install vpnc

配置文件也很简单,参考 /etc/vpnc/default.conf 修改就行了,下面是我的配置

IPSec ID xxxxx                       ## 组名
IPSec gateway xxx.xxx.xxx.xxx        ## vpn 服务器地址
IPSec secret xxx                     ## 组密码
 
IKE Authmode psk
 
## To add your username and password,
## use the following lines: 如果你的 VPN Server 没有设置单独的用户名和密码,下面可以不用写
Xauth username xxxx
Xauth password xxxxxxx
 
## 可以打开下面的注释,不过输出调试信息完全看不懂
# Debug 3

如果对配置文件还有不明白的,可以先安装一个 Windows 客户端,配好连接,然后在安装目录中的 Profiles子目录找到后缀为 pcf 的文件,复制到 linux 中,下载一个Perl 脚本,直接把它转成 vpnc 的配置文件。

[tommy@tmypc ~]$ wget http://svn.unix-ag.uni-kl.de/vpnc/trunk/pcf2vpnc
[tommy@tmypc ~]$ chmod +x pcf2vpnc
[tommy@tmypc ~]$ ./pcf2vpnc cisco.pcf > cisco.conf

我使用的 vpnc 在这个版本有个 Bug,启动的时候会报个 SIOCSIFMTU: Invalid argument 的错误,但不影响使用,可以通过下面的方法修改,可参考关于这个bug的讨论

[tommy@tmypc ~]$ sudo vi /etc/vpnc/vpnc-script
# 在文件最上方加上下面这行
INTERNAL_IP4_MTU=1500

安装完成以后,用下面命令启动和断开连接

[tommy@tmypc ~]$ sudo vpnc cisco
[tommy@tmypc ~]$ sudo vpnc-disconnect

vpnclient
~~~~~~~
Cisco 官方的客户端工具,虽然也好使,但是版本更新很慢,现在的 4.8.02 竟然连 2.6.30 的内核都不支持。好在有人提供了相关的补丁文件,但是编译需要内核的部分源码,在 Fedora 下,该源码可以通过下面的命令直接安装到 /usr/src/kernels 目录下:

[tommy@t42 vpnclient]$ sudo yum install kernel-devel

注意安装的内核源码版本一定要和你当前使用的内核版本一直,否则在启动时会报一个这样的错误

Starting /opt/cisco-vpnclient/bin/vpnclient: insmod: error inserting '.../cisco_ipsec.ko': -1 Invalid module format Failed (insmod)

下载 vpnclient,虽然写的是 64 位版本,但兼容 32 位,解压缩该文件,下载补丁,注意如果你使用的是其它 Linux 发行版, 需要将下面的 /usr/src 改为你的内核源码目录。

[tommy@tmypc ~]$ tar xzvf vpnclient-linux-x86_64-4.8.02.0030-k9.tar.gz
[tommy@tmypc ~]$ cd vpnclient
[tommy@tmypc ~]$ wget http://lamnk.com/download/vpnclient-linux-2.6.31-final.diff
[tommy@tmypc ~]$ patch < ./vpnclient-linux-2.6.31-final.diff
[tommy@tmypc ~]$ sudo sed -i 's/const\ struct\ net_device_ops\ \*netdev_ops;/struct\ net_device_ops\ \*netdev_ops;/' `find /usr/src -name netdevice.h`
[tommy@tmypc ~]$ sudo ./vpn_install

如果没有在安装的时候设置 vpnclient 进程开机启动,那么在使用前先启动它:

[tommy@tmypc ~]$ sudo /etc/init.d/vpnclient_init start
[tommy@tmypc ~]$ vpnclient connect cisco

cisco 表示你的配置文件 cisco.pcf,该文件保存在 /etc/opt/cisco-vpnclient/Profiles/ 目录下。
Ctrl + c 就可以断开连接了。
如果使用有问题,可以在连接前用下面的命令将日志输出到一个文件 vpn.log,先把日志控制打开

[tommy@tmypc ~]$ sudo vi /etc/opt/cisco-vpnclient/vpnclient.ini
[main]
EnableLog=1
[tommy@tmypc ~]$ sudo /usr/local/bin/ipseclog /var/log/vpn.log  &

有个奇怪的地方,用 vpnc 连接以后, ssh 登录内网服务器时很慢。vpnclient 则没有问题。

参考文档
~~~~~~~
[1] http://forums.fedoraforum.org/showthread.php?t=259317
[2] how_to_install_cisco_vpn_client
[3] how-to-install-cisco-vpn-client-on-ubuntu
[4] http://ubit.buffalo.edu/software/linux/vpn/install.php

Tags: ,
Posted in Technology | No Comments »

无奈的放弃

August 24th, 2011

花了近半年的时间一直在解决一个问题,一个很难的问题,涉及到力学,分析数学,图形数学几个领域,一直觉得自己能搞定,而且对这个问题的理解也越来越深,用了无数种算法,一直得不到满意的结果,感觉自己就像一个输红了了眼的赌徒,投入的时间越多,就越难收手,总幻想着新的算法能有突破,结果得到的只是一次又一次的失望。回首过去的这半年里,我几乎放弃了所有的业余活动,连续的通宵,学习那些变态的数学公式,去大学请教相关领域的老师,用我蹩脚的英语泡国外的邮件列表,几乎被它折磨的没有人形。直到今天再一次求得一个不理想的值,终于决定放弃了,虽然很不甘心,但却无可奈何。

安慰一下自己,虽然问题没搞定,毕竟在这半年里,对一些特殊的算法,图形学,数学方面的知识都有了很大的提高。最关键的让我认识到,隔行如隔山,有些事对我来说不可为!

Posted in Inspire | 1 Comment »

在 Slackware 13.1 上配置 gitosis 和 gitweb

April 19th, 2011

由于 Slackware 默认已经安装好了 git,所以下面我们要做的是安装并配置 gitosis 和 gitweb。

gitosis
~~~~~~~
gitosis 需要通过 python 安装,所以先安装 pysetuptools

tommy@s1:~$ wget http://slackbuilds.org/slackbuilds/13.1/development/pysetuptools.tar.gz
tommy@s1:~$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tommy@s1:~$ tar xzvf pysetuptools.tar.gz
tommy@s1:~$ mv setuptools-0.6c11.tar.gz pysetuptools
tommy@s1:~$ cd pysetuptools
tommy@s1:~/pysetuptools$ sudo ./pysetuptools.SlackBuild

编译成功后,会得到一个 /tmp/pysetuptools-0.6c11-i486-1_SBo.tgz 安装它

tommy@s1:~$ sudo /sbin/installpkg /tmp/pysetuptools-0.6c11-i486-1_SBo.tgz

下载 gitosis 源码,然后通过 python 进行安装

tommy@s1:~$ git clone git://eagain.net/gitosis
tommy@s1:~$ cd gitosis/
tommy@s1:~/gitosis$ sudo python setup.py install

用下面命令增加一个系统用户,所有的 git 操作都通过这个用户来完成,似乎还需要设置密码,记不清楚了,我在 redhat 下配置是不需要设置密码的。

tommy@s1:~$ sudo /usr/sbin/useradd -d /home/git -c "git" -r -s /bin/bash -m git

现在就可以初始化 Gitosis 了。需要通过自己的公钥来运行 gitosis-init。如果公钥不在服务器上,则必须复制一份:

[tommy@t42 ~]$ scp .ssh/id_rsa.pub tommy@192.168.0.194:
tommy@s1:~$ sudo -H -u git gitosis-init < id_rsa.pub

这样该公钥的拥有者就能修改包含着 Gitosis 设置的那个 Git 仓库了。然后手动将这个新的控制仓库中的 post-update 脚本加上执行权限。

tommy@s1:~$ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

由于我是在家里做动态ip 绑定,所以需要配置路由器,打开 22 端口并映射到内网ip 192.168.0.194 ,然后直接通过域名 clone 项目

[tommy@t42 tmp]$ git clone git@git.gaixie.info:gitosis-admin.git

gitweb
~~~~~~~
gitweb 已经被内置到 git 源码中了,先 clone git 源码

tommy@s1:~$ git clone git://git.kernel.org/pub/scm/git/git.git
tommy@s1:~$ cd git

生成 gitweb ,并复制到 apache 的相应目录下

tommy@s1:~/git$ make clean
tommy@s1:~/git$ make GITWEB_PROJECTROOT="/home/git/repositories" \
        		prefix=/usr gitweb/gitweb.cgi
tommy@s1:~/git$ sudo cp -Rf gitweb /var/www/htdocs

修改 apahce 的主配置文件,让 httpd-vhosts.conf 配置文件生效

tommy@s1:~/git$ sudo vi /etc/httpd/httpd.conf

把下面这行注释打开

# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf

编辑子配置文件 httpd-vhosts.conf

tommy@s1:~/git$ sudo vi /etc/httpd/extra/httpd-vhosts.conf 
<VirtualHost *:80>
    ServerName git.gaixie.info
    SetEnv  GITWEB_CONFIG   /home/git/gitosis/gitweb.conf
    DocumentRoot /var/www/htdocs
    <Directory /var/www/htdocs/gitweb>
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All
        order allow,deny
        Allow from all
        AddHandler cgi-script cgi
        DirectoryIndex gitweb.cgi
    </Directory>
</VirtualHost>

修改 gitweb.conf 配置文件

tommy@s1:~$ sudo cp gitosis/gitweb.conf /home/git/gitosis/
tommy@s1:~$ sudo vi /home/git/gitosis/gitweb.conf

增加一个新的 public 项目 slackware-howto,在客户端执行下面的命令

[tommy@t42 gitosis-admin]$ vi gitosis.conf
[tommy@t42 gitosis-admin]$ git commit -am 'add slackware-howto project and linux-admin group'
[tommy@t42 gitosis-admin]$ git push
 
 
[tommy@t42 Projects]$ mkdir slackware-howto
[tommy@t42 Projects]$ cd slackware-howto/
[tommy@t42 slackware-howto]$ git init
Initialized empty Git repository in /home/tommy/Projects/slackware-howto/.git/
[tommy@t42 slackware-howto]$ git remote add origin git@git.gaixie.info:slackware-howto.git
[tommy@t42 slackware-howto]$ touch README
[tommy@t42 slackware-howto]$ git add .
[tommy@t42 slackware-howto]$ git commit -m 'add readme file'
[tommy@t42 slackware-howto]$ git push origin master

让新项目可以被 apache 读取

tommy@s1:~$ sudo chmod 755 /home/git/repositories/slackware-howto.git/

重启 httpd 服务

tommy@s1:~$ sudo sh /etc/rc.d/rc.httpd restart

如果 gitosis 中配置了 daemon = yes ,好像会自动创建 git-daemon-export-ok 文件,所以可以不用手动通过下面的命令 touch 该文件

tommy@s1:~$ sudo touch /home/git/repositories/slackware-howto.git/git-daemon-export-ok

让 daemon 开机运行 ,增加到下面的文件中

tommy@s1:~$ sudo vi /etc/inetd.conf
 
git	stream	tcp	nowait	nobody	/usr/bin/git 
	git daemon --inetd --verbose
	--base-path=/home/git/repositories/
 
tommy@s1:~$ sudo /etc/rc.d/rc.inetd restart

在防火墙上开 git 协议使用的 9418 端口并测试

[tommy@t42 tmp]$ git clone git://git.gaixie.info/slackware-howto.git

参考文档
~~~~~~~
[1] http://progit.org/book/zh/ch4-7.html
[2] http://eagain.net/gitweb/?p=gitosis.git;a=blob;f=README.rst;hb=master
[3] http://www.linuxforums.org/forum/linux-tutorials-howtos-reference-material/64958-how-install-software-linux.html
[4] ftp://ftp.slackware.com/pub/slackware/slackware-13.1/
[5] http://ao2.it/wiki/How_to_setup_a_GIT_server_with_gitosis_and_gitweb
[6] http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
[7] http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html

Tags: , , ,
Posted in Technology | 1 Comment »

RHEL6 上的 DNS Server 配置

March 20th, 2011

首先确保下面的包已经安装,如果你在安装 RHEL 时,选择了 DNS Server ,下面的包应该会自动安装。

[tommy@s3 ~]sudo rpm -q bind bind-libs bind-utils
[sudo] password for tommy: 
bind-utils-9.7.0-5.P2.el6.i686
bind-libs-9.7.0-5.P2.el6.i686
bind-9.7.0-5.P2.el6.i686

DNS 配置
~~~~~~~
接下来我们为 gaixie.org 配置一个 DNS,先启动 DNS 服务

[tommy@s3 ~]$ sudo service named restart

修改下面的文件,设置 DNS 服务用于监听的IP,并接受所有 dns 查询 (例如你的IP 为 10.10.10.110)

[tommy@s3 ~]$ sudo vi /etc/named.conf
options {
	listen-on port 53 { 127.0.0.1;10.10.10.110; };
	listen-on-v6 port 53 { ::1; };
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
	allow-query     { any; };
......

指定 named.gaixie.org 为 gaixie.org 域的配置文件,该 dns 为 master dns,10.10.10.111 是一个 dns slaver ,以后再讨论两个 dns 同步的问题,如果只有一个 dns ,可以不用设置 allow-transfer

[tommy@s3 ~]$ sudo vi /etc/named.rfc1912.zones

在文件最后加入

zone "gaixie.org" IN {
        type master;
        file "named.gaixie.org";
        allow-update { none; };
        allow-transfer { 10.10.10.111; };
};

/var/named 目录下建立 named.gaixie.org 文件,用 named.localhost做模板修改

[tommy@s3 ~]$ sudo cp /var/named/named.localhost /var/named/named.gaixie.org
[tommy@s3 ~]$ sudo vi /var/named/named.gaixie.org

修改后内容如下

$TTL 1D
@       IN SOA  ns1.gaixie.org. admin.gaixie.org. (
                                1       ; serial
                                1D      ; refresh
                                1H      ; retry
                                1W      ; expire
                                3H )    ; minimum
 
@               IN      NS              ns1.gaixie.org.
@               IN      NS              ns2.gaixie.org.
 
@               IN      MX      10      mail.gaixie.org.
 
gaixie.org. IN	A	10.10.10.113
ns1             IN      A       10.10.10.110
ns2             IN      A       10.10.10.111
mail            IN      A       10.10.10.112
www             IN      A       10.10.10.113
gaixie.org. IN TXT "v=spf1 a mx a:ns1.gaixie.org -all"

给文件加 named 组权限

[tommy@s3 www]$ sudo chown root:named /var/named/named.gaixie.org

让新配的 DNS 作为本机的首选 DNS Server

[tommy@s3 ~]$ sudo vi /etc/resolv.conf

文件最上方加入

nameserver 10.10.10.110

修改防火墙配置,让外部可以进行 dns 查询,dns 查询小于 512 bytes 走 udp ,大于走 tcp

[tommy@s3 ~]$ sudo vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT

对于 INPUT 请求,只放行目标端口为 53,状态为 NEW 的连接,如 外部机器对本dns server 进行查询时的初次连接。
rhel 防火墙对于状态为 ESTABLISHED,RELATED 的连接通通放行,所以这里不用设置 OUTPUT

[tommy@s3 ~]$ sudo service iptables restart
[tommy@s3 ~]$ sudo service named restart

DNS 测试
~~~~~~~
如果你只是在局域网内测试DNS,只要给客户端机器加上新配的 DNS (10.10.10.110),最好放在其它 DNS 的最前面,然后执行下面的命令:

[tommy@s3 ~]$ nslookup mail.gaixie.org

看看 10.10.10.110 是否已经能够正确解析此域名。
如果配置的是一个公网 DNS,就不用在客户端机器配置,需要在你的域名服务商那里配置一下。
如果你像我一样,有自己的邮件服务器,最好配置完以后测试一下 spf,否则会被可能会被 163之类的邮箱退信。

参考文档
~~~~~~~
[1] http://forums.fedoraforum.org/showthread.php?t=212337
[2] http://blog.csdn.net/zjl_1026_2001/archive/2010/05/20/5610215.aspx
[3] http://www.linuxidc.com/Linux/2011-01/31084.htm
[4] http://bbs2.chinaunix.net/thread-1593566-1-1.html (zone 文件说明)
[5] http://bit7.itpub.net/post/37616/491031

Tags: ,
Posted in Technology | No Comments »

如何在Thinkpad T60 上安装 Linux 时不破坏一键恢复

November 2nd, 2010

Thinkpad 上的一键恢复 (Rescue and Recovery,以下简称 R&R) 是个很方便的功能,特别是对于我们这些厌倦安装 Windows的懒人来说。它总是躲在一个隐藏分区中,静静的等着你的系统崩溃,然后挺身而出收拾残局。下面简单说说它的实现原理:

R&R 在 MBR (Master Boot Record) 中有一个引导程序,这个程序的主要任务是:

  • 在系统启动是捕获 Access IBM 键(这里指的是 T60 ,其它型号可能不同)的事件,如果被捕获,则进入 R&R 所在的隐藏分区,启动一键恢复程序。
  • 如果没有捕获 Access IBM 键,则寻找有引导标志的主分区并进入该分区,如果所有主分区都没有引导标志,进入第一个主分区。R&R 默认第一个主分区为 Windows 分区。

一旦这个引导程序被修改,将无法通过 Access IBM 键进行恢复,所以我们要确保不要让 Linux 安装时将 Grub 或者是 Lilo 装在 MBR,因为它们会覆盖 R&R 的引导程序。最好也不要在 Linux 安装时,设置主分区的引导标志,有些发行版,例如 Opensuse,似乎会同时修改 R&R 分区的一些属性,导致引导程序无法找到该分区。

所以,如果你想在 Thinkpad 上装双系统(Windows + Linux),正确的操作方式如下:

  1. 下载 Gparted, 用它刻张引导盘,后面会用到。
  2. 通过工具(如魔术分区)缩小原有的 Windows 分区,多出来的空间用来安装 Linux。
  3. 安装 Linux 过程中,分区时不要设置 Boot 标志,即使你有专门的 /boot 分区。
  4. 留意 Grub 或 Lilo的安装位置,不要安装在 MBR。
  5. Linux 安装完成后,直接用 Gparted 光盘引导,然后将装有 Grub 或 Lilo 的 Linux分区置 boot 标志,这样操作不会修改 R&R 分区属性。

注意:不同的 R&R 版本使用上述方法可能会有问题,例如进入一次 R&R 应用以后,R&R 分区可能会被置为引导分区,解决方法有两种:

  • 再用 Gparted 把 boot 标志置回 Linux 引导分区。
  • 用 Windows 来加载 Grub 或 Lilo ,先把它们 dd 出来,如:dd if=/dev/sda3 of=linux_boot.bin bs=512 count=1(sda3 是你的 grub 或者是 lilo所在的分区),然后将 linux_boot.bin 文件复制到 windows 的 C 盘根目录下。修改 boot.ini,加一个选项使其可以加载 linux_boot.bin 文件。详细步骤可以去 Google 一下,网上很多此方法的说明。

如果你将 Grub 或者是 Lilo 装到 MBR,Windows 可能会出一些奇怪的问题,例如 Vista 无法升级 SP1 ,因为在升级 SP1 时会访问 MBR,不过不用紧张,R&R 依然完好的保存在隐藏分区中,只要通过 bmgr32 命令来将 R&R 引导程序恢复到 MBR中就 OK了。

没写过系统引导相关的程序,对于它的原理,基本上都是网上查查资料,自己试来试去得出的结果,肯定不够准确,但大方向应该没问题。

Tags: ,
Posted in Technology | 3 Comments »

Previous page