Part III: System Administration Tools
Chapter 9: Bypassing Automatic Configurations to Gain Control
Debian
系统启动 /etc/inittab 调用 /etc/init.d/rcS
SysV启动脚本 /etc/rc?.d
运行级别和启动X /etc/X11/default-display-manager
cron: /etc/crontab 调用 /etc/cron.interval
超级服务 inetd, xinetd
邮件服务器
模块update-modules 根据/etc/modutils目录自动创建 /etc/modules.conf
网络配置: 启动脚本/etc/init.d/networking 配置文件/etc/network
启动文件: /etc/rc.boot 以及 /etc/rcS.d
SysV 启动脚本模板
#!/bin/bash
case "$1" in
start)
/usr/local/bin/bigserv
;;
stop)
/usr/bin/killall bigserv
;;
restart)
$0 stop
$0 start
;;
esac
~/.xinitrc ==> startx
~/.xsession ==> XDM,KDM,GDM
~/.vnc/xstartup ==> VNC server
Chapter 10: Using Multiple OSs
GRUB
# grub
grub> find /boot/grub/stage1
(hd0,5)
grub> root (hd0,5)
grub> setup (hd0)
grub> quit
Chapter 11: Managing Packages
Chapter 13: Managing Printers
Chapter 14: Programs and Processes
ps
top
pstree
w
jobs
lsof
netstat
nice/renice
kill/killall
Chapter 15: Creating a Custom Kernel
Chapter 16: Optimizing X Configuration
Chapter 17: Protecting Your System with Backups
cp
cpio
dump
smbtar
tar
Chapter 18: System Security
攻击方法
好的密码
本地服务
# netstat -ap
$ nmap -sT www.debsir.org
Part IV: Networking Tools
Chapter 19: Basic Network Configuration
网卡
驱动 /etc/modules.conf
DHCP
客户端 dhclient/pump 调用程序 /sbin/ifup 配置文件 /etc/network/interfaces, /etc/dhclient.conf RedHat /etc/sysconfig/network,/etc/sysconfig/network-scripts/ifcfg-eth0
配置生效: # /etc/rc.d/init.d/network stop|start
查看进程: $ ps ax | grep dhcpcd
静态地址
测试
Xtraceroute
优化网络
Chapter 20: Controlling Network Access
防火墙工具
Shorewall 调用配置文件 /etc/sysconfig/iptables
Red Hat Security Level Configuration: redhat-config-securitylevel 和 lokkit 调用 iptables
Knetfilter 配置文件 /etc/iptables_rules.cfg
防火墙模板
#!/bin/bash
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# Let traffic on the loopback interface pass
iptables -A OUTPUT -d 127.0.0.1 -o lo -j ACCEPT
iptables -A INPUT -s 127.0.0.1 -i lo -j ACCEPT
# Let DNS traffic pass
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
# Let clients' TCP traffic pass
iptables -A OUTPUT -p tcp --sport 1024:65535 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 1024:65535 -m state \
--state ESTABLISHED,RELATED -j ACCEPT
# Let local connections to local SSH server pass
iptables -A OUTPUT -p tcp --sport 22 -d 172.24.1.0/24 -m state \
--state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 172.24.1.0/24 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
TCP Wrappers
通常由 inetd 调用
配置文件 /etc/inetd.conf /etc/hosts.allow 和 /etc/hosts.deny
服务名解析 /etc/services
TCP Wrappers配置格式(/etc/hosts.allow 和 /etc/hosts.deny)
service-names : client-list [: shell-command ]
service-names : 例如 in.ftpd 或 in.telnetd
client-list : ip地址或ip地址范围, 主机名, 域名, 用户名 例如 172.24.45.0/24 EXCEPT 172.24.45.72
/etc/hosts.allow 格式
in.telnetd : 172.24.45.2 trex.pangaea.edu
vsftpd : 172.24.45. EXCEPT 172.24.45.1
imapd : .pangaea.edu EXCEPT router.pangaea.edu
ipop3d : sue@trex.pangaea.edu
xinetd
格式
service swat
{
port = 901
socket_type = stream
wait = no
only_from = 127.0.0.1
user = root
server = /usr/sbin/swat
disable = no
}
使用Jail
chroot
Chapter 21: Detecting Intruders
Tripwire
策略文件格式:
TWBIN = /usr/sbin ;
# Tripwire binaries
(
rulename = "Tripwire Binaries",
)
{
$(TWBIN)/siggen -> $(ReadOnly) ;
$(TWBIN)/tripwire -> $(ReadOnly) ;
$(TWBIN)/twadmin -> $(ReadOnly) ;
$(TWBIN)/twprint -> $(ReadOnly) ;
}
/usr/bin -> $(ReadOnly) ;
/etc -> $(Dynamic) ;
初始化数据库
/etc/tripwire/twinstall.sh
tripwire --init
校验
tripwire --check
修改Tripwire配置
twadmin --create-cfgfile -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt # 修改配置文件
twadmin --create-polfile -S /etc/tripwire/site.key /etc/tripwire/twpol.txt # 修改策略
tripwire --update-policy -S /etc/tripwire/site.key /etc/tripwire/twpol.txt # 创建新的策略文件
tripwire --update --twrfile /var/lib/tripwire/report/knox.luna.edu-20031212-155357.twr # 更新数据库
chkrootkit
Part V: Server Tools
Chapter 22: Running Servers
SysV启动脚本
位置: Debian /etc/init.d /etc/rc?.d Redhat /etc/rc.d/init.d/ /etc/rc.d/rc?.d
chkconfig/ntsysv/redhat-config-services/ksysv
本地启动脚本: /etc/rc.boot
Chapter 23: Getting More from a Web Server
web服务器: apache/roxen/zeus/kHTTPd
apache服务器配置
Chapter 24: Serving Files
FTP
NFS
Samba
Chapter 25: Delivering E-Mail
服务器: Sendmail/Postfix/Exim/qmail
Chapter 26: Providing Remote Login Access
字符模式远程访问: OpenSSH
GUI 远程访问: XDMCP Server/VNC
Chapter 27: Miscellaneous Servers
DHCP
DNS
NTP
2007年10月28日星期日
Linux Power Tools: (II) User Tools
Part II: User Tools
Chapter 4: Mastering Shells and Shell Scripting
指定用户shell /etc/passwd
tony:x:1000:1000:tony,,,:/home/tony:/bin/bash
用命令修改用户默认shell
# usermod -s /bin/tcsh sandro
普通用户修改自己的shell
$ chsh -s /bin/tcsh
set show-all-if-ambiguous on # 设定 tab 键自动补齐
配置文件/etc/inputrc
配置shell
全局配置文件 /etc/profile 和 /etc/profile.d目录(login相关) /etc/bashrc 或 /etc/bash.bashrc (login无关)
用户配置文件 ~/.profile (login相关) ~/.bashrc (login无关)
shell 脚本
Chapter 5: Doing Real Work in Text Mode
定义虚拟终端 /etc/inittab
通过Alt+F1 到 Alt+F6调用
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
如果运行了X, 则在 Alt+F7
重要命令
文件系统 mount umount fdformat mkfs
文件管理 cp ln mv rm ls chown chgrp chmod mkdir rmdir cd pwd
文件信息 df du stat lsof uptime free hostname who dmesg
tip 对应错误信息存储在 /var/log/dmesg
字符模式环境
配置环境 /etc/termcap /usr/share/terminfo
修改终端字体
相关命令 consolechars, setfont, fontconfig
$ setfont -v /usr/lib/kbd/consolefonts/t.psf.gz
Debian 命令 consolechars 软件包 console-tools 字体包 console-data 和 fonty 字体文件位置 /usr/share/consolefonts
色彩 alias ls='ls --color'
Chapter 6: Getting the Most from a Desktop Environment
从字符模式或使用XDM登录X 会读取 .xsession 或 .xinitrc
XDM 使用 .xsession, startx 使用 .xinitrc
startkde ==> KDE(~/.kde), gnome-session ==> GNOME(~/.gnome2), startxfce ==> XFce
KDE
GNOME
Chapter 7: Using Linux for Office Productivity
OpenOffice.org
KOffice
GNOME Office
LaTeX
Emulators
字体
打印机
Chapter 8: Miscellaneous User Tools.
音频
数码相机
GIMP
浏览器
E-Mail 客户端
Chapter 4: Mastering Shells and Shell Scripting
指定用户shell /etc/passwd
tony:x:1000:1000:tony,,,:/home/tony:/bin/bash
用命令修改用户默认shell
# usermod -s /bin/tcsh sandro
普通用户修改自己的shell
$ chsh -s /bin/tcsh
set show-all-if-ambiguous on # 设定 tab 键自动补齐
配置文件/etc/inputrc
配置shell
全局配置文件 /etc/profile 和 /etc/profile.d目录(login相关) /etc/bashrc 或 /etc/bash.bashrc (login无关)
用户配置文件 ~/.profile (login相关) ~/.bashrc (login无关)
shell 脚本
Chapter 5: Doing Real Work in Text Mode
定义虚拟终端 /etc/inittab
通过Alt+F1 到 Alt+F6调用
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
如果运行了X, 则在 Alt+F7
重要命令
文件系统 mount umount fdformat mkfs
文件管理 cp ln mv rm ls chown chgrp chmod mkdir rmdir cd pwd
文件信息 df du stat lsof uptime free hostname who dmesg
tip 对应错误信息存储在 /var/log/dmesg
字符模式环境
配置环境 /etc/termcap /usr/share/terminfo
修改终端字体
相关命令 consolechars, setfont, fontconfig
$ setfont -v /usr/lib/kbd/consolefonts/t.psf.gz
Debian 命令 consolechars 软件包 console-tools 字体包 console-data 和 fonty 字体文件位置 /usr/share/consolefonts
色彩 alias ls='ls --color'
Chapter 6: Getting the Most from a Desktop Environment
从字符模式或使用XDM登录X 会读取 .xsession 或 .xinitrc
XDM 使用 .xsession, startx 使用 .xinitrc
startkde ==> KDE(~/.kde), gnome-session ==> GNOME(~/.gnome2), startxfce ==> XFce
KDE
GNOME
Chapter 7: Using Linux for Office Productivity
OpenOffice.org
KOffice
GNOME Office
LaTeX
Emulators
字体
打印机
Chapter 8: Miscellaneous User Tools.
音频
数码相机
GIMP
浏览器
E-Mail 客户端
2007年10月27日星期六
Linux Power Tools: (I) Hardware Tools 2
Chapter 2: Improving Disk Performance
测试与优化磁盘性能
# /sbin/hdparm -Tt /dev/hdb (针对ATA硬盘)
# /sbin/hdparm -v /dev/hdb 查看硬盘参数
优化硬盘性能
参阅hdparm mainpage
优化硬盘分区
1. 将经常访问的数据存储在硬盘内圈
2. 交换分区放置在硬盘内圈
3. 将性能相关的大数据文件放在硬盘的前段, 比如数据库文件
3. 相关的分区应该放在一起
4. 对于旧电脑, /boot分区有1024柱面(约8G)的限制
5. 多硬盘性能会提升
Chapter 3: Using External Peripherals
配置USB,RS-232, 并口
配置键盘 Debian
Keymap文件位置 /etc/console and /usr/share/keymaps
调用脚本 /etc/init.d/keymap.sh
系统提供键盘映射文件位置 /usr/share/keymaps
调整键盘响应 # kbdrate -r 12 -d 250
rate (-r) delay (-d)
X下的键盘配置
setxkbmap -v # 查看当前键盘配置
$ xmodmap -e 'keycode 23 = Tab' # 重新设定Tab键
.Xmodmap # 用户设定
鼠标配置
Option "Device" "/dev/mouse"
/dev/mouse 为到 /dev/psaux 的符号链接 用于PS/2鼠标
/dev/usb/mouse0 USB鼠标
Option "Protocol" "ps/2"
imps/2 微软智能鼠标协议
两键鼠标(模拟三键)
Option "Emulate3Buttons"
Option "Emulate3Timeout" "60"
配置滚轮鼠标
需要协议 imps/2
Option "ZAxisMapping" "4 5"
配置扫描仪
测试与优化磁盘性能
# /sbin/hdparm -Tt /dev/hdb (针对ATA硬盘)
# /sbin/hdparm -v /dev/hdb 查看硬盘参数
优化硬盘性能
参阅hdparm mainpage
优化硬盘分区
1. 将经常访问的数据存储在硬盘内圈
2. 交换分区放置在硬盘内圈
3. 将性能相关的大数据文件放在硬盘的前段, 比如数据库文件
3. 相关的分区应该放在一起
4. 对于旧电脑, /boot分区有1024柱面(约8G)的限制
5. 多硬盘性能会提升
Chapter 3: Using External Peripherals
配置USB,RS-232, 并口
配置键盘 Debian
Keymap文件位置 /etc/console and /usr/share/keymaps
调用脚本 /etc/init.d/keymap.sh
系统提供键盘映射文件位置 /usr/share/keymaps
调整键盘响应 # kbdrate -r 12 -d 250
rate (-r) delay (-d)
X下的键盘配置
setxkbmap -v # 查看当前键盘配置
$ xmodmap -e 'keycode 23 = Tab' # 重新设定Tab键
.Xmodmap # 用户设定
鼠标配置
Option "Device" "/dev/mouse"
/dev/mouse 为到 /dev/psaux 的符号链接 用于PS/2鼠标
/dev/usb/mouse0 USB鼠标
Option "Protocol" "ps/2"
imps/2 微软智能鼠标协议
两键鼠标(模拟三键)
Option "Emulate3Buttons"
Option "Emulate3Timeout" "60"
配置滚轮鼠标
需要协议 imps/2
Option "ZAxisMapping" "4 5"
配置扫描仪
Linux Power Tools: (I) Hardware Tools 1
Linux Power Tools
by Roderick W. Smith ISBN:0782142265
Sybex ? 2003 (644 pages)
Part I: Hardware Tools
Chapter 1: Optimizing System Architecture Usage
编译参数的针对平台的优化: -march=pentium4
驱动硬件:
1. 将驱动编译进内核
2. 以模块方式加载驱动 模块位置 /lib/modules/version
insmod:单个模块加载命令, 需要指定模块名称或模块文件文件名, 比如加载via-rhine.o, 可以insmod via-rhine, 问题: 可能会因为依赖问题而模块加载失败.
modprobe: 加载模块同时解决依赖问题, 其他同insmod
depmod: 创建模块依赖列表, 供modprobe使用
rmmod: 卸载内核模块, 与insmod 相反, 使用-r 或 --stacks 则与modprobe相反
加载模块时的通用参数 -r 模块闲置不用时, 即自动卸载模块.
内核守护进程: kerneld
模块强制加载(通常只加载版本匹配的模块): -f
自动加载模块
配置文件: /etc/modules.conf(在Debian 中是/etc/modules)
debian的方式: 使用目录树方式/etc/modutils: update-modules 根据此目录生成/etc/modules.conf文件 因此不应该直接修改此配置文件, 如果要增加模块, 可以修改 /etc/modules文件 或 /etc/modutils/目录, 然后用 update-modules 更新
alias 为设备指定驱动 options 指定模块加载参数
Delivering Clear Sound
OSS, ALSA 驱动
/proc 文件系统说明
了解您的硬件
$ cat /proc/version 查看内核信息
修改硬件设定
by Roderick W. Smith ISBN:0782142265
Sybex ? 2003 (644 pages)
Part I: Hardware Tools
Chapter 1: Optimizing System Architecture Usage
编译参数的针对平台的优化: -march=pentium4
驱动硬件:
1. 将驱动编译进内核
2. 以模块方式加载驱动 模块位置 /lib/modules/version
insmod:单个模块加载命令, 需要指定模块名称或模块文件文件名, 比如加载via-rhine.o, 可以insmod via-rhine, 问题: 可能会因为依赖问题而模块加载失败.
modprobe: 加载模块同时解决依赖问题, 其他同insmod
depmod: 创建模块依赖列表, 供modprobe使用
rmmod: 卸载内核模块, 与insmod 相反, 使用-r 或 --stacks 则与modprobe相反
加载模块时的通用参数 -r 模块闲置不用时, 即自动卸载模块.
内核守护进程: kerneld
模块强制加载(通常只加载版本匹配的模块): -f
自动加载模块
配置文件: /etc/modules.conf(在Debian 中是/etc/modules)
debian的方式: 使用目录树方式/etc/modutils: update-modules 根据此目录生成/etc/modules.conf文件 因此不应该直接修改此配置文件, 如果要增加模块, 可以修改 /etc/modules文件 或 /etc/modutils/目录, 然后用 update-modules 更新
alias 为设备指定驱动 options 指定模块加载参数
Delivering Clear Sound
OSS, ALSA 驱动
/proc 文件系统说明
了解您的硬件
$ cat /proc/version 查看内核信息
修改硬件设定
订阅:
博文 (Atom)
