免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2110 | 回复: 2

Linux系统中网络配置详解 [复制链接]

论坛徽章:
0
发表于 2009-06-10 09:25 |显示全部楼层
从linux诞生的那一天起,就注定了它的网络功能空前地强大.所以在linux系统中如何配置网络,使其高效,安全的工作就显得十分重要.下面我们就从网络设备的安装,网络服务的设置和网络安全性三个方面来介绍一下linux系统中网络的设置.
  一.安装和配置网络设备
  在安装linux时,如果你有网卡,安装程序将会提示你给出tcp/ip网络的配置参数,如本机的ip地址,缺省网关的ip地址,DNS的ip地址等等.根据这些配置参数,安装程序将会自动把网卡(linux系统首先要支持)驱动程序编译到内核中去.但是我们一定要了解加载网卡驱动程序的过程,那么在以后改变网卡,使用多个网卡的时候我们就会很容易的操作.网卡的驱动程序是作为模块加载到内核中去的,所有linux支持的网卡驱动程序都是存放在目录/lib/modules/(linux版本号)/net/ ,例如inter的82559系列10/100M自适应的引导网卡的驱动程序是eepro100.o,3COM的3C509 ISA网卡的驱动程序是3C509.o,DLINK的pci 10网卡的驱动程序是via-hine.o,NE2000兼容性网卡的驱动程序是ne2k-pci.o和ne.o.在了解了这些基本的驱动程序之后,我们就可以通过修改模块配置文件来更换网卡或者增加网卡.
  1. 修改/etc/conf.modules 文件
  这个配置文件是加载模块的重要参数文件,大家先看一个范例文件
  #/etc/conf.modules
  alias eth0 eepro100
  alias eth1 eepro100
  这个文件是一个装有两块inter 82559系列网卡的linux系统中的conf.modules中的内容.alias命令表明以太口(如eth0)所具有的驱动程序的名称,alias eth0 eepro100说明在零号以太网口所要加载的驱动程序是eepro100.o.那么在使用命令 modprobe eth0的时候,系统将自动将eepro100.o加载到内核中.对于pci的网卡来说,由于系统会自动找到网卡的io地址和中断号,所以没有必要在conf.modules中使用选项options来指定网卡的io地址和中断号.但是对应于ISA网卡,则必须要在conf.modules中指定硬件的io地址或中断号, 如下所示,表明了一块NE的ISA网卡的conf.modules文件.
  alias eth0 ne
  options ne io=0x300 irq=5
  在修改完conf.modules文件之后,就可以使用命令来加载模块,例如要插入inter的第二块网卡:
  #insmod /lib/modules/2.2.14/net/eepro100.o
  这样就可以在以太口加载模块eepro100.o.同时,还可以使用命令来查看当前加载的模块信息:
  [root@ice /etc]# lsmod
  Module Size Used by
  eepro100 15652 2 (autoclean)
  返回结果的含义是当前加载的模块是eepro100,大小是15652个字节,使用者两个,方式是自动清除.
  2. 修改/etc/lilo.conf文件
  在一些比较新的linux版本中,由于操作系统自动检测所有相关的硬件,所以此时不必修改/etc/lilo.conf文件.但是对于ISA网卡和老的版本,为了在系统初始化中对新加的网卡进行初始化,可以修改lilo.conf文件.在/etc/lilo.conf文件中增加如下命令:
  append="ether=5,0x240,eth0 ether=7,0x300,eth1"
  这条命令的含义是eth0的io地址是0x240,中断是5,eth1的io地址是0x300,中断是7.
  实际上,这条语句来自在系统引导影像文件时传递的参数,
  LILO: linux ether=5,0x240,eth0 ether=7,0x300,eth1
  这种方法也同样能够使linux系统配置好两个网卡.类似的,在使用三个以上网卡的时候,也可以依照同样的方法.
  在配置好网卡之后,就应该配置TCP/IP的参数,在一般情况下,在安装linux系统的同时就会提示你配置网络参数.但是之后如果我们想要修改网络设置,可以使用如下的命令:
  #ifconfig eth0 A.B.C.D netmask E.F.G.H
  A.B.C.D 是eth0的IP地址,E.F.G.H是网络掩码.
  其实,在linux系统中我们可以给一块网卡设置多个ip地址,例如下面的命令:
  #ifconfig eth0:1 202.112.11.218 netmask 255.255.255.192
  然后,使用命令#ifconfig -a 就可以看到所有的网络接口的界面:
  eth0   Link encap:Ethernet HWaddr 00:90:27:58:AF:1A
       inet addr:202.112.13.204 Bcast:202.112.13.255 Mask:255.255.255.192
       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
       RX packets:435510 errors:0 dropped:0 overruns:0 frame:2
       TX packets:538988 errors:0 dropped:0 overruns:0 carrier:0
       collisions:318683 txqueuelen:100
       Interrupt:10 Base address:0xc000
  eth0:1  Link encap:Ethernet HWaddr 00:90:27:58:AF:1A
       inet addr:202.112.11.218 Bcast:202.112.11.255 Mask:255.255.255.192
       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
       Interrupt:10 Base address:0xc000
  lo    Link encap:Local Loopback
       inet addr:127.0.0.1 Mask:255.0.0.0
       UP LOOPBACK RUNNING MTU:3924 Metric:1
       RX packets:2055 errors:0 dropped:0 overruns:0 frame:0
       TX packets:2055 errors:0 dropped:0 overruns:0 carrier:0
       collisions:0 txqueuelen:0
  我们看到网络接口有三个,eth0 , eth0:1,lo,eth0是真实的以太网络接口,eth0:1和eth0是同一块网卡,只不过绑定了另外的一个地址,lo是会送地址。eth0和eth0:1可以使用不同网段的ip地址,这在同一个物理网段却使用不同的网络地址的时候十分有用。
  另外,网卡有一种模式是混杂模式(prosimc),在这个模式下,网卡将会接收网络中所有的数据包,一些linux下的网络监听工具例如tcpdump,snort等等都是把网卡设置为混杂模式.
  ifconfig命令可以在本次运行的时间内改变网卡的ip地址,但是如果系统重新启动,linux仍然按照原来的默认的设置启动网络接口。这时候,可以使用netconfig或netconf命令来重新设置默认网络参数。
  netconfig 命令是重新配置基本的tcp/ip参数,参数包括是否配置为动态获得ip地址(dhcpd和bootp),网卡的ip地址,网络掩码,缺省网关和首选的域名服务器地址。netconf命令可以详细的配置所有网络的参数,分为客户端任务,服务器端任务和其他的配置三个部分,在客户端的配置中,主要包括基本主机的配置(主机名,有效域名,网络别名,对应相应网卡的ip地址,网络掩码,网络设备名,网络设备的内核驱动程序),DNS地址配置,缺省网关的地址配置,NIS地址配置,ipx接口配置,ppp/slip的配置等等。在服务器端配置中,主要包括NFS的配置,DNS的配置,ApacheWebServer配置,Samba的配置和Wu-ftpd的配置。在其他的配置选项中,一个是关于/etc/hosts文件中的主机配置,一个是关于/etc/networks文件中的网络配置信息,最后是关于使用linuxconf配置的信息。
  在linuxconf命令下,同样也可以配置网络信息,但是大家可以发现,linuxconf程序是调用netconf来进行网络配置的。
  另外,在/etc/sysconfig/network-scripts目录下存放着系统关于网络的配置文件,范例如下:
  ifcfg-eth0*  ifdown-post*  ifup-aliases*  ifup-ppp*
  ifcfg-eth1*  ifdown-ppp*   ifup-ipx*    ifup-routes*
  ifcfg-lo*   ifdown-sl*   ifup-plip*    ifup-sl*
  ifdown@    ifup@      ifup-post*    network-functions
  ifcfg-eth0是以太口eth0的配置信息,它的内容如下:
  DEVICE="eth0"              /*指明网络设备名称*/
  IPADDR="202.112.13.204"         /*指明网络设备的ip地址*/
  NETMASK="255.255.255.192"        /*指明网络掩码*/
  NETWORK=202.112.13.192         /*指明网络地址*/
  BROADCAST=202.112.13.255         /*指明广播地址*/
  ONBOOT="yes"               /*指明在系统启动时是否激活网卡*/
  BOOTPROTO="none"             /*指明是否使用bootp协议*/
  
  所以,我们也可以修改这个文件来进行linux下网络参数的改变。
  二 网络服务的配置
 在这一部分,我们并不是详细的介绍具体的网络服务器(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版本中已经突破了这个限制,同时引导界面也变成了图形界面更加直观.最新版本的下载站点:
  
ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz
  下载解压后,使用命令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    
www.xjtu.edu.cn
     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/image";
      host dial_server {
           hardware ethernet 00:02:b3:11:f2:30;
           fixed-address 210.27.48.8;
           filename "/tmp/image";
      }
  }
  在这个文件中,最主要的是通过设置的硬件地址来鉴别局域网中的主机,并分配给它指定的ip地址,hardware ethernet 00:02:b3:11:f2:30指定要动态分配ip的主机得网卡的MAC地址,fixed-address 210.27.48.8指定分配其ip地址。filename "/tmp/image"是通过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.
  三.网络的安全设置
  在这一部分,再次强调一定要修改/etc/inetd.conf,安全的策略是禁止所有不需要的服务.除此之外,还有以下几个文件和网络安全相关.
  (1)./etc/ftpusers ftp服务是一个不太安全的服务,所以/etc/ftpusers限定了不允许通过ftp访问linux主机的用户列表.当一个ftp请求传送到ftpd,ftpd首先检查用户名,如果用户名在/etc/ftpusers中,则ftpd将不会允许该用户继续连接.范例文件如下:
