[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 系統管理 > Linux > 正文
Linux系統中網絡配置詳解
本文出自:http://www.china-pub.com 作者: 吳瞻 (2001-08-09 10:00:00)

  從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-rhine.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, <waltje@uwalt.nl.mugnet.org>
#
# Modified for Debian Linux by Ian A. Murdock <imurdock@shell.portal.com>
#
# Modified for RHS Linux by Marc Ewing <marc@redhat.com>
#
# <service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
#服務名 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


(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章
Linux系統中網絡配置詳解 (2001-08-09 10:00:00)
幾種網絡配置信息及口令的清除方法 (2001-06-26 18:08:00)
Solaris網絡配置 (2001-05-01 15:47:13)
 

★  樊強制作 歡迎分享  ★