安裝套件 perl-Net-IP
# yum install -y perl-Net-IP
# iptab
# iptables -A INPUT -p tcp -m tcp --dport 65534 -j ACCEPT
# nc -l 65534 // 開啟本地通訊埠 65534,參數 -l:listening
i
love
you
# nc 192.168.18.128 65534
i
love
you
# nc -v 192.168.18.128 -z 80
Connection to 192.168.18.128 80 port [tcp/http] succeeded!
# nc -v 192.168.18.128 -z 110
Connection to 192.168.18.128 110 port [tcp/pop3] succeeded!
# rpm -ivh xxx.rpm // 本地安裝
# rpm -ivh http://aaa.bbb.com/xxx.rpm // 網路安裝
# rpm -Fvh pidgin-2.7.9-5.el6.2.x86_64.rpm // 無後續安裝步驟
# rpm -Uvh pidgin-2.7.9-5.el6.2.x86_64.rpm // 執行安裝步驟,但相依性檢查失敗中斷安裝
error: Failed dependencies:
libgstfarsight-0.10.so.0()(64bit) is needed by pidgin-2.7.9-5.el6.2.x86_64
libpurple = 2.7.9-5.el6.2 is needed by pidgin-2.7.9-5.el6.2.x86_64
libpurple.so.0()(64bit) is needed by pidgin-2.7.9-5.el6.2.x86_64
# rpm -e firefox
# rpm --import ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/x86_64/RPM-GPG-KEY-CentOS-6
# rpm -K firefox-10.0.10-1.el6.centos.x86_64.rpm
firefox-10.0.10-1.el6.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
# rpm -K google-chrome-stable_current_x86_64.rpm
google-chrome-stable_current_x86_64.rpm:(SHA1) DSA sha1 md5 (GPG) NOT OK (MISSING KEYS:
GPG#7fac5991) // 用 CentOS 的 key 來驗證 google 的套件
# rpm -qf /etc/ntp.conf
ntp-4.2.4p8-2.el6.centos.x86_64
# rpm -qi httpd
# rpm -qa
# rpm -q httpd
# rpm -ql ntp
/etc/dhcp/dhclient.d
/etc/dhcp/dhclient.d/ntp.sh
/etc/ntp.conf
........
# rpm -qs httpd | tail -n4
normal /var/www/icons/world1.gif // normal 表示安裝正常
normal /var/www/icons/world1.png
normal /var/www/icons/world2.gif
normal /var/www/icons/world2.png
........
# rpm -qR httpd
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(VersionedDependencies) <= 3.0.3-1
rtld(GNU_HASH)
system-logos >= 7.92.1-1
rpmlib(PayloadIsXz) <= 5.2-1
........
# rpm -q --scripts httpd
# rpm -qp pidgin
# rpm -qpl pidgin
# rpm -qpR pidgin
# rpm -qpi pidgin
# rpm -q --scripts pidgin
補充:不能與參數 s 同時使用,因為還沒有安裝,不會有安裝時的狀態。
# rpm -ivh --replacepkgs vsftpd
補充:此參數也可以解釋為 reinstall,但並不會覆蓋原先的檔案,只是將缺少的檔案再補回去。
# rpm -Vf /etc/httpd/conf/httpd.conf
S.5....T. c /etc/httpd/conf/httpd.conf // 若檔案未遭到改變,就不會出現此行訊息
# rm -rf /etc/vsftpd/vsftpd.conf
# rpm -V vsftpd
missing c /etc/vsftpd/vsftpd.conf
# yum search scsi | grep --color target
scsi-target-utils.x86_64 : The SCSI target daemon and utility programs
# yum install -y scsi-target-utils // 安裝 iSCSI Target 套件
# cp /etc/tgt/targets.conf /etc/tgt/targets.conf.backup // 備份原始設定檔
# fdisk -l
Disk /dev/sdb: 1073 MB, 1073741824 bytes // 使用 VMware Player 配置了一個 1GB
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
# fdisk /dev/sdb // 配置分享磁區,不用格式化
# fdisk -l
# vim /etc/tgt/targets.conf // 設定分享磁區
<target iqn.2012-10.com.example:server.target1="iqn.2008-09.com.example:server.target1">
backing-store /dev/sdb1
</target>
# service tgtd start
Starting SCSI target daemon: [ OK ]
# iptables -A INPUT -p tcp -m tcp --dport 3260 -j ACCEPT
# yum search scsi | grep --color initiator
iscsi-initiator-utils.i686 : iSCSI daemon and utility programs
# yum install -y iscsi-initiator-utils.i686 // 安裝 iSCSI Initiator 套件
# iscsiadm -m discovery -t st -p 192.168.18.128 // 搜尋定分享磁區
Starting iscsid: [ OK ] // 啟動 iSCSI Initiator 服務
192.168.18.128:3260,1 iqn.2008-09.com.example:server.target1
# iscsiadm -m discovery -t st -p 192.168.18.128 -l
# iscsiadm -m node -l // -l:login;-u:logout
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target1, portal: 192.168.18.128,3260] (multiple)
Login to [iface: default, target: iqn.2008-09.com.example:server.target1, portal: 192.168.18.128,3260] successful.
補充:以下 2 種方式皆可登入。
# dmesg | tail
# fdisk -l
# fdisk /dev/sdb
# fdisk /dev/sdc
# mkfs.ext4 /dev/sdb1 ; mkfs.ext4 /dev/sdc1
# mkdir /mnt/iscsi1
# mkdir /mnt/iscsi2
# mount /dev/sdb1 /mnt/iscsi1
# mount /dev/sdc1 /mnt/iscsi2
# vim /etc/fstab
/dev/sdb1 /mnt/iscsi1 ext4 _netdev 1 2 // 裝置名稱亦可使用 UUID,使用指令# blkid /dev/sdb1 查看
/dev/sdc1 /mnt/iscsi2 ext4 _netdev 1 2
# mount -a
# df
/dev/sdb1 2060144 35840 1919656 2% /mnt/iscsi1
/dev/sdc1 1027004 17668 957168 2% /mnt/iscsi2
# iscsiadm -m node -u
# chkconfig iscsi off
# chkconfig iscsid off
# yum install -y gpm
# yum install -y tcp_wrappers
# ldd $(which http vsftpd sshd) | grep -E 'libwrap|bin'
/usr/sbin/httpd:
/usr/sbin/vsftpd:
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007ff8725a9000)
/usr/sbin/sshd:
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007fcfbca96000)
由以上結果可知 httpd 服務並不支援 TcpWrappers 功能,故在 /etc/hosts.allow 或 /etc/hosts.deny 設定規則,並不會產生任何作用。
# vim /etc/hosts.deny
ALL: ALL
# vim /etc/hosts.allows
sshd: ALL EXCEPT 192.168.18.132
# ssh 192.168.18.128
The authenticity of host '192.168.18.128 (192.168.18.128)' can't be established.
RSA key fingerprint is a1:2b:03:12:a5:f4:a9:1d:eb:52:b2:d4:2f:f3:66:d6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.18.128' (RSA) to the list of known hosts.
root@192.168.18.128's password:
Last login: Sun Sep 23 22:50:12 2012
// 登入成功
# hostname
host128.ntucc.edu.tw
# ssh 192.168.18.128
ssh_exchange_identification: Connection closed by remote host // 登入失敗
# iptables-save | grep '\-A' | nl -bt
# iptables -L INPUT --line-numbers
# vim /var/www/html/index.html // 記得防火牆要開
<h1> SSH Tunnel </h1>
# ssh -L 65534:192.168.18.128:80 lee@192.168.18.129
# elinks http://localhost:65534
# netstat -anp | grep --color sshd
tcp 0 0 192.168.18.129:22 192.168.18.131:60861 ESTABLISHED 3014/sshd
# tail -f /var/log/httpd/access_log
192.168.18.129 - - [25/Sep/2012:05:06:40 -0700] "GET / HTTP/1.1" 200 22 "-" "ELinks/0.12pre5 (textmode; Linux; 80x24-2)"
# route add -net network/netmask gw router_ip // network 是指網段,netmask 可以用 prefix
# ip route add network/netmask via router_ip
# vim /etc/sysconfig/network-scripts/route-iface
ADDRESSX = 網段 // 『X』從『0』開始
NETMASKX = netmask
GATEWAYX = router_ip
# ll -d /proc/
dr-xr-xr-x. 171 root root 0 Oct 5 20:10 /proc/
# sysctl -a
# sysctl -a | grep --color icmp
net.ipv4.ip_forward = 0
net.ipv4.icmp_echo_ignore_all = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
...
# sysctl -w net.ipv4.icmp_echo_ignore_all=1 // 等號不能有空格
# sysctl -w net.ipv4.ip_forward = 1
# vim /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all = 1
net.ipv4.ip_forward = 1
# sysctl -p // 不用重開機就能生效
# echo "net.ipv4.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf
# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
# tcpdump -D
1.eth0
2.usbmon1 (USB bus number 1)
3.usbmon2 (USB bus number 2)
4.any (Pseudo-device that captures on all interfaces)
5.lo
# echo $?
0
# ls -lt // 最新的檔案在最上面
# ls -ltr // 最舊的檔案在最上面
# chkconfig ntpd on
# chkconfig --list ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# service ntpd start
Starting ntpd: [ OK ]
# service ntpd status
ntpd (pid 3633) is running...
# vim /etc/ntp.conf
server time.stdtime.gov.tw iburst // iburst 加速對時
# service ntpd restart
# ntpdate time.stdtime.gov.tw
19 Sep 10:16:32 ntpdate[3707]: the NTP socket is in use, exiting // 必需關閉 NTP
# service ntpd stop
# ntpdate time.stdtime.gov.tw
19 Sep 10:17:07 ntpdate[3758]: step time server 59.124.196.84 offset 1.352043 sec
# crontab -e
*/10 * * * * /usr/sbin/ntpdate time.stdtime.gov.tw && hwcolck -w
# date 01010909 // 調整成錯誤時間,以測試排程是否有正常動作
Sun Jan 1 09:09:00 CST 2012
// 10 分鐘後會自動網路校時成正確時間
# date
Wed Sep 19 10:51:57 CST 2012
# netstat -nap | grep ntp // NTP 的通訊埠號為 123
ntpstat
synchronised to NTP server (59.124.196.84) at stratum 3
time correct to within 1000 ms
polling server every 64 s
# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*59-124-196-84.H 59.124.196.86 2 u 8 64 1 19.389 39.112 6.558
# date
Wed Sep 19 11:22:27 CST 2012
# ls /usr/share/zoneinfo/Asia/ | grep --color Taipei
Taipei
# vim /etc/sysconfig/clock
ZONE="Asia/Taipei"
# \cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime
# date
Wed Sep 26 20:56:04 CST 2012
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT
# vim /etc/ntp.conf
restrict 140.112.163.58
# ntpdate 主機 A_IP
19 Sep 15:20:53 ntpdate[8971]: adjust time server
主機 A_IP offset 0.184811 sec
# vim /etc/yum.repos.d/nsysu.repo
[nsysu]
name=nsysu
baseurl=ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/i386/
enabled=1
gpgcheck=1
gpgkey=ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/i386//RPM-GPG-KEY-EPEL-6
# yum upgrade [-y] rpm // -y 自動安裝
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* epel: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: centosa5.centos.org
......
Dependencies Resolved
==================================================================================
Package Arch Version Repository Size
==================================================================================
Updating:
rpm i686 4.8.0-27.el6 base 898 k
Updating for dependencies:
rpm-libs i686 4.8.0-27.el6 base 313 k
rpm-python i686 4.8.0-27.el6 base 53 k
Transaction Summary
==================================================================================
Upgrade 3 Package(s)
Total download size: 1.2 M
Is this ok [y/N]: 詢問是否安裝
# yum info vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* epel: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: centosa5.centos.org
Installed Packages
Name : vsftpd
Arch : i686
Version : 2.2.2
Release : 11.el6
Size : 344 k
Repo : installed
From repo : base
Summary : Very Secure Ftp Daemon
URL : http://vsftpd.beasts.org/
License : GPLv2 with exceptions
Description : vsftpd is a Very Secure FTP daemon. It was written completely from : scratch.
# yum search vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* epel: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: centosa5.centos.org
============================= N/S Matched: vsftpd ============================
vsftpd.i686 : Very Secure Ftp Daemon
Name and summary matches only, use "search all" for everything.
# yum provides */sshd_config
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* epel: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: centosa5.centos.org
openssh-server-5.3p1-81.el6.i686 : An open source SSH server daemon
Repo : base
Matched from:
Filename : /etc/ssh/sshd_config
# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base epel extras isu updates
Cleaning up Everything
Cleaning up list of fastest mirrors
# yum reinstall vsftpd
# yum check-update openssh
# yum remove vsftpd
# yum localinstall vsftpd
grouplist
groupinstall
grouperase
groupinfo
# ifconfig eth0:0 192.168.0.1/24
# ip addr add 192.168.0.1/24 dev eth0 label eth0:0
# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.0.1
PREFIX=24 // NETMASK 255.255.255.0
ONPARENT=yes
# service network restart
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-band0
# vim /etc/sysconfig/network-scripts/ifcfg-band0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
BONDING="mode=1 miimon=50" // mode 1:Active-Backup
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=52:54:00:6b:bf:b2
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
MASTER=bond0
SLAVE=yes
# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=52:54:00:11:fe:26
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
MASTER=bond0
SLAVE=yes
# vim /etc/modprobe.d/bonding.conf
alias bond0 bonding
# cat /proc/net/bonding/band0
# yum install -y nfs-utils rpcbind
# chkconfig nfs on
# chkconfig rpcbind on
# service rpcbind start // 先啟動
# service nfs start
# iptables -F
# vim /etc/exports
/var/ftp *(ro)
# service nfs restart
# exportfs -rv // 參數『v』代表詳細模式,可以不用加
# rpcinfo -p 10.10.10.128 // 查看 NFS 伺服器是否有提供 NFS 服務
# showmount -e 10.10.10.128
Export list for 10.10.10.128:
/var/ftp *
# mkdir /mnt/nfsclient
# mount 10.10.10.128:/var/ftp /mnt/nfsclient
# df
檔案系統 1K- 區段 已用 可用 已用 % 掛載點
10.10.10.128:/var/ftp 15163392 2951168 11441664 21% /mnt/nfsclient
注意:無法對資料夾 /mnt/nfsclient 進行新增刪除的操作。
# vim /etc/fstab
nisserver128.example.com:/var/ftp /mnt/nfsclient nfs ro 0 0
# vim /etc/sysconfig/nfs
RQUOTAD_PORT=875
LOCKD_TCPPORT=32769
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 111 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 875 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 875 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 32769 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 32769 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 662 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 662 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 892 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 892 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 2049 -j ACCEPT
# service nfs restart
client # mount nfs_server_ip:/var/ftp /mnt/nfsclient
mount.nfs: access denied by server while mounting nfs_server_ip:/var/ftp
client # showmount -e nfs_server_ip
Export list for nfs_server_ip:
/var/ftp 10.10.10.128