二 网络服务的配置

 在这一部分 , 我们并不是详细的介绍具体的网络服务器 (DNS,FTP,WWW,SENDMAIL) 的配置 ( 那将是巨大的篇幅 ), 而是介绍一下与 linux 网络服务的配置相关的文件 .

1. LILO 的配置文件

  在 linux 系统中 , 有一个系统引导程序 , 那就是 lilo(linux loadin), 利用 lilo 可以实现多操作系统的选择启动 . 它的配置文件是 /etc/lilo.conf. 在这个配置文件中 ,lilo 的配置参数主要分为两个部分 , 一个是全局配置参数 , 包括设置启动设备等等 . 另一个是局部配置参数 , 包括每个引导影像文件的配置参数 . 在这里我就不详细介绍每个参数 , 特别的仅仅说明两个重要的参数 --------password 和 restricted 选项 ,password 选项为每个引导的影像文件加入口令保护 . 我们都知道 , 在 linux 系统中有一个运行模式是单用户模式 , 在这个模式下 , 用户是以超级用户的身份登录到 linux 系统中 . 人们可以通过在 lilo 引导的时候加入参数 (linux single 或 linux init 0) 就可以不需要口令直接进入单用户模式的超级用户环境中 , 这将是十分危险的 . 所以在 lilo.conf 中增加了 password 的配置选项来为每个影像文件增加口令保护 . 你可以在全局模式中使用 password 选项 ( 对所有影像文件都加入相同的口令 ), 或者为每个单独的影像文件加入口令 . 这样一来 , 在每次系统启动时 , 都会要求用户输入口令 . 也许你觉得每次都要输入口令很麻烦 , 可以使用 restricted 选项 , 它可以使 lilo 仅仅在 linux 启动时输入了参数 ( 例如 linux single) 的时候才会检验密码 . 这两个选项可以极大的增加系统的安全性 , 建议在 lilo.conf 文件中设置它们 . 由于 password 在 /etc/lilo.conf 文件是以明文存放的 , 所以必须要将 /etc/lilo.conf 文件的属性改为仅仅 root 可读 (0400).

  另外 , 在 lilo 的早期版本中 , 存在着引导扇区必须存放到前 1024 柱面的限制 , 在 lilo 的 2.51 版本中已经突破了这个限制 , 同时引导界面也变成了图形界面更加直观 . 最新版本的下载站点 :

[url]ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz[/url]
 
    下载解压后 
  , 
  使用命令 
  make install 
  即可完成安装 
  .



  注意 : 物理安全才是最基本的安全 , 即使在 lilo.conf 中增加了口令保护 , 如果没有物理安全 , 恶意闯入者可以使用启动软盘启动 linux 系统 .

2. 域名服务的配置文件

 

(1)/etc/HOSTNAME  
  在这个文件中保存着 
  linux 
  系统的主机名和域名 
  . 
  范例文件 
  
 
     
  ice.xanet.edu.cn
 
    这个文件表明了主机名 
  ice, 
  域名是 
  xanet.edu.cn



   (2)/etc/hosts 和 /etc/networks 文件 在域名服务系统中 , 有着主机表机制 ,/etc/hosts 和 /etc/networks 就是主机表发展而来在 /etc/hosts 中存放着你不需要 DNS 系统查询而得的主机 ip 地址和主机名的对应 , 下面是一个范例文件 :

  

# ip  
  地址 
    
  主机名 
    
  别名 
  
 
     
  127.0.0.1  
        
  localhosts  
          
  loopback
 
     
  202.117.1.13 
       
  [url]www.xjtu.edu.cn[/url] 
        
  www
 
     
  202.117.1.24  
      
   ftp.xjtu.edu.cn  
       
   ftp



  在 /etc/networks 中 , 存放着网络 ip 地址和网络名称的一一对应 . 它的文件格式和 /etc/hosts 是类似的

   (3)/etc/resolv.conf 这个文件是 DNS 域名解析器的主要配置文件 , 它的格式十分简单 , 每一行由一个主关键字组成 ./etc/resolv.conf 的关键字主要有 :

  