# /etc/ftpusers - users not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
nadmin
  (2)/etc/securetty 在linux系统中,总共有六个终端控制台,我们可以在/etc/securetty中设置哪个终端允许root登录,所有其他没有写入文件中的终端都不允许root登录.范例文件如下:
# /etc/securetty - tty's on which root is allowed to login
tty1
tty2
tty3
tty4
(3)tcpd的控制登录文件/etc/hosts.allow和/etc/hosts.deny
  在tcpd服务进程中,通过在/etc/hosts.allow和/etc/hosts.deny中的访问控制规则来控制外部对linux主机的访问.它们的格式都是
  service-list : hosts-list [ : command]
  服务进程的名称 : 主机列表 可选,当规则满足时的操作
  在主机表中可以使用域名或ip地址,ALL表示匹配所有项,EXCEPT表示除了某些项, PARANOID表示当ip地址和域名不匹配时(域名伪装)匹配该项.
  范例文件如下:
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
ALL : 202.112.13.0/255.255.255.0
ftpd: 202.117.13.196
in.telnetd: 202.117.48.33
ALL : 127.0.0.1
  在这个文件中,网段202.112.13.0/24可以访问linux系统中所有的网络服务,主机202.117.13.196只能访问ftpd服务,主机202.117.48.33只能访问telnetd服务.本机自身可以访问所有网络服务.
  在/etc/hosts.deny文件中禁止所有其他情况:
  #/etc/hosts.deny
  ALL : DENY : spawn (/usr/bin/finger -lp @%h | /bin/mail -s "Port Denial noted in %d-%h" root)
  在/etc/hosts.allow中,定义了在所有其他情况下,linux所应该执行的操作.spawn选项允许linux系统在匹配规则中执行指定的shell命令,在我们的例子中,linux系统在发现无授权的访问时,将会发送给超级用户一封主题是"Port Denial noted in %d-%h"的邮件,在这里,我们先要介绍一下allow和deny文件中的变量扩展.
  (4)/etc/issue和/etc/issue.net
  在我们登录linux系统中的时候,我们常常可以看到我们linux系统的版本号等敏感信息.在如今的网络攻击行为中,许多黑客首先要收集目标系统的信息,版本号等就是十分重要的信息,所以在linux系统中一般要把这些信息隐藏起来./etc/issue和/etc/issue.net就是存放这些信息的文件.我们可以修改这些文件来隐藏版本信息.
另外,在每次linux重新启动的时候,都会在脚本/etc/rc.d/rc.local中再次覆盖上面那两个文件./etc/rc.d/rc.local文件的范例如下:
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
if [ -f /etc/redhat-release ]; then
R=$(cat /etc/redhat-release)
arch=$(uname -m)
a="a"
case "_$arch" in
_a*) a="an";;
_i*) a="an";;
esac
NUMPROC=`egrep -c "^cpu[0-9]+" /proc/stat`
if [ "$NUMPROC" -gt "1" ]; then
SMP="$NUMPROC-processor "
if [ "$NUMPROC" = "8" -o "$NUMPROC" = "11" ]; then
a="an"
else
a="a"
fi
fi
# This will overwrite /etc/issue at every boot. So, make any changes you
# want to make to /etc/issue here or you will lose them when you reboot.
#echo "" > /etc/issue
#echo "$R" >> /etc/issue
# echo "Kernel $(uname -r) on $a $SMP$(uname -m)" >> /etc/issue
cp -f /etc/issue /etc/issue.net
echo >> /etc/issue
  在文件中黑体的部分就是得到系统版本信息的地方.一定要将他们注释掉.
  (5)其他配置
  在普通微机中,都可以通过ctl+alt+del三键的组合来重新启动linux.这样是十分不安全的,所以要在/etc/inittab文件中注释该功能:
  # Trap CTRL-ALT-DELETE
  #ca::ctrlaltdel:/sbin/shutdown -t3 -r now

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/98460/showart_1960500.html

论坛徽章:
0
发表于 2014-10-23 16:28 |显示全部楼层
翻开沉睡的博客,学无止境……:wink:

求职 : Windows运维
论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-05-24 06:20:00
发表于 2016-05-21 13:25 |显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP