RHCE学习笔记-253-1

RH253 Red Hat Network Services and security administration
introduction to system services
service management
services are managed several ways:
1 by init /etc/inittab /etc/rc5.d/*
通过inittab里面的启动模式,通过l3:3:wait:/etc/rc.d/rc 3来执行相应的脚本
2 by system V script /etc/init.d/httpd start
3 by direct command
4 by xinetd eg:telnet
services managed by init(init如何管理linux的服务的)
可以直接管理非TCP/IP的服务,如virtual console
提供respawn再生的能力
如cat /etc/inittab
virtual console就拥有再生的能力,ps -t tty1
kill -9 4474
终止后再ps -t tty1
结果还是可以看到
configured in /etc/inittab
system V service management
system V类型的程序的初始化参数包含在sys v script档里,script里并没有程序本身
/etc/init.d/httpd start
service httpd start
whereis service
cat service
service会包含system V的脚本路径
chkcongfig
manages service definitions in run levels
list run level definitions with
chkconfig --list
to start the httpd service on boot
chkconfig httpd on
does no modify current run state of system v services
其实各个runlevel预设的启动设置是在/etc/rc*.d/里
ls -l /etc/rc*.d/*httpd
chkconfig httpd -del
删除每个run levels里httpd的每个link文件
chkconfig httpd -add
添加每个run leves里httpd的每个link文件
cp /etc/init.d/httpd /etc/init.d/myprog
chkconfig myprog -add
xinetd managed services
superdeamon
客户端请求telnet到服务器,telnetd不启动,先把请求提交到xinetd,xinetd再把请求转交到telnetd
chkconfig telnet on
the xinetd daemon
xinetd可以用来管理特殊网络的资源和验证的工作
管理很少会用到的服务,避免很少会用到的服务浪费系统资源
可以用来管理需要验证身份的服务
可以用来对服务做统计以及记录服务的事件记录
可以用来对服务做IP位置的导向
xinetd使用/etc/services设定哪个服务使用哪个端口
连接libwrap.so这个文件来判断允许哪个电脑提出请求或是不允许哪个电脑提出请求,增加安全性
取代了RHEL3时的inetd,增加了服务的安全性,原来使用单一的inetd.conf配置文件
到了xinetd使用配置文件:
/etc/xinetd.conf
/etc/xinetd.d/
单独每个服务的配置文件,安全性比较高
xinetd default controls
统一预设的控制值
/etc/xinetd.conf
defaults
{
instances = 60 可以管理同时执行60个服务
log_type = SYSLOG suthpriv 日志记录类型
log_on_success = HOST PID 登录成功就记录IP和PID
log_on_failure = HOST 登录失败就记录客户端IP
cps = 25 30 如果每秒建立超过25个连接,中断服务30秒
}
xinetd service controls
/etc/xinetd.d/telnet
service telnet
{
flags = REUSE 回收内存,将断开的用户资源回收
socket_type = stream 代表telnet服务使用stream流的方式处理资料
wait = no 允许多人同时连接到telnet服务
user = root 由root用户来管理telnet服务
server = /usr/kerberos/sbin/telnetd 这个目录才是telnet真正的程序
log_on_failure += USERID 登录失败记录IP和使用者的账户
disable = yes 不启用telnet服务
}
the /etc/sysconfig/ files
/etc/sysconfig目录下的文件跟服务有什么关系
常见由以下几个服务会根据这个目录里的配置文件来决定服务是如何执行的
named
sendmail
dhcpd
samba
init
syslog
[root@host ~]# cat /etc/sysconfig/syslog
#Options to syslogd
#-m 0 disables ‘MARK’ messages.
#-r enables logging from remote machines
#-x disables DNS lookups on messages recieved with -r
#See syslogd(8) for more details
SYSLOGD_OPTIONS=“-r -m 0” 允许本机记录远程服务器的log
#Options to klogd
#-2 prints all kernel oops messages twice; once for klogd to decode, and
#once for processing with ‘ksymoops’
#-x disables all klogd processing of oops messages entirely
#See klogd(8) for more details
KLOGD_OPTIONS=“-x”

SYSLOG_UMASK=077
#set this to a umask value to use for all log files as in umask(1).
#By default, all permissions are removed for “group” and “other”.
fault analysis
精确的找出问题的故障点
1 是不是资料本身的问题
2 如果资料没有问题,再检查程序是否有问题
3 是否是操作系统设置问题
4 是否硬件问题
检查日志
也可以使用命令来显示更详细的信息
查看相关和新发布的文档,增加相关知识
security enhanced linux :SELinux
当操作系统判断谁对哪个文件有什么事情
在传统的linux(DAC Discretionary access control)下访问权限根据:user,group,other
在SELinux(MAC Mandatory access control)环境下,由root来控制权限
每个process或object(file, directory, network socket)都有一组security context,一些额外的安全性资料:identity:role:domain/type
security policy(targeted) 定义哪一种操作需要哪些security context权限
例如:/etc/passwd档案,在传统情况下,任何人都可以读取,在SELinux后,限制apache用户不可以读取
sestatus
检查selinux状态
installation options(安装选项)
enforcing 强制启用保护
permissive 启用,但是只提出警告,没有提供保护
disable 不启动selinux
control options when SELinux is enforced(控制选项)
targeted(default)只保护网络相关的服务
strict 保护所有linux的服务
RHEL4目前只支持targeted policy
修改完selinux的配置后需要reboot才生效
controlling SELinux
控制SELinux只对某些特定的服务做安全性的控制
setenforce=0 将模式转为permissive
setenforce=1 将模式转为enforcing
Boolean:0=inactive 1=active
getsebool
getsebool httpd_disable_trans
setsebool
setsebool -P httpd_disable_trans=1 -P会影响到下次启动
这些boolean值存储在/etc/selinux/targeted/booleans
/etc/sysconfig/selinux是selinux的设置档
SELinux contexts
list process contexts:ps -Z
list file contexts:ls -Z
change file contexts: chcon
eg:runcon -t httpd_t cat /etc/passwd
id -Z
troubleshooting SELinux
检查哪里发生错误
/var/log/message for avc denials
有关avc的信息产生
检查档案或process里是否有正确的security context
检查security linux里是否需要调整boolean的设置值
organizing networked systems(DNS,DHCP)
Domain Name System
nameip forward lookup 正向解析
ipname reverse lookup 反向解析
allows machines to be logically grouped by name domains
根据domain name把电脑划分成许多逻辑化的群组
Provides email routing information
DNS还负责email发收时的路由信息
Zones,Domains, & Delegation
Domain就是DNS服务器管辖的范围,负责电脑名称和IP的对应关系
DNS Zone是负责存储这些资料的资料库
我们可以把subdomain里维护名称和IP对应关系的工作委派给另一台DNS来做
也可以全部存储在一台DNS上有一台服务器来维护
Name Server Hierarchy
Master name server
用来存储并维护DNS记录的服务器,可以修改记录。
Slave name server
用来备份DNS Zone记录的DNS服务器,不可修改,只读。
所有salve name servers负责自己所备份的DNS Zone与master name server里的记录一致
复制的过程叫DNS zone transfer
The DNS Server
客户端和服务器之间一般是递归查询,直接返回正确或没有的结果
服务器之间发生反复(迭代)查询,这样的返回的结果有可能是最佳答案而不是正确答案
当收到客户端解析请求的DNS没有这个记录,如果这个DNS去问root zone,那么root返回一个最佳答案,也就是说返回其他DNS;如果去问其他DNS的话,那么其他DNS会返回一个正确的最终答案。
Server receives request
当dns服务器收到请求时,先查看DNS zone,然后看chache,如果没有记录,可能会直接问root,或者转送到其他dns服务器,如果转送到其他dns服务器,回来的是正确结果,如果到root,回答的是最佳答案。
Berkeley Internet Name Domain
在互联网中,BIND是使用最多的DNS服务器
RHEL使用BIND 9
提供稳定可靠的DNS结构
在BIND的DNS服务器中会启用chrooted机制来保护DNS的资料库被入侵的可能性
/var/named/chroot
/var/named/chroot/var/named/db*
Service Profile:DNS
type system V-namaged service
packages bind,bind-utils,bind-chroot
daemons named, rndc(检查安全性)
script named
ports 53(named),953(rndc)
configs under /var/named/chroot
/etc/named.conf 配置文件
/var/named/* 资料库档案
/etc/rndc.* 检查DNS安全性的档案
related caching-nameserver(快速建立caching only DNS server的设定档)openssl (一个资料保护的套件,在复制DNS资料的时候使用openssl的加密机制)
bind-chroot
Config file: /etc/sysconfig/named
define chroot directory ROOTDIR=/var/named/chroot
Configuring BIND
default configuration file is /var/named/chroot/etc/named.conf
当named启动或reload的时候会自动读取设置档里的内容
text-file specifying directive:zones,options,access control lists,etc
comments can be in C,C++ or shell style
Global Options
我们可以在DNS的设定档/etc/named.conf中加上options的参数
options {
directory “var/named”; #设置zone file存储的路径
forwarders {10.0.1.254}; #自己无法解析时,就转发到此处,如果还无法解析时,会转发到root name server,但是如果设置了forwarder only的话,就只会向此DNS查询而不再向root name server查询
allow-query {192.168.2/24;}; #“192.168.2/24”;
allow-transfer {192.168.2/24;};
};
Access Control Lists(acl)
acl是一份清单,列出了哪些IP的使用者具有使用的权限
使用acl为清单命名
acl “mylist” {192.168.0/24;
192.168.1/24;};
让整个设定档比较容易阅读,容易维护
Name Daemon Control Utility(rndc)
提供比较安全的DNS管理机制,可以管理远端的DNS,默认情况下只会监听loopback地址及localhost,rndc并不是一个服务,但是可以被named用来检查rndc所提供的keys有没有问题
Master and Slave Zones
slave zones里的记录只能由master zones复制过来,而且不能修改记录
master zone:
zone “example.com” {
type master;
file “example.com.zone”;
};
Slave zone:
zone “kernel.org” {
type slave;
masters {192.168.0.254;};
file “slave/kernel.org.zone”;
};
zone file的名称必须包含zone名称,通常我们会用zone的名称加上zone
Reverse Lookup Zones
反向解析zone,过程类似于正向解析
主要作用让管理者了解网络情况,例如在log文件中显示FQDN会比显示IP更容易让人理解
安全考虑,有一些服务器会使用IP地址去查询向对应的FQDN,然后再用FQDN去查询IP地址,与要求连线的IP地址是否一致
zone name ends with special domain: in-adde.arpa
eg:
zone “1.0.10.in-adde.arpa”{
type slave
master {10.0.1.254;};
file “slave/10.0.1.zone”;
};
Root Zone and Lookback Zone
root zone: “.”
zone “”
type hint;
file “named.ca”;
};
loopback zone:”0.0.127.in-adde.arpa”
zone “0.0.127.in-addr.arpa” {
type master;
file “named.local”;
};
Zone Files
通常zone file存放在/var/named/chroot/var/named
所有zone files会以$TTL为开头,限制其他DNS可以cache这台DNS上记录多久
第一笔record一定是SOA记录
然后才是资料内容
Resource Records
[domain][ttl][class]
domain 定义所在domain或定义名称
ttl 当其他DNS cache这个记录时的时间
classs IN,代表internet
type record type SOA,MX,A,etc
rdata 这笔记录所要记录的内容
SOA (Start of Authority)
每个zone file都会有一个SOA,起始的授权机构
并且会放在file最开始的地方,记录了是由哪台DNS负责维护的及这个zone file由谁来管理
2001101100 serial number 版本信息
10800 refresh 以秒为单位的时间,3个小时slave会检查master记录是否更新
3600 retry query 以秒为单位,如果refresh时间到了,但slave却联系不到master server时,每隔retry query时间会在此尝试连接
604800 expire 以秒为单位,如果超过expire后,slave还没有联系到master server的话,那么slave server就会删除掉自己备份的zone file
0 negative TTL cache查询不到的记录多久
)
NS(Name Server)
定义某个domain的由哪台DNS server负责解析的,在每一个zone里都至少有一个指向domain server的NS记录
在zone里指定一个指向slave server的NS记录是当master宕机或是没办法提供服务的时候可以有一个DNS server提供服务
example.com. IN NS ns.example.com.
如果有两个NS记录,那么第一个会指向master,第二个指向slaver
Main Record Types
A records map hostname to IP address
mail IN A 192.168.0.2 如果mail没有以点结束,那么系统自动会加上后缀,成为mail.example.com
ns.example.com IN A 192.168.0.3 如果输入完成的主机名称的话必须以点结束
CNAME records
www IN CNAME ns1
dns IN CNAME ns.example.com
通常会以这台主机提供的服务来为它起别名
PTR records
3.0 IN PTR ns.example.com.
MX records
example.com. IN MX 5 mail.example.com.
example.com. IN MX 10 mail1.example.com.
定义有哪台服务器提供mail server,优先权,数字小优先权高
Example Zone File
forward lookup zone
SOA record
NS record
A record
cd /var/named/chroot/var/named/
vi example.com.zone
[root@host named]# vi example.com.zone
$TTL 86400
@ IN SOA example.com. root.example.com. {
20080573100 ;serial number
10800 ;refresh slave
3600 ;retry query
604800 ;expire
0 ;negative TTL
}
@ IN NS ns.example.com.
ns IN A 192.168.8.3
ls -l example.com.zone
-rw-r–r-- 1 root root 320 03-31 12:49 example.com.zone
我们要把这个档案的权限修改一下
chown named:named example.com.zone
reverse lookup zone
SOA record
NS record
PTR record
vi 192.168.1.zone
$TTL 86400
@ IN SOA example.com. root.example.com.{
2008052100 ;serial number
10800 ;refresh slave
3600 ;retry query
604800 ;expire
0 ;negative TTL
}
@ IN NS ns.example.com.
3 IN PTR ns.example.com.
ls -l 192.168.1.zone
chown named:named 192.168.1.zone
Round Robin Load Sharing Through DNS
DNS轮询和负载均衡
在DNS里设置多个A records,实现负载均衡
www 0 IN A 192.168.0.1
www 0 IN A 192.168.0.2
www 0 IN A 192.168.0.3
0就是TTL为0,不cache,DNS会随机回复客户端的请求,使用round robin的方式会使DNS的流量非常大,其他DNS就不能cache这个记录,每次有查询的时候必须要到此DNS上,所以说流量比较大。
Delegating Subdomains
可以为subdomian建立一个zone,并建立一个DNS服务器维护这个zone的记录
sub.example.com IN NS dns1.sub.example.com
dns1.sub.example.com IN A 192.168.10.1
BIND Syntax Utilities
检查DNS语法设置的工具
当语法设置有误的时候BIND就无法启动
named-checkconf
默认情况下检查/var/named/chroot/etc/named.conf
named-checkzone
会去检查我们设定的zone file里面语法有无错误
named-checkzone example.com /var/named/chroot/var/named/example.com.zone
Caching-only Name Server
在一台DNS服务器里共有5种zone file,网络正解档,网络反解档,look server正解档,本机正解档,本机反机档
但在caching-only name server里只有look server正解档这种zone file,当收到客户机的请求时,先在本地cache里招,如没有forward到设置好的其他的DNS server上,并不会转发到root DNS。等其他dns server返回结果后,再将结果返回给客户机,并cache此记录
必须设置forward,cache results,首先确认是否安装caching-nameserver RPM包,如安装了会提供一个named.conf配置文件,使用这个档就可以让cache-only name server正常工作,另外还提供了lookserver所在路径
BIND Utilities
BIND提供的工具
bind-utils RPM
host 解析某台主机或domain名 eg:host www.sina.com.cn
host -a sina.com.cn | grep [;]
dig 用来查询某台特定的NS server
dig @ns.redhat.com redhat.com | grep [;]
dig @ns.redhat.com redhat.com mx | grep [;]
nslookup
查询internet name server,有interactively mode和non-interactively mode
set type=mx
non-interactively mode
nslookup yahoo.com ns.redhat.com
LABS
caching-only name server
rpm -qa | grep caching-nameserver
rpm -qa | grep bind
vi /etc/hosts
至少有2个记录:127.0.0.1 localhost.localdomain localhost
192.168.8.100 ns.example.com ns
vi /etc/resolv.conf
确认目前的name server是202.102.224.68
改为自己
vi /var/named/chroot/etc/named.conf
option加forwards {202.102.224.68};
forward only; 表示只要把请求包转发出去就行了,不需要再向其他DNS SERVER请求
配置named.conf,修改example.zone
Slave name server
Master name server
Advanced BIND Features
DDNS,动态更新的DNS,通过DHCP SERVER及时把客户机的IP和名称更新过来
transfer过程加密TSIG
DHCP Overview
提供DHCP,BOOTTP
Service Profile:DHCP
type syste V-managed service
packages dhcp
daemons dhcpd
script dhcpd
ports 67(bootps server端),68(bootpc client端)
configuration /etc/dhcpd.conf
/var/lib/dhcpd.leases
related dhclient
Configuring a DHCP Server
/etc/dhcpd.conf
在/usr/share/doc/dhcp-/有个模板
cp /usr/share/doc/dhcp-3.0.1/dhcp.conf.sample /etc/dhcp.conf
发布IP范围在一个网段和服务器IP在一个网段
rpm -aq | grep dhcps

network file sharing services(NFS,FTP,SAMBA)
network file service(NFS)
在/etc/exports中设置要共享的目录
当NFS修改了配置的时候,使用命令:exportfs -r更新共享清单
使用mount命令就可以使用NFS server分享出来的目录
NFS serever是使用RPC server,必须用到portmap服务
rpcinfo -p
service profile:NFS
type system V-managed service
packages nfs-utils
daemons nfsd, lockd, rpciod, rpc{mountd,rquotad,statd}
ports assigned by portmap(111),必须开放111
configuration /etc/exports
related portmap(mandatory)

[root@host ~]# vi /etc/exports
/tmp *(ro,sync) #*代表任何电脑都可以访问,ro只读,sync,当服务器有改变的时候同步客户端
[root@host ~]rpcinfo -p
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 1006 status
100024 1 tcp 1009 status
/etc/init.d/nfs start
[root@host ~]rpcinfo -p
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 1006 status
100024 1 tcp 1009 status
100011 1 udp 771 rquotad
100011 2 udp 771 rquotad
100011 1 tcp 774 rquotad
100011 2 tcp 774 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 32776 nlockmgr
100021 3 udp 32776 nlockmgr
100021 4 udp 32776 nlockmgr
100021 1 tcp 48422 nlockmgr
100021 3 tcp 48422 nlockmgr
100021 4 tcp 48422 nlockmgr
100005 1 udp 804 mountd
100005 1 tcp 807 mountd
100005 2 udp 804 mountd
100005 2 tcp 807 mountd
100005 3 udp 804 mountd
100005 3 tcp 807 mountd
当客户端连接NFS服务器的时候,客户端先通过本地的rpc.mountd连到s的portmapper,portmapper指定port号给c,客户端的rpc.mountd连到s的mountd做mount动作,mount之后,c的rpciod和s的nfs负责读取和写入资料,c的nlockmgr和s的nlockmgr负责资料的一致性,c的status和s的status负责连线的状态

NFS Server
根据/etc/exports的设置来共享目录,每一行代表一个目录和访问设置。
/data *.example.com(ro,sync) server1,redhat.com(rw,sync)
/data1 192.168.1.0/255.255.255.0(sync)
showmount -e 192.168.0.1 查看服务器端共享了哪些目录
当c用root账户在NFS SERVER上建立档案时,会用UID=4294967294(2的32次方减2)
叫root_squashing,为了区分s的root和c的root,如想取消这个功能,不建议
/data *.example.com(ro,sync,no_root_squash)
RPC:Unable to receive,可能因为防火墙。
Nfs客户端各个用户建立的文件时只会记录user id,而不是名称,会对照server端的user id来显示用户信息。
client-side NFS
/etc/fstab可以添加网络中的共享资源以开机自动挂载
vi /etc/fstab
192.168.0.1:/opt /nfsdata nfs ro,soft,intr,timeo=1 0 0
soft当NFS有错误时返回错误信息,hard(default)当NFS有错误时一直尝试,intr=allow interruption,nointr(default)=not allow interruption,timeo:time out(sec)
在开机时系统使用/etc/rc.d/init.d/netfs来挂载网络上的共享目录
NFS网络共享的功能也可以应用在autofs的服务上,当需要NFS资源时才挂载起来,当闲置时间太久时自动断开,避免NFS SERVER负载太重
NIS(Network Information Service) Overview
假设有个用户tom,需要登陆到多台服务器,但是太麻烦,NIS SERVER只要建立一个tom用户,负责用户的身份验证,通过后就可以登陆服务器,存放资料的地方叫NIS db,通常有一台MASTER SERVER和多台SLAVE SERVER,NIS不太安全
Service Profile:NIS
type system V-managed service
packages ypserv
daemons ypserv,rpc.yppasswdd
scripts ypserv,yppasswdd
ports dynamically assigned by portmap
configuration /etc/sysconfig/network,/var/yp/*,/etc/ypserv.conf
也是RPC类的服务,使用portmapper来管理C和S之间的端口
C通过ypbind连接portmapper,portmapper指定port给C,C的ypbind和S的ypserv连接进行认证,当C的用户修改密码时,C的yppasswd跟S的yppasswd连接进行修改
NIS Server Configuration
检查是否安装了portmap and ypserv RPMs
set NIS domain name
in /etc/sysconfig/network insert the line:
NISDOMAIN=your-domain-name
in /var/yp/securenets,specify the network that may use your server or not
[root@host ~]# vi /var/yp/securenets
255.255.255.0 192.168.0.0
start ypserv
/etc/init.d/ypserv start
Configuring a Master Server
NIS database里是由NIS SERVER上的/etc/passwd,/etc/shadow转换而来的
放在/var/yp/
要转换哪些档案在/var/yp/Makefile里设置
假设我们只想转换用户,组及host名称信息可以编辑/var/yp/Makefile
NOPUSH=true #在只有一台NIS的时候设置为true
MINUID=500 #只转换UID大于500的用户
MINGID=500 #只转换GID大于500的组
然后再建立NIS的资料库,/usr/lib/yp/ypinit -m
会建立/var/yp/,由/etc/sysconfig/network定义的
启动yppasswdd服务允许C端的用户更改密码
Configuring a Slave Server
所有SLAVE SERVER的清单设置在MASTER SERVE的/var/yp/ypservers的文件中
当MASTER SEREVER工作正常后,就可以在SLAVE SERVER上执行
/usr/lib/yp/ypinit -s example.domain.com将MASTER的资料库同步到SLAVE上
如果在MASTER上用户资料有变动的话必须将变动PUSH到SLAVE
cd /var/yp;make
NIS Client configuration
C端如何假如NIS的domain
必须安装ypbind and portmap RPMs
执行authconfig
起用NIS功能,允许NIS提供用户信息以便用户登陆电脑
需要指定NIS SERVER和NIS DOMAIN NAME
同时可以保持本机原来的认证方式

我们可以将NIS的/home目录mount到client端,这样用户在登陆到电脑时就可以使用/home/user的目录了。
vi /etc/exports
/home 192.168.0.0/255.255.255.0(rw,sync)
C端,mount 192.168.0.1:/home /home
mount的方式有缺点,造成NIS很大的负担,可以改用Automount
在NIS建立目录nishome
chmod 1777 /nishome
useradd -u 5001 -d /nishome/nis1 nis1
vi /etc/exports
/nishome *(rw,sync)
exporfs -r
vi /var/yp/Makefile
MINUID=5001
MINGID=5002
cd /var/yp;make
在客户端authconfig
vi /etc/auto.master
/nishome /etc/auto.nis --timeout=60
cp /etc/auto.misc /etc/auto.nis
vi /etc/auto.nis
nis1 -rw,soft,intr 192.168.0.1:/nishome/nis1
nis2 -rw,soft,intr 192.168.0.1:/nishome/nis2
nis3 -rw,soft,intr 192.168.0.1:/nishome/nis3
如果用户很多可以使用
* -rw,soft,intr 192.168.0.1:/nishome/&
mkdir /nishome
service autofs restart
NIS Troubleshooting
Check log files in /var/log for errors first
ls the default firewall still turned on
are services running and registered with portmap?
rpcinfo -p hostname
rpcinfo -p 192…168.0.1
查看指定主机的portmap信息
有没有关于ypservd的服务要使用哪些端口的信息
在客户端可以使用ypwhich命令来检查使用哪个NIS SERVER做身份认证的
用在客户端使用ypcat and getent查看NIS资料库里的资料
ypcat hosts #查看NIS hosts资料
ypcat passwd #查看NIS passwd的资料
getnet hosts #也可以查看NIS hosts资料
ypcat是只查看NIS database的信息,getent不止查看NIS database信息,还可以查看NIS SERVER的信息
getent passwd #查看NIS上所有passwd的信息
File Transfer Protocol(FTP)
vsftpd – the default RHEL ftp server
no longer managed by xinetd
默认情况下只允许匿名用户和本机用户访问
在ftp里,分两种访问类型
匿名用户访问
可以用ftp或anonymous用户匿名登陆
默认情况下匿名登陆的用户会使用change-rooted机制只允许访问/var/ftp
并且匿名用户只允许下载文件,不允许上传
user accesss
使用ftp server上的用户信息登陆,登陆后根据用户对此文件/文件夹的权限进行操作
/etc/vsftpd/vsfdpd.conf is the main configuration file
#chroot_list_enable=YES将使用者锁定在家目录
anonymous_enable=YES允许匿名登陆
chroot_list_file=/etc/vsftpd/chroot_list 根据后面文件里设置来确定哪些用户启用chroot机制
ftp_banner welcome to this ftp server
如果需要用户切换目录后提示信息,在那个目录里添加.message文件,在这个文件中设置:
cat > /var/ftp/pub/.message
This is /var/ftp/pub directory
使用匿名登陆后根目录是/var/ftp,也只能使用这个目录
Service Profile:FTP
type system V-managed service
packages vsftpd
daemons vsftpd
script vsftpd
ports 21(ftp),20(ftp-data)
configuration /etc/vsftpd/vsftpd.conf /etc/vsftpd.ftpusers
logs /var/log/vsftpdd.log
/etc/vsftpd.ftpusers可以定义登陆的用户 #各种发行版可能不同,centos使用/etc/vsftpd/ftpusers
vi /etc/vsftpd/user_list 也是定义用户登陆的设置
vi /etc/vsftpd/vsftpd.conf
userlist_enable=YES #这里设置是否启用vsftpd/user_list这个清单
vi /etc/hosts.deny" #定义限制的IP
vsftpd:192.168.1 #整个1段都不允许访问此机的vsftpd服务
192.168.1.0/255.255.255.0
是匿名用户可以上传:
mkdir /var/ftp/incoming
chown root.ftp /var/ftp/incoming
chmod 730 /var/ftp/incoming
ls -ld /var/ftp/incoming
vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
anon_upload_enable=YES
chown_uploads=YES
chown_username=whoever
anon_umask=077
避免匿名用户上传重名文档,覆盖以前的文档。
Samba services
Unix/Linux和microsoft之间共享文件,使用SMB(server message block) protocol
在SMB服务里,提供了四个主要的服务
验证使用者并授予相应权限
可以共享文件和打印机
提供NETBIOS的名称解析,也就是说可以扮演WINS
资源浏览
samba daemons
smbd
验证使用者并授予相应权限
可以共享文件和打印机
nmbd
提供NETBIOS的名称解析,也就是说可以扮演WINS
资源浏览
service profile:SMB
type system V-managed service
packages samba{-common,-client,-swat} #swat默认不会安装
daemons smbd,nmbd
script smb
ports:(netbios) 137(-ns netbios),138(-dgm data),139(-ssn netbios session)
configuration /etc/samba/smb.conf,/etc/samba/*
related system-config-samba,samba-swat
logs /var/log/samba/*
configuring samba
可以通过以下方式配置
/etc/samba/smb.conf
system-config-samba
samba-swat
使用浏览器进行配置,端口号901
比system-config-samba提供更多的功能
yum -y install samba-swat #在线安装swat
swat是xinetd管理的服务
先启动,在浏览器输入http://localhost:901,使用root用户登陆,在别的发行版不一定支持
建议使用/etc/samba/smb.conf方式
overview of smb.conf sections
smb.conf中使用[]来区分不同的部分
[global] 整台SMB服务器的设置
[homes] 用户家目录的设置
[printers] 打印机的共享设置
configuring file and directory sharing
some options to use:括号内为默认值
public(no):是否可用guest这个匿名帐户来访问共享的资源
browsable(yes):设置C端在网络里是否可以浏览共享的资源
writable(no):设置是否有写入权限
printable(no):设置是共享的打印机还是一般文件
group:设定登陆来的用户使用哪个组作为他的主要组
printing to the samba server
所有打印机的配置在/etc/cups/printers.confs
vi /etc/samba/smb.conf
[printers]
comment = printer A
printer = printera
valid users = jacky tom mary
path = /var/spool/printera
browseable = no
guest ok = no
writable = no
printable = yes
通过smb.conf设置需要共享的printers
echo 1234 | passwd --stdin tom 把tom的密码设置为1234
authentication methods
使用者身份验证的方式通过security = 设置
share 不进行验证
user 使用本机帐户进行验证,并不是shadow的资料,而是/etc/samba/smbpasswd
domain 使用NT 4.0的DC进行验证
ads 交给AD,使用kerberos的方式
passwords
SMB用户管理使用smbpasswd命令
但是必须已经是本机使用者帐户或winbindd服务的帐户,winbindd是用来整合Linux、LDAP、AD的帐号的服务
tail /etc/passwd
cat /etc/samba/smbpasswd
smbpasswd -a tom
smbpasswd tom #修改tom的密码
smbpasswd -d tom #disable tom
smbpasswd -e tom #enable tom
smbpasswd -x tom #delete tom
samba client tools:smbclient
smbclient //machine/share #UNC path
>cd directory
>get file
显示区域网络里有哪些分享的资源
smbclient -L hostname
需要输入密码的形式是smbclient -L hostname -U user%password
nmblookup
用这个命令查看WINS上某台电脑的情况
nmblookup -U WINS Server -R ‘name’
list all machines
nmblookup * #以广播的形式查看,查询网段里所有电脑的IP
smbmount(mount)
使用smbmount或mount将SMB SERVER上分享出来的资源mount到本机
mount //server/share /mnt/smb -o username=USER%PASSWD
samba mounts in /etc/fstab
在开机时自动挂载SMB SERVER的资源
mkdir /mnt/smb
vi /etc/fstab
//192.168.0.1/myshare /mnt/smb smbfs default,username=tom%1234 0 0

猜你喜欢

转载自blog.csdn.net/imtech/article/details/128633985