domain  
    指明缺省的本地域名 
  ,
 
     
  search  
    指明了一系列查找主机名的时候搜索的域名列表 
  ,
 
     
  nameserver  
  指明了在进行域名解析时域名服务器的 
  ip 
  地址 
  . 
  下面给出一个范例文件 
  :
 
     
  #/etc/resolv.conf
 
     
  domain  
      
  xjtu.edu.cn
 
     
  search  
      
  xjtu.edu.cn edu.cn
 
     
  nameserver  
    
  202.117.0.20
 
     
  nameserver  
    
  202.117.1.9
 
     
  (4)/etc/host.conf  
  在系统中同时存在着 
  DNS 
  域名解析和 
  /etc/hosts 
  的主机表机制时 
  , 
  由文件 
  /etc/host.conf 
  来说明了解析器的查询顺序 
  . 
  范例文件如下 
  :
 
     
  #/etc/host.conf
 
     
  order hosts,bind  
       
  # 
  解析器查询顺序是文件 
  /etc/hosts, 
  然后是 
  DNS
 
     
  multi on  
           
  # 
  允许主机拥有多个 
  ip 
  地址 
  
 
     
  nospoof on  
          
  # 
  禁止 
  ip 
  地址欺骗


3. DHCP 的配置文件
   /etc/dhcpd.conf 是 DHCPD 的配置文件 , 我们可以通过在 /etc/dhcpd.conf 文件中的配置来实现在局域网中动态分配 ip 地址 , 一台 linux 主机设置为 dhcpd 服务器 , 通过鉴别网卡的 MAC 地址来动态的分配 ip 地址 . 范例文件如下 :

option domain-name "chinapub.com";
 
     
  use-host-decl-names off;
 
     
  subnet 210.27.48.0 netmask 255.255.255.192 {
 
         
  filename "/tmp/p_w_picpath";
 
         
  host dial_server {
 
              
  hardware ethernet 00:02:b3:11:f2:30;
 
              
  fixed-address 210.27.48.8;
 
              
  filename "/tmp/p_w_picpath";
 
         
  }
 
     
  }



  在这个文件中,最主要的是通过设置的硬件地址来鉴别局域网中的主机,并分配给它指定的 ip 地址, hardware ethernet 00:02:b3:11:f2:30 指定要动态分配 ip 的主机得网卡的 MAC 地址, fixed-address 210.27.48.8 指定分配其 ip 地址。 filename "/tmp/p_w_picpath" 是通过 tftp 服务,主机所要得到的影像文件,可以通过得到的影像文件来引导主机启动。

4. 超级守候进程 inetd 的配置
  在 linux 系统中有一个超级守候进程 inetd,inetd 监听由文件 /etc/services 指定的服务的端口 ,inetd 根据网络连接请求 , 调用相应的服务进程来相应请求 . 在这里有两个文件十分重要

,/etc/inetd.conf 
  和 
  /etc/services, 
  文件 
  /etc/services 
  定义 
  linu 
  系统中所有服务的名称 
  , 
  协议类型 
  , 
  服务的端口等等信息 
  ,/etc/inetd.conf 
  是 
  inetd 
  的配置文件 
  , 
  由它来指定那些服务可以由 
  inetd 
  来监听 
  , 
  以及相应的服务进程的调用命令 
  . 
  首先介绍一下 
  /etc/services 
  文件 
  ,/etc/services 
  文件是一个服务名和服务端口对应的数据库文件 
  , 
  如下面所示 
  :
# /etc/services:
# $Id: services,v 1.4 2000/01/23 21:03:36 notting Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
# are included, only the more common ones.
# 
  名称 
    
     端口 
  / 
  协议     
    
  别名 
    
         注释 
  
tcpmux  
     
   1/tcp  
                  
  # TCP port service multiplexer
echo  
      
   7/tcp
echo  
      
   7/udp
discard  
     
  9/tcp  
        
  sink null
discard  
     
  9/udp  
        
  sink null
systat 
      
  11/tcp  
       
   users
daytime  
     
  13/tcp
daytime  
     
  13/udp
netstat  
     
  15/tcp
qotd  
      
   17/tcp  
        
  quote
msp  
       
  18/tcp  
                   
  # message send protocol
msp  
       
  18/udp 
                   
   # message send protocol
chargen  
     
  19/tcp  
       
  ttytst source
chargen 
     
   19/udp 
       
   ttytst source
ftp-data  
    
   20/tcp
ftp 
       
   21/tcp
fsp 
       
  21/udp 
        
   fspd
ssh  
       
  22/tcp  
                   
  # SSH Remote Login Protocol
ssh 
       
  22/udp 
                    
  # SSH Remote Login Protocol
telnet  
     
  23/tcp
# 24 - private
smtp  
      
  25/tcp  
        
  mail
# 26 - unassigned
time 
       
  37/tcp 
       
   timserver
time  
      
  37/udp  
        
  timserver
rlp  
       
  39/udp 
        
   resource 
           
   # resource location
nameserver 42/tcp  
        
  name 
              
  # IEN 116
whois  
      
  43/tcp  
        
  nicname
