2007年12月アーカイブ
ユーザープロファイル管理
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
パスワードに有効期限を設定
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# chage
Usage: chage [options] user
Options:
-d, --lastday LAST_DAY set last password change to LAST_DAY
-E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-h, --help display this help message and exit
-I, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --list show account aging information
-m, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-M, --maxdays MAX_DAYS set maximim number of days before password
change to MAX_DAYS
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
[root@localhost ~]#
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
アカウントの確認
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# chage -l admin
Last password change : 10月 04, 2007
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@localhost ~]#
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↑のアカウントはディフォルトのままなので,設定を変更する
パスワード変更には最低1日
パスワード有効期限90日
パスワードが切れる30日前から警告が出る
パスワードが切れると7日間待ってアカウントロック
アカウント無効化の日は2010年4月1日に設定
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# chage -m 1 -M 90 -W 30 -I 7 -E 2010-04-01 admin
[root@localhost ~]# chage -l admin
Last password change : 10月 04, 2007
Password expires : 1月 02, 2008
Password inactive : 1月 09, 2008
Account expires : 4月 01, 2010
Minimum number of days between password change : 1
Maximum number of days between password change : 90
Number of days of warning before password expires : 30
[root@localhost ~]#
[root@localhost ~]# cat /etc/shadow | grep admin
admin:$1$FssAdbea$.hYb8/RSdjmqZ4yDuFcAd1:13790:1:90:30:7:14700:
administrator:!!:13835:0:99999:7:::
[root@localhost ~]#
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
パスワード変更
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# chage -l admin
Last password change : 12月 30, 2007
Password expires : 3月 29, 2008
Password inactive : 4月 05, 2008
Account expires : 4月 01, 2010
Minimum number of days between password change : 1
Maximum number of days between password change : 90
Number of days of warning before password expires : 30
[root@localhost ~]#
※ 一般ユーザーのログインを禁止する設定
/etc/nologinファイルを作成しておく。 (touch /etc/nologin)
※ usermod -s /bin/false ユーザー名 (特定ユーザーのログイン禁止)
※ /etc/passwdファイルを直接編集でも可
ユーザーのリソース利用制限をulimitにて変更できます。
[root@localhost ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
max nice (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 5119
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
max rt priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 5119
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@localhost ~]#
RPMからインストールされたファイルの検証。
rpm -Vコマンド
━━━━━━━━━━━━━━━━━━━━━━━━━━━
8桁検証記号 c=設定ファイル
━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# rpm -Va
..5....T c /etc/pki/nssdb/secmod.db
.M...... c /etc/cups/classes.conf
S.5....T c /etc/php.ini
SM5....T /usr/lib/perl5/5.8.8/CGI.pm
SM5....T /usr/lib/perl5/5.8.8/CGI/Carp.pm
SM5....T /usr/lib/perl5/5.8.8/CGI/Cookie.pm
SM5....T /usr/lib/perl5/5.8.8/CGI/Fast.pm
SM5....T /usr/lib/perl5/5.8.8/CGI/Util.pm
SM5....T /usr/lib/perl5/5.8.8/File/Temp.pm
SM5....T /usr/lib/perl5/5.8.8/Test/Builder.pm
.M5....T /usr/lib/perl5/5.8.8/Test/Builder/Module.pm
SM5....T /usr/lib/perl5/5.8.8/Test/Builder/Tester.pm
SM5....T /usr/lib/perl5/5.8.8/Test/More.pm
.M5....T /usr/lib/perl5/5.8.8/Test/Simple.pm
SM5....T /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/List/Util/Util.so
SM5....T c /etc/sysconfig/iptables-config
.......T c /etc/inittab
S.5....T c /etc/sysconfig/system-config-securitylevel
S.5....T c /etc/sudoers
S.5....T c /etc/aliases
S.5....T c /etc/printcap
..5....T c /etc/profile
S.5....T c /etc/dumpdates
S ファイルサイズが異なる
M アクセス権限かファイルタイプが変更されている
5 MD5チェックサム地が異なる
L シンボリックリンクが変更されている
U 所有者が変更されている
G 所属グループが変更されている
T ファイルの更新時刻が異なる
D デバイスファイルが変更されている
? 不明
c 設定ファイル
━━━━━━━━━━━━━━━━━━━━━━━━━━━
MD5チェックサムの確認 md5sum
━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost mysql-rpms]# md5sum MySQL-server-community-5.0.45-0.rhel4.i386.rpm
80897d276a381df8aa6277d29d861ca3 MySQL-server-community-5.0.45-0.rhel4.i386.rpm
[root@localhost mysql-rpms]#
━━━━━━━━━━━━━━━━━━━━━━━━━━━
GPG検証
━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost mysql-rpms]# rpm --checksig MySQL-server-community-5.0.45-0.rhel4.i386.rpm
MySQL-server-community-5.0.45-0.rhel4.i386.rpm: sha1 md5 (GPG) OK ではありません。(見つからない鍵: GPG#5072e1f5)
[root@localhost mysql-rpms]#
公開鍵は,ベンダーウエブサイトなどから取得できます。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
suid(set user id)やsgidが設定された実行ファイルを実行すると,そのプログラムは実行ファイルの所有ユーザ
または所有グループの権限で動作します。なのでスーパーユーザーが所有者であるプログラムにSUIDを設定
すると,ユーザーが実行した場合でもそのプログラムはスーパーユーザー権限で動作します。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# find / -perm -u+s -exec ls -la '{}' ';'
-rwsr-xr-x 1 root root 55016 3月 15 2007 /sbin/mount.nfs4
-rwsr-xr-x 1 root root 12280 3月 15 2007 /sbin/pam_timestamp_check
-rwsr-xr-x 1 root root 55012 3月 15 2007 /sbin/mount.nfs
-rwsr-xr-x 1 root root 20796 3月 15 2007 /sbin/unix_chkpwd
-rwsr-xr-x 1 root root 55016 3月 15 2007 /sbin/umount.nfs4
-rwsr-xr-x 1 root root 55016 3月 15 2007 /sbin/umount.nfs
--wS--xr-x 1 root root 0 10月 5 04:59 /media/.hal-mtab-lock
-rwsr-xr-x 1 root root 31244 3月 15 2007 /bin/ping6
-rwsr-xr-x 1 root root 57588 3月 15 2007 /bin/mount
-rwsr-xr-x 1 root root 38552 3月 15 2007 /bin/umount
-rwsr-xr-x 1 root root 24060 3月 22 2007 /bin/su
-rwsr-xr-x 1 root root 35864 3月 15 2007 /bin/ping
-rwsr-xr-x 1 root root 6808 3月 22 2007 /usr/sbin/usernetctl
-rws--x--x 1 root root 34824 3月 15 2007 /usr/sbin/userhelper
-rwsr-xr-x 1 root root 6240 1月 6 2007 /usr/sbin/ccreds_validate
-rwsr-xr-x 1 root root 172200 3月 22 2007 /usr/libexec/openssh/ssh-keysign
-rwsr-xr-x 1 root root 144537 3月 15 2007 /usr/kerberos/bin/ksu
-rwsr-xr-x 1 root root 18544 3月 15 2007 /usr/bin/rcp
-rws--x--x 1 root root 17900 3月 15 2007 /usr/bin/chfn
-rwsr-xr-x 1 root root 13108 3月 15 2007 /usr/bin/rlogin
-rws--x--x 1 root root 70892 1月 10 2007 /usr/bin/sperl5.8.8
-rwsr-xr-x 1 root root 46748 3月 15 2007 /usr/bin/chage
---s--x--x 2 root root 159096 1月 7 2007 /usr/bin/sudoedit
-rws--x--x 1 root root 1820868 3月 15 2007 /usr/bin/Xorg
-rwsr-xr-x 1 root root 8876 3月 15 2007 /usr/bin/rsh
-rwsr-sr-x 1 root root 311288 3月 15 2007 /usr/bin/crontab
-rwsr-xr-x 1 root root 47352 3月 15 2007 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 43976 1月 6 2007 /usr/bin/at
-rws--x--x 1 root root 19064 3月 15 2007 /usr/bin/chsh
---s--x--x 2 root root 159096 1月 7 2007 /usr/bin/sudo
-rwsr-xr-x 1 root root 24556 3月 15 2007 /usr/bin/newgrp
-rwsr-xr-x 1 root root 22984 1月 7 2007 /usr/bin/passwd
[root@localhost ~]#
「chmod u+s」 コマンドや「chmod 4755」 コマンドにてコマンドにsuidを付与する事が出来ます。
[root@localhost ~]# /sbin/iptables -[AD] チェイン ルール
[root@localhost ~]# /sbin/iptables -P チェイン ターゲット
[root@localhost ~]# /sbin/iptables -L チェイン
オプション,チェイン,ターゲット,ルール
━━━━━━━━━━━━━━━━━━━━━━━
オプション 概要
━━━━━━━━━━━━━━━━━━━━━━━
-A <チェイン> チェインの最後にルールを追加
-D <チェイン> チェインからルールを削除する
-P <チェイン> <ターゲット> チェインのポリシーを変更する
-L <チェイン> ルールのリストを表示
━━━━━━━━━━━━━━━━━━━━━━━
チェイン 設定
━━━━━━━━━━━━━━━━━━━━━━━
INPUT 入力パケット
OUTPUT 出力パケット
FORWARD 転送パケット
━━━━━━━━━━━━━━━━━━━━━━━
ターゲット 設定
━━━━━━━━━━━━━━━━━━━━━━━
ACCEPT 許可
DROP 破棄
REJECT 拒否(送信元に通知)
━━━━━━━━━━━━━━━━━━━━━━━
ターゲット 設定
━━━━━━━━━━━━━━━━━━━━━━━
-s <送信元> 送信元のIPアドレスを指定
-d <送信先> 送信先のIPアドレスを指定
--support <ポート番号> 送信元のポート番号指定
--drop <ポート番号> 送信先のポート番号指定
-j <ターゲット> ターゲットを指定
-p <プロトコル> プロトコルを指定
-i <インターフェース> インターフェースを指定(eth0,eth1,ppp0など)
『設定の確認』
[root@localhost ~]# /sbin/iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# /sbin/iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]#
まずは,SSHにてアクセスを許可させる設定をしてみる。
※ リモートから設定はアクセス出来なくなる可能性があるので注意(今回はシェルにしてリモートから対応してみた)
[root@localhost ~]# cat iptable_config_base.sh
#! /bin/sh
#すべてのiptables設定を削除#
/sbin/iptables -F
/sbin/iptables -X
#すべてのパケットを拒否#
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
#ループバックアドレスからのパケットを全て許可#
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
#ICMP許可 全て->自分#
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-reply -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
#ICMP許可 自分->全て#
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-request -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
#sshパケットの許可 自分のセグメント->自分
/sbin/iptables -A INPUT -p tcp -s 192.168.11.0/24 -d 192.168.11.5 --dport 22 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -s 192.168.11.5 --sport 22 -d 192.168.11.0/24 -o eth0 -j ACCEPT
#loggingの設定#
/sbin/iptables -N LOGGING
/sbin/iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit
/sbin/iptables -A LOGGING -j DROP
/sbin/iptables -A INPUT -j LOGGING
/sbin/iptables -A OUTPUT -j LOGGING
※SSHもICMPも接続可能Apache(Port80)は接続出来なくなってました。
━━━━━━━━スクリプトの編集(Apache追加)━━━━━━━━━━━━
Apacheの接続を最後に設定に追加して,保存して終了。(またリモートからの作業なので,シェルスクリプトの編集)
[root@localhost ~]# cat iptable_config_base.sh
#! /bin/sh
#すべてのiptables設定を削除
/sbin/iptables -F
/sbin/iptables -X
#すべてのパケットを拒否
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
#ループバックアドレスからのパケットを全て許可
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
#ICMPパケットの許可 (方向)trusthost->myhost
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-reply -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
#ICMPの許可 (方向)myhost->trusthost
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-request -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
#sshパケットの許可 (方向)trusthost-> myhost
/sbin/iptables -A INPUT -p tcp -s 192.168.11.0/24 -d 192.168.11.5 --dport 22 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -s 192.168.11.5 --sport 22 -d 192.168.11.0/24 -o eth0 -j ACCEPT
# HTTP 80,443 許可#
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --sport 443 -j ACCEPT
# 内部から行ったアクセスに対する外部からの返答アクセスを許可#
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#loggingの設定#
/sbin/iptables -N LOGGING
/sbin/iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit
/sbin/iptables -A LOGGING -j DROP
/sbin/iptables -A INPUT -j LOGGING
/sbin/iptables -A OUTPUT -j LOGGING
[root@localhost ~]#
━━━━━━━━保存と再起動━━━━━━━━━━━━
[root@localhost ~]# /etc/rc.d/init.d/iptables save
ファイアウォールのルールを /etc/sysconfig/iptables に保存中[ OK ]
[root@localhost ~]# /etc/init.d/iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns [ OK ]
[root@localhost ~]#
⑴ Source Fileのダウンロード
wget http://www.modsecurity.org/download/modsecurity-apache_2.1.4.tar.gz
⑵ インストール
make
make install
⑶ ルールファイルを読み込むために,httpd.confの変更
⑷ 設定完了したら,Apacheの再起動してみる。(設定ファイルは以下のような感じ)
※ mod_unique_idがApacheにロードされて無い場合は,予め追加しておく必要があるようです。
[root@localhost metadata]# /usr/local/apache2/bin/apxs -cia mod_unique_id.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_unique_id.lo mod_unique_id.c && touch mod_unique_id.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_unique_id.la -rpath /usr/local/apache2/modules -module -avoid-version mod_unique_id.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_unique_id.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_unique_id.la /usr/local/apache2/modules/
cp .libs/mod_unique_id.so /usr/local/apache2/modules/mod_unique_id.so
cp .libs/mod_unique_id.lai /usr/local/apache2/modules/mod_unique_id.la
cp .libs/mod_unique_id.a /usr/local/apache2/modules/mod_unique_id.a
chmod 644 /usr/local/apache2/modules/mod_unique_id.a
ranlib /usr/local/apache2/modules/mod_unique_id.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_unique_id.so
[activating module `unique_id' in /usr/local/apache2/conf/httpd.conf]
[root@localhost metadata]# ls -l /usr/local/
詳細は,オフィシャルサイト参照下さい。
利用している,ネットワークカードにDHCPクライアントの設定をする。
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# ADMtek NC100 Network Everywhere Fast Ethernet 10/100
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:90:CC:E0:0C:A4
ONBOOT=yes
※Debian系のディストリビューションの場合は, /etc/network/interfacesに記入。
DHCPコマンドを直接実行する場合は。 pump, dhclient, dhcpcdコマンドなどを利用します。
[root@localhost ~]# dhclient eth0
[root@localhost ~]# dhclient
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:90:cc:e0:0c:a4
Sending on LPF/eth0/00:90:cc:e0:0c:a4
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6
DHCPOFFER from 192.168.11.1
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.11.1
bound to 192.168.11.4 -- renewal in 70777 seconds.
[root@localhost ~]#
名前解決順序
[root@localhost ~]# cat /etc/host.conf
order hosts,bind
[root@localhost ~]#
[root@localhost ~]# more /etc/nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
# nisplus or nis+ Use NIS+ (NIS version 3)
# nis or yp Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# [NOTFOUND=return] Stop searching if not found so far
#
# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
passwd: files
shadow: files
group: files
#hosts: db files nisplus nis dns
hosts: files dns
名前解決
[root@localhost ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.1
search localdomain
[root@localhost ~]#
[root@localhost ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[root@localhost ~]#
ホスト名,ホスト名,GW,使用/不使用
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1
[root@localhost ~]#
IPアドレスの設定
(以下:DHCPの場合)
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# ADMtek NC100 Network Everywhere Fast Ethernet 10/100
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:90:CC:E0:0C:C5
ONBOOT=yes
[root@localhost ~]#
(以下:IP指定の場合)
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# ADMtek NC100 Network Everywhere Fast Ethernet 10/100
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:90:CC:E0:0C:C5
BROADCAST=192.168.1.255
IPADDR=192.168.1.10
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
[root@localhost ~]#
※ NETWORK,BROADCASTなどは記入しなくても良い場合は多い。
コマンド色々:
hostコマンド
[root@localhost ~]# host yahoo.co.jp
yahoo.co.jp has address 203.216.227.176
yahoo.co.jp has address 124.83.139.192
yahoo.co.jp mail is handled by 10 mx5.mail.yahoo.co.jp.
yahoo.co.jp mail is handled by 10 mx1.mail.yahoo.co.jp.
yahoo.co.jp mail is handled by 10 mx2.mail.yahoo.co.jp.
yahoo.co.jp mail is handled by 10 mx3.mail.yahoo.co.jp.
[root@localhost ~]#
[root@localhost ~]# host 203.216.227.176
176.227.216.203.in-addr.arpa domain name pointer f1.top.vip.tnz.yahoo.co.jp.
[root@localhost ~]#
netstatコマンド
[root@localhost ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:838 *:* LISTEN
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 1 0 192.168.11.4:46259 ftp4.ncnu.edu.tw:http CLOSE_WAIT
tcp 1 0 192.168.11.4:46262 ftp4.ncnu.edu.tw:http CLOSE_WAIT
tcp 1 0 192.168.11.4:40359 centos.at.multacom.com:http CLOSE_WAIT
tcp 1 0 192.168.11.4:40363 centos.at.multacom.com:http CLOSE_WAIT
tcp 1 0 192.168.11.4:40361 centos.at.multacom.com:http CLOSE_WAIT
tcp 1 0 192.168.11.4:40365 centos.at.multacom.com:http CLOSE_WAIT
tcp 0 0 *:webcache *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 132 ::ffff:192.168.11.4:ssh ::ffff:192.1:carrius-rshell ESTABLISHED
[root@localhost ~]#
-a 全てのソケット
-c 1秒毎リアルタイム表示
-i ネットワークインターフェース状況
-n アドレス,ポートを数値で表示
-p PIDとプロセス名も表示する
-r ルーティングテーブル表示
-t TCPポートのみ表示
routeコマンド
Destination → 宛先 Gateway→GWのアドレス Genmask→宛先のSubnet(ホストは255.255.255.255 GWは0.0.0.0)
Flags→経路状態(U:有効, H:宛先はホスト, G: GW, !:経路無効) Metric→距離(HOP) Ref→ルートの参照数,
Use→経路参照回数 Iface→ネットワークインターフェース
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.11.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
default air.setup 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]#
route add で追加
route del で削除
LinuxをRouterとして扱うような場合は,異なるネットワークのパケットを転送する必要がるのでip fowardを1に設定する。
0=パケット転送拒否 1=パケット転送許可
[root@localhost ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@localhost ~]#
TCPDUMP
-i インターフェース
-s バイト数
-X 16進とASCII文字で表示
-n アドレスを名前変換しないで表示
port ポート番号指定
proto プロトコルを指定
[root@localhost ~]# tcpdump -X -i eth0 port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
01:09:10.196603 IP 192.168.11.2.gxtelmd > 192.168.11.4.http: S 3053066467:3053066467(0) win 16384 <mss 1460,
0x0000: 4500 0030 601c 4000 8006 0355 c0a8 0b02 E..0`.@....U....
0x0010: c0a8 0b04 0934 0050 b5fa 18e3 0000 0000 .....4.P........
0x0020: 7002 4000 d366 0000 0204 05b4 0101 0402 p.@..f..........
01:09:10.239801 IP 192.168.11.4.http > 192.168.11.2.gxtelmd: S 2904952068:2904952068(0) ack 3053066468 win 5p,nop,sackOK>
[admin@localhost ~]$ whois yahoo.com
[Querying whois.verisign-grs.com]
[whois.verisign-grs.com]
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: YAHOO.COM
Registrar: MARKMONITOR INC.
Whois Server: whois.markmonitor.com
Referral URL: http://www.markmonitor.com
Name Server: NS1.YAHOO.COM
Name Server: NS2.YAHOO.COM
Name Server: NS3.YAHOO.COM
Name Server: NS4.YAHOO.COM
Name Server: NS5.YAHOO.COM
Status: clientDeleteProhibited
Status: clientTransferProhibited
Status: clientUpdateProhibited
Updated Date: 22-jul-2005
Creation Date: 18-jan-1995
Expiration Date: 19-jan-2012
>>> Last update of whois database: Sat, 08 Dec 2007 15:29:10 UTC <<<
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar. Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.[admin@localhost ~]$
nslookup, digコマンドで名前解決調査
a :ipアドレス
any : 全ての情報
mx : メールサーバーの情報
ns : ネームサーバーの情報
[admin@localhost ~]$ dig yahoo.co.jp a
; <<>> DiG 9.3.3rc2 <<>> yahoo.co.jp a
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13855
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.co.jp. IN A
;; ANSWER SECTION:
yahoo.co.jp. 150 IN A 124.83.139.192
yahoo.co.jp. 150 IN A 203.216.227.176
;; Query time: 10 msec
;; SERVER: 192.168.11.1#53(192.168.11.1)
;; WHEN: Sun Dec 9 00:25:28 2007
;; MSG SIZE rcvd: 61
[admin@localhost ~]$ dig yahoo.co.jp mx
; <<>> DiG 9.3.3rc2 <<>> yahoo.co.jp mx
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42981
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.co.jp. IN MX
;; ANSWER SECTION:
yahoo.co.jp. 250 IN MX 10 mx3.mail.yahoo.co.jp.
yahoo.co.jp. 250 IN MX 10 mx5.mail.yahoo.co.jp.
yahoo.co.jp. 250 IN MX 10 mx1.mail.yahoo.co.jp.
yahoo.co.jp. 250 IN MX 10 mx2.mail.yahoo.co.jp.
;; Query time: 10 msec
;; SERVER: 192.168.11.1#53(192.168.11.1)
;; WHEN: Sun Dec 9 00:25:33 2007
;; MSG SIZE rcvd: 114
[admin@localhost ~]$ dig yahoo.co.jp ns
; <<>> DiG 9.3.3rc2 <<>> yahoo.co.jp ns
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60340
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.co.jp. IN NS
;; ANSWER SECTION:
yahoo.co.jp. 419 IN NS dnsg01.yahoo.co.jp.
yahoo.co.jp. 419 IN NS ns10.yahoo.co.jp.
;; Query time: 11 msec
;; SERVER: 192.168.11.1#53(192.168.11.1)
;; WHEN: Sun Dec 9 00:25:35 2007
;; MSG SIZE rcvd: 69
[admin@localhost ~]$
dateコマンドとhwclockコマンド
dateはシステムクロック確認,設定
hwclockはハードウエアクロック確認,設定
dateコマンド
dateコマンドによる時間設定
date [MMDDhhmm[[CC]YY][.ss]]
例) date 120123452007
2007年12月01日11午後11時45分に設定してます。
表示方法は「+」出始めると指定した書式で表示します。
%Y 年
%m 月 (01~12)
%d 日 (01~31)
%H 時 (00~23)
%M 分 (00~59)
%a 曜日 (Sun~Sat)
%b 月名 (Jan~Dec)
[root@localhost home]# date "+%Y/%m/%d (%a)"
2007/12/02 (日)
hwclockコマンド
-r ハードウエアクロック表示
-w ハードウエアクロックをシステムクロックの時間と同じにする
-s システムクロックをハードウエアクロックの時間と同じにする
[root@localhost home]# hwclock -s
[root@localhost home]# hwclock -r
2007年12月02日 00時47分44秒 -0.604682 seconds
[root@localhost home]# date
2007年 12月 2日 日曜日 00:47:48 JST
[root@localhost home]#
正確な時間を設定する必要がある場合は,ntpサーバーを指定する方が良いかも。
ntpdate タイムサーバー
※ntpサーバーを自前で運用する場合は,上位のNTPから時間を受け取りクライアントに配布。(/etc/ntp.conf)
ntp.conf (server / driftfile / logfile)
※クロックの誤差を予測した数値は,/etc/ntp.driftに保存されます。
コマンド
tar , cpio, dd, dump, restoreなど
tarコマンド
ファイルやディレクトリーを一つのファイルにまとめたり,展開したりします。
zオプションをつけると,gzipを利用した圧縮もサポートします。「-」は省略可能。
=================================オプション====================================
-c アーカイブ作成 / -x アーカイブからファイルの取り出し / -t アーカイブの内容を確認 / -f ファイル名指定
-z gzipによる圧縮サポート / -j bzip2による圧縮サポート / -v 詳細表示
-u アーカイブないの同名ファイルより新しいのもだけ追加 / -r アーカイブにファイル追加
-N 指定した日付より新しいデータのみ対象とする。 / -M 複数デバイスへの分割を行う
--delete アーカイブカラファイルを削除する。
============================================================================
※ tar cvf /dev/st0 /home などSCSI接続されたテープドライブにアーカイブ作成なども可能。
アーカイブファイルの中身を表示
[admin@localhost ~]$ tar -tf /home/admin/atmarkit5th.tar.tar
atmarkit5th/
atmarkit5th/ADDRESS.sql
atmarkit5th/atmarkit.ini
atmarkit5th/delete.php
atmarkit5th/grant.sql
atmarkit5th/index.html
atmarkit5th/insert.php
atmarkit5th/insert_form.ini
atmarkit5th/jscripts.ini
atmarkit5th/select.php
atmarkit5th/select_form.ini
atmarkit5th/update.ini
atmarkit5th/update.php
atmarkit5th/image/
atmarkit5th/image/0.gif
atmarkit5th/image/1shori.gif
atmarkit5th/image/back.gif
atmarkit5th/image/henko.gif
atmarkit5th/image/kensaku.gif
atmarkit5th/image/line.gif
atmarkit5th/image/sakujo.gif
atmarkit5th/image/title1.gif
atmarkit5th/image/title2.gif
atmarkit5th/image/uketsuke.gif
atmarkit5th/image/xpress2.gif
[admin@localhost ~]$
アーカイブから特定のファイルのみ取り出す
[admin@localhost ~]$ tar -xvf /home/admin/atmarkit5th.tar.tar atmarkit5th/image/0.gif
CPIOコマンド
=================================オプション====================================
-i アーカイブからファイルを抽出する。 / -o アーカイブを作成する。 / -p ファイルを別のディレクトリにコピーする。
-A 既存のアーカイブにファイル追加 / -d 必要ならディレクトリーを作成 / -r ファイル名を対話的に変更。
-t コピーしないで,入力された内容を一覧表示 / -v ファイル名の一覧を表示
============================================================================
[admin@localhost conf]$ ls /usr/local/apache2/conf/ | cpio -o > /home/admin/backup20071201
99 blocks
[admin@localhost conf]$
詳しくは,このサイトを参照する。
ddコマンド
=================================オプション====================================
if= 入力側ファイルを指定 / of=出力側ファイルを指定 / bs=ブロックサイズ指定 / count=回数分の入力ブロックコピー
============================================================================
※ddコマンドは,デバイス間でのディスク内容のコピーや,ブートディスクの作成などに利用されます。
次の例では,起動ディスクを作成する為に,カーネルイメージをフロッピーディスクにコピーしています。
[admin@localhost ~]$ dd if=boot.img of=/dev/fd0
dumpコマンド
=================================オプション====================================
0~9 dumpレベル指定 / u /etc/dumpdatesにバックアップファイルを記録 / f バックアップ装置指定
============================================================================
バックアップ例
[root@localhost home]# dump 0uf /home/admin/dumpbackup /boot
DUMP: Date of this level 0 dump: Sun Dec 2 00:14:36 2007
DUMP: Dumping /dev/hda1 (/boot) to /home/admin/dumpbackup
DUMP: Label: /boot1
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 8775 blocks.
DUMP: Volume 1 started with block 1 at: Sun Dec 2 00:14:37 2007
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /home/admin/dumpbackup
DUMP: Volume 1 completed at: Sun Dec 2 00:14:39 2007
DUMP: Volume 1 8840 blocks (8.63MB)
DUMP: Volume 1 took 0:00:02
DUMP: Volume 1 transfer rate: 4420 kB/s
DUMP: 8840 blocks (8.63MB) on 1 volume(s)
DUMP: finished in 2 seconds, throughput 4420 kBytes/sec
DUMP: Date of this level 0 dump: Sun Dec 2 00:14:36 2007
DUMP: Date this dump completed: Sun Dec 2 00:14:39 2007
DUMP: Average transfer rate: 4420 kB/s
DUMP: DUMP IS DONE
[root@localhost home]#
[root@localhost home]# ls -l /home/admin/dumpbackup
-rw-r--r-- 1 root root 9052160 12月 2 00:14 /home/admin/dumpbackup
[root@localhost home]# cat /etc/dumpdates
/dev/hda1 0 Sun Dec 2 00:14:36 2007 +0900
[root@localhost home]#
RESTOREコマンド
=================================オプション====================================
r 全てのファイルを取り出す / i 対話的にファイルを取り出す / f バックアップ装置のデバイス指定
============================================================================
リストアのテスト
[root@localhost home]# dump 0f /home/admin/dumpbackup2 /home/www/
DUMP: Date of this level 0 dump: Sun Dec 2 00:17:23 2007
DUMP: Dumping /dev/hda3 (/home (dir /www)) to /home/admin/dumpbackup2
DUMP: Label: /home
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 348 blocks.
DUMP: Volume 1 started with block 1 at: Sun Dec 2 00:17:24 2007
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /home/admin/dumpbackup2
DUMP: Volume 1 completed at: Sun Dec 2 00:17:24 2007
DUMP: Volume 1 480 blocks (0.47MB)
DUMP: 480 blocks (0.47MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Sun Dec 2 00:17:23 2007
DUMP: Date this dump completed: Sun Dec 2 00:17:24 2007
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE
[root@localhost home]#
[root@localhost home]# ls -l /home/admin/dumpbackup2
-rw-r--r-- 1 root root 491520 12月 2 00:17 /home/admin/dumpbackup2
[root@localhost home]# ls
admin administrator lost+found mysql subversion www
[root@localhost home]# rm -rf /home/www
[root@localhost home]# ls
admin administrator lost+found mysql subversion
[root@localhost home]#
[root@localhost home]# restore rf /home/admin/dumpbackup2
./lost+found: (inode 11) not found on tape
./admin: (inode 360449) not found on tape
./mysql: (inode 65537) not found on tape
./subversion: (inode 131073) not found on tape
./administrator: (inode 196609) not found on tape
[root@localhost home]#
リストアされている事を確認。
[root@localhost home]# ls
admin administrator lost+found mysql restoresymtable subversion www
[root@localhost home]#
restoreを実行すると、restoresymtableというファイルがカレントディレクトリに作成されます。増分バックアップをリストアするときにこのファイルを使って、リストアするファイルの情報を得ます。そのため、すべてのリストアが終了するまではこのファイルが必要になります。リストア終了後は不要になるので、削除。
参考URL
リッチサイトはCSSやらJSやら多くのファイルをロードするために,リクエスト回数も増えサーバーも重くなります。
変更が少ないファイルについてはExpiresヘッダを追加することで,ユーザにキャッシュさせリクエスト回数
を減らすことができます。
Apache側でExpiresヘッダをレスポンスに追加することで,このファイルは,~日間までは再リクエストしなくても変更が無いという設定をmod_expiresですることが出来ます。
基本的には静的なファイルや更新されることがほとんど無いファイルはmod_expireにて設定した方が
良い場合が多いです。(gif/jpg, js, css)
mod_expireはApacheのディフォルトモジュールです。
①find . / -name mod_expires.c で.cを探す。
②/home/admin/httpd-2.2.4/modules/metadata/mod_expires.cに発見した.cより.soを作成する。
③cd /home/admin/httpd-2.2.4/modules/metadata/
④/usr/local/apache2/bin/apxs -c mod_expires.c
⑤ls -l mod_expires*
- -rw-r--r-- 1 admin admin 18117 7月 12 2006 mod_expires.c
- -rw-r--r-- 1 admin admin 3971 8月 6 2006 mod_expires.dsp
- -rw-r--r-- 1 admin admin 15 11月 22 2004 mod_expires.exp
- -rw-r--r-- 1 root root 822 8月 31 06:15 mod_expires.la
- -rw-r--r-- 1 root root 324 8月 31 06:15 mod_expires.lo
- -rw-r--r-- 1 root root 29116 8月 31 06:15 mod_expires.o
- -rw-r--r-- 1 root root 0 8月 31 06:15 mod_expires.slo
⑥mod_expire.soファイルの作成
/usr/local/apache2/bin/apxs -i -a -n expires mod_expires.la
⑦/usr/local/apache2/modules/mod_expires.so が作成されたか確認。
⑧/usr/local/apache2/conf/httpd.conf にモジュールロードが追加されているか確認。
LoadModule expires_module modules/mod_expires.so
⑨画像ファイル等のキャッシュを設定
mod_expiresでgif、jpeg等をキャッシュ
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 1 days"
ExpiresByType text/css "access plus 1 days"
ExpiresByType application/x-javascript "access plus 1 days"
</IfModule>
⑩再起動して設定を反映
/usr/local/apache2/bin/apachectl restart