re-mail-ck  
    
  50/tcp  
                    
  # Remote Mail Checking Protocol
re-mail-ck 
    
  50/udp  
                    
   # Remote Mail Checking Protocol
domain  
     
   53/tcp  
       
  nameserver  
           
  # name-domain server
domain 
      
  53/udp  
       
  nameserver
mtp  
       
  57/tcp 
                     
   # deprecated
bootps  
     
   67/tcp  
                     
  # BOOTP server
bootps  
     
   67/udp
bootpc  
     
   68/tcp  
                     
  # BOOTP client
bootpc  
     
   68/udp
tftp  
      
   69/udp
gopher  
     
   70/tcp # Internet Gopher
gopher  
     
   70/udp
rje  
       
  77/tcp netrjs
finger  
     
   79/tcp
www  
       
  80/tcp  
       
  http 
               
   # WorldWideWeb HTTP
www 
       
   80/udp  
                     
   # HyperText Transfer Protocol
link  
      
   87/tcp  
       
  ttylink
kerberos  
    
   88/tcp  
       
  kerberos5 krb5  
          
  # Kerberos v5
kerberos  
    
   88/udp  
       
  kerberos5 krb5  
          
  # Kerberos v5
supdup 
      
  95/tcp
# 100 - reserved
hostnames  
    
  101/tcp  
       
  hostname  
             
  # usually from sri-nic
iso-tsap  
    
  102/tcp 
        
  tsap  
               
  # part of ISODE.
csnet-ns  
    
  105/tcp  
       
  cso-ns 
               
   # also used by CSO name server
csnet-ns  
    
  105/udp 
       
   cso-ns
rtelnet  
     
  107/tcp  
                      
  # Remote Telnet
rtelnet  
     
  107/udp
pop2  
       
  109/tcp  
      
  pop-2 postoffice 
          
   # POP version 2
pop2  
       
  109/udp 
      
   pop-2
pop3  
       
  110/tcp  
      
  pop-3 
                
   # POP version 3
pop3 
       
   110/udp 
      
   pop-3
sunrpc  
      
  111/tcp  
     
  portmapper 
              
   # RPC 4.0 portmapper TCP
sunrpc  
      
  111/udp  
     
  portmapper  
              
  # RPC 4.0 portmapper UDP
auth  
       
  113/tcp 
     
   authentication tap ident
sftp  
       
  115/tcp
uucp-path  
     
  117/tcp
nntp  
       
  119/tcp  
      
  readnews untp 
            
   # USENET News Transfer Protocol
ntp  
        
  123/tcp
ntp  
        
  123/udp 
                      
  # Network Time Protocol
netbios-ns  
     
  137/tcp 
                     
   # NETBIOS Name Service
netbios-ns  
     
  137/udp
netbios-dgm  
     
  138/tcp  
                     
  # NETBIOS Datagram Service
netbios-dgm  
     
  138/udp
netbios-ssn  
     
  139/tcp 
                      
  # NETBIOS session service
netbios-ssn  
     
  139/udp
imap2  
        
  143/tcp  
     
  imap  
                 
  # Interim Mail Access Proto v2
imap2  
        
  143/udp 
     
   imap



( 实际上 , 以上仅仅是 /etc/services 的一部分 , 限于篇幅没有全部写出 )

  在这个文件中 , 为了安全考虑 , 我们可以修改一些常用服务的端口地址 , 例如我们可以把 telnet 服务的端口地址改为 52323,www 的端口改为 8080,ftp 端口地址改为 2121 等等 , 这样仅仅需要在应用程序中修改相应的端口即可 . 这样可以提高系统的安全性 .

/etc/inetd.conf 
  文件是 
  inetd 
  的配置文件 
  ,  
  首先要了解一下 
  linux 
  服务器到底要提供哪些服务。一个很好的原则是 
  "  
  禁止所有不需要的服务 
  " 
  ,这样***就少了一些***系统的机会 
  ./etc/inetd.conf 
  范例文件如下 
  :
#
# inetd.conf 
       
  This file describes the services that will be available
#  
            
  through the INETD TCP/IP super server. To re-configure
#  
            
  the running INETD process, edit this file, then send the
#  
            
  NETD process a SIGHUP signal.
#
# Version: 
      
   @(#)/etc/inetd.conf  
     
  3.10  
     
  05/27/93
#
# Authors:  
      
  Original taken from BSD UNIX 4.3/TAHOE.
#  
           
  Fred N. van Kempen, 
#
# Modified for Debian Linux by Ian A. Murdock 
#
# Modified for RHS Linux by Marc Ewing 
#
# 
# 
  服务名 
   socket 
  类型 
    
  协议 
    
  动作 
    
  拥有者 
    
  服务进程路径名 
    
  掉用参数 
  
#nowait  
  表示在相应一个网络连接之后 
  , 
  服务进程在释放旧的联接之前可以接受 
  
# 
  新的连接请求 
  ,wait  
  则表示必须在旧连接清除之后才能接收新的连接 
  .
# Echo, discard, daytime, and chargen are used primarily for testing.
# To re-read this file after changes, just do a 'killall -HUP inetd'
#
#echo  
    
  stream  
    
  tcp 
    
   nowait 
    
   root  
    
  internal
#echo  
    
  dgram  
     
  udp 
    
   wait  
     
  root  
    
  internal
#discard 
      
   stream  
    
  tcp 
    
   nowait 
    
   root  
    
  internal
#discard 
      
   dgram  
     
  udp  
    
  wait  
     
  root  
    
  internal
#daytime stream 
    
   tcp 
     
   nowait 
     
   root  
     
  internal
#daytime dgram 
     
  udp  
     
  wait  
      
  root  
     
  internal
#chargen  
       
  stream  
    
  tcp  
     
  nowait  
    
  root  
    
  internal
#chargen  
       
  dgram  
    
  udp  
    
  wait 
     
   root  
     
  internal
#time  
     
  stream  
     
  tcp  
     
  nowait  
     
  root  
    
  internal
#time  
     
  dgram 
     
   udp  
     
  wait  
     
  root  
     
  internal
#
# These are standard services.
#
ftp  
     
  stream 
     
   tcp 
     
   nowait 
     
   root 
     
   /usr/sbin/tcpd  
     
  in.wuftpd -l -a
telnet 
    
  stream  
     
  tcp  
     
  nowait  
     
  root  
     
  /usr/sbin/tcpd  
     
  in.telnetd
#
# Shell, login, exec, comsat and talk are BSD protocols.
#
#shell  
    
  stream 
    
   tcp  
    
  nowait  
    
  root  
     
  /usr/sbin/tcpd  
     
  in.rshd
#login  
    
  stream 
    
   tcp 
    
   nowait 
    
   root 
     
   /usr/sbin/tcpd  
     
  in.rlogind
#exec  
    
  stream  
    
  tcp 
    
   nowait 
    
   root  
     
  /usr/sbin/tcpd 
     
   in.rexecd
#comsat dgram 
    
   udp  
    
  wait  
     
  root 
     
   /usr/sbin/tcpd 
     
   in.comsat
#talk  
    
  dgram  
    
  udp  
    
  wait  
     
  root 
     
   /usr/sbin/tcpd  
     
  in.talkd
#ntalk 
    
   dgram  
    
  udp 
    
  wait  
     
  root  
     
  /usr/sbin/tcpd  
     
  in.ntalkd
#dtalk 
    
   stream 
    
  tcp 
    
   waut 
     
   nobody  
    
  /usr/sbin/tcpd  
     
  in.dtalkd
# Pop and imap mail services et al
#
#pop-2 stream tcp nowait root /usr/sbin/tcpd ipop2d
#pop-3 stream tcp nowait root /usr/sbin/tcpd ipop3d
#imap stream tcp nowait root /usr/sbin/tcpd imapd
#
# The Internet UUCP service.
#
#uucp stream tcp nowait uucp /usr/sbin/tcpd /usr/lib/uucp/uucico -l
#
# Tftp service is provided primarily for booting. Most sites
# run this only on machines acting as "boot servers." Do not uncomment
# this unless you *need* it.
#
#tftp  
    
  dgram  
    
  udp 
    
   wait  
    
  root  
    
  /usr/sbin/tcpd  
    
  in.tftpd
#bootps dgram 
    
   udp 
    
   wait 
    
   root  
    
  /usr/sbin/tcpd 
    
   bootpd
# 
    
  
# Finger, systat and netstat give out user information which may be
# valuable to potential "system crackers." Many sites choose to disable
# some or all of these services to improve security.
#
#finger stream 
    
   tcp  
     
  nowait  
     
  root  
     
  /usr/sbin/tcpd  
     
  in.fingerd
#cfinger stream  
    
  tcp  
     
  nowait 
     
   root  
     
  /usr/sbin/tcpd  
     
  in.cfingerd
#systat stream 
    
   tcp 
     
   nowait  
     
  guest  
     
  /usr/sbin/tcpd /bin/ps -auwwx
#netstat stream  
    
  tcp 
     
   nowait  
     
  guest  
     
  /usr/sbin/tcpd /bin/netstat  
    
  -f inet
#
# Authentication
#
#auth 
      
   stream  
    
  tcp  
    
  nowait 
    
   nobody  
    
  /usr/sbin/in.identd in.identd -l -e -o
#linuxconf stream 
     
   tcp  
    
  wait  
     
  root  
     
  /bin/linuxconf linuxconf -http

 
    大家看到的这个文件已经修改过的文件 
  , 
  除了 
  telnet  
  和 
  ftp 
  服务 
  , 
  其他所有的服务都被禁止了 
  . 
  在修改了 
  /etc/inetd.conf 
  之后 
  , 
  使用命令 
  kill -HUP (inetd 
  的进程号 
  ), 
  使 
  inetd 
  重新读取配置文件并重新启动即可 
  .
5. ip route 
  的配置 
  

 
    利用 
  linux, 
  一台普通的微机也可以实现高性价比的路由器 
  . 
  首先让我们了解一下 
  linux 
  的查看路由信息的命令 
  :
 
     
  [root@ice /etc]# route -n
 
     
  Kernel IP routing table
 
     
  Destination 
      
   Gateway 
      
   Genmask  
       
  Flags Metric Ref 
     
   Use Iface
 
     
  202.112.13.204 
     
  0.0.0.0  
      
  255.255.255.255 UH  
    
  0 
    
   0  
    
  0  
       
  eth0
 
     
  202.117.48.43  
     
  0.0.0.0 
      
   255.255.255.255 UH 
    
   0 
    
   0 
    
   0  
       
  eth1
 
     
  202.112.13.192 
    
   202.112.13.204 255.255.255.192 UG 
    
   0  
    
  0  
    
  0  
       
  eth0
 
     
  202.112.13.192  
    
  0.0.0.0 
       
  255.255.255.192 U  
    
  0  
    
  0  
    
  0 
        
   eth0
 
     
  202.117.48.0 
     
   202.117.48.43 
    
  255.255.255.0  
    
  UG  
    
  0  
    
  0 
    
   0  
       
  eth1
 
     
  202.117.48.0 
     
   0.0.0.0 
       
   255.255.255.0 
    
   U  
    
  0 
    
   0 
    
   0 
       
   eth1
 
     
  127.0.0.0  
      
  0.0.0.0  
       
  255.0.0.0 
       
   U  
    
  0  
    
  0  
    
  0  
       
  lo
 
     
  0.0.0.0  
       
  202.117.48.1 
     
   0.0.0.0  
       
  UG  
    
  0  
    
  0 
    
   0  
       
  eth1
 
    命令 
  netstat -r n  
  得到输出结果和 
  route -n 
  是一样的 
  . 
  它们操作的都是 
  linux  
  内核的路由表 
  .
 
    命令 
  cat /proc/net/route 
  的输出结果是以十六进制表示的路由表 
  .
[root@ice /etc]# cat /proc/net/route
Iface 
    
   Destination 
     
   Gateway  
    
  Flags  
    
  RefCnt  
    
  Use 
     
   Metric Mask
eth0  
    
  CC0D70CA 
       
   00000000 0005  
    
  0  
     
  0  
      
  0  
       
  FFFFFFF
eth1  
    
  2B3075CA 
       
   00000000 0005  
    
  0 
     
   0 
      
   0  
       
  FFFFFFF
eth0 
    
   C00D70CA  
       
  CC0D70CA 0003  
    
  0 
     
   0  
      
  0  
       
  C0FFFFF
eth0  
    
  C00D70CA  
       
  00000000 0001 
    
   0 
     
   0  
      
  0  
       
  C0FFFFF
eth1 
    
   003075CA 
       
   2B3075CA 0003 
    
   0 
    
    
    
  0  
      
  0  
       
  00FFFFF
eth1 
     
  003075CA 
       
   00000000 0001  
    
  0  
     
  0  
      
  0  
       
  00FFFFF
lo  
     
  0000007F  
        
  00000000 0001 
    
   0 
     
   0  
      
  0 
      
   000000F
eth1 
     
   00000000  
        
  013075CA 0003 
    
   0 
    
   0  
      
  0 
       
   0000000


  通过计算可以知道 , 下面的这个路由表 ( 十六进制 ) 和前面的路由表 ( 十进制 ) 是一致的 .

  我们还可以通过命令 route add (del ) 来操作路由表 , 增加和删除路由信息 .

除了上面的静态路由 ,linux 还可以通过 routed 来实现 rip 协议的动态路由 . 我们只需要打开 linux 的路由转发功能 , 在 /proc/sys/net/ipv4/ip_forward 文件中增加一个字符 1.


转载于:https://blog.51cto.com/linuxsir/70985