Linux系統(tǒng)配置網(wǎng)絡(luò)詳解

一.安裝和配置網(wǎng)絡(luò)設(shè)備
在安裝linux時,如果你有網(wǎng)卡,安裝程序?qū)崾灸憬o出tcp/ip網(wǎng)絡(luò)的配置參數(shù),如本機的ip地址,缺省網(wǎng)關(guān)的ip地址,DNS的ip地址等等.根據(jù)這些配置參數(shù),安裝程序?qū)詣影丫W(wǎng)卡(linux系統(tǒng)首先要支持)驅(qū)動程序編譯到內(nèi)核中去.但是我們一定要了解加載網(wǎng)卡驅(qū)動程序的過程,那么在以后改變網(wǎng)卡,使用多個網(wǎng)卡的時候我們就會很容易的操作.網(wǎng)卡的驅(qū)動程序是作為模塊加載到內(nèi)核中去的,所有l(wèi)inux支持的網(wǎng)卡驅(qū)動程序都是存放在目錄/lib/modules/(linux版本號)/net/ ,例如inter的82559系列10/100M自適應(yīng)的引導(dǎo)網(wǎng)卡的驅(qū)動程序是eepro100.o,3COM的3C509 ISA網(wǎng)卡的驅(qū)動程序是3C509.o,DLINK的pci 10網(wǎng)卡的驅(qū)動程序是via-rhine.o,NE2000兼容性網(wǎng)卡的驅(qū)動程序是ne2k-pci.o和ne.o.在了解了這些基本的驅(qū)動程序之后,我們就可以通過修改模塊配置文件來更換網(wǎng)卡或者增加網(wǎng)卡.
1. 修改/etc/conf.modules 文件
這個配置文件是加載模塊的重要參數(shù)文件,大家先看一個范例文件
#/etc/conf.modules
alias eth0 eepro100
alias eth1 eepro100
這個文件是一個裝有兩塊inter 82559系列網(wǎng)卡的linux系統(tǒng)中的conf.modules中的內(nèi)容.alias命令表明以太口(如eth0)所具有的驅(qū)動程序的名稱,alias eth0 eepro100說明在零號以太網(wǎng)口所要加載的驅(qū)動程序是eepro100.o.那么在使用命令 modprobe eth0的時候,系統(tǒng)將自動將eepro100.o加載到內(nèi)核中.對于pci的網(wǎng)卡來說,由于系統(tǒng)會自動找到網(wǎng)卡的io地址和中斷號,所以沒有必要在conf.modules中使用選項options來指定網(wǎng)卡的io地址和中斷號.但是對應(yīng)于ISA網(wǎng)卡,則必須要在conf.modules中指定硬件的io地址或中斷號, 如下所示,表明了一塊NE的ISA網(wǎng)卡的conf.modules文件.
alias eth0 ne
options ne io=0x300 irq=5
在修改完conf.modules文件之后,就可以使用命令來加載模塊,例如要inter的第二塊網(wǎng)卡:
#insmod /lib/modules/2.2.14/net/eepro100.o
這樣就可以在以太口加載模塊eepro100.o.同時,還可以使用命令來查看當(dāng)前加載的模塊信息:
[root@ice /etc]# lsmod
Module Size Used by
eepro100 15652 2 (autoclean)
返回結(jié)果的含義是當(dāng)前加載的模塊是eepro100,大小是15652個字節(jié),使用者兩個,方式是自動清除.
2. 修改/etc/lilo.conf文件
在一些比較新的linux版本中,由于操作系統(tǒng)自動檢測所有相關(guān)的硬件,所以此時不必修改/etc/lilo.conf文件.但是對于ISA網(wǎng)卡和老的版本,為了在系統(tǒng)初始化中對新加的網(wǎng)卡進(jìn)行初始化,可以修改lilo.conf文件.在/etc/lilo.conf文件中增加如下命令:
append="ether=5,0x240,eth0 ether=7,0x300,eth1"
這條命令的含義是eth0的io地址是0x240,中斷是5,eth1的io地址是0x300,中斷是7.
實際上,這條語句來自在系統(tǒng)引導(dǎo)影像文件時傳遞的參數(shù),
LILO: linux ether=5,0x240,eth0 ether=7,0x300,eth1
這種方法也同樣能夠使linux系統(tǒng)配置好兩個網(wǎng)卡.類似的,在使用三個以上網(wǎng)卡的時候,也可以依照同樣的方法.
在配置好網(wǎng)卡之后,就應(yīng)該配置TCP/IP的參數(shù),在一般情況下,在安裝linux系統(tǒng)的同時就會提示你配置網(wǎng)絡(luò)參數(shù).但是之后如果我們想要修改網(wǎng)絡(luò)設(shè)置,可以使用如下的命令:
#ifconfig eth0 A.B.C.D netmask E.F.G.H
A.B.C.D 是eth0的IP地址,E.F.G.H是網(wǎng)絡(luò)掩碼.
其實,在linux系統(tǒng)中我們可以給一塊網(wǎng)卡設(shè)置多個ip地址,例如下面的命令:
#ifconfig eth0:1 202.112.11.218 netmask 255.255.255.192
然后,使用命令#ifconfig -a 就可以看到所有的網(wǎng)絡(luò)接口的界面:
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
我們看到網(wǎng)絡(luò)接口有三個,eth0 , eth0:1,lo,eth0是真實的以太網(wǎng)絡(luò)接口,eth0:1和eth0是同一塊網(wǎng)卡,只不過綁定了另外的一個地址,lo是會送地址。eth0和eth0:1可以使用不同網(wǎng)段的ip地址,這在同一個物理網(wǎng)段卻使用不同的網(wǎng)絡(luò)地址的時候十分有用。
另外,網(wǎng)卡有一種模式是混雜模式(prosimc),在這個模式下,網(wǎng)卡將會接收網(wǎng)絡(luò)中所有的數(shù)據(jù)包,一些linux下的網(wǎng)絡(luò)****工具例如tcpdump,snort等等都是把網(wǎng)卡設(shè)置為混雜模式.
ifconfig命令可以在本次運行的時間內(nèi)改變網(wǎng)卡的ip地址,但是如果系統(tǒng)重新啟動,linux仍然按照原來的默認(rèn)的設(shè)置啟動網(wǎng)絡(luò)接口。這時候,可以使用netconfig或netconf命令來重新設(shè)置默認(rèn)網(wǎng)絡(luò)參數(shù)。netconfig 命令是重新配置基本的tcp/ip參數(shù),參數(shù)包括是否配置為動態(tài)獲得ip地址(dhcpd和bootp),網(wǎng)卡的ip地址,網(wǎng)絡(luò)掩碼,缺省網(wǎng)關(guān)和首選的域名服務(wù)器地址。netconf命令可以詳細(xì)的配置所有網(wǎng)絡(luò)的參數(shù),分為客戶端任務(wù),服務(wù)器端任務(wù)和其他的配置三個部分,在客戶端的配置中,主要包括基本主機的配置(主機名,有效域名,網(wǎng)絡(luò)別名,對應(yīng)相應(yīng)網(wǎng)卡的ip地址,網(wǎng)絡(luò)掩碼,網(wǎng)絡(luò)設(shè)備名,網(wǎng)絡(luò)設(shè)備的內(nèi)核驅(qū)動程序),DNS地址配置,缺省網(wǎng)關(guān)的地址配置,NIS地址配置,ipx接口配置,ppp/slip的配置等等。在服務(wù)器端配置中,主要包括NFS的配置,DNS的配置,ApacheWebServer配置,Samba的配置和Wu-ftpd的配置。在其他的配置選項中,一個是關(guān)于/etc/hosts文件中的主機配置,一個是關(guān)于/etc/networks文件中的網(wǎng)絡(luò)配置信息,最后是關(guān)于使用linuxconf配置的信息。
在linuxconf命令下,同樣也可以配置網(wǎng)絡(luò)信息,但是大家可以發(fā)現(xiàn),linuxconf程序是調(diào)用netconf來進(jìn)行網(wǎng)絡(luò)配置的。
另外,在/etc/sysconfig/network-scripts目錄下存放著系統(tǒng)關(guān)于網(wǎng)絡(luò)的配置文件,范例如下:
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的配置信息,它的內(nèi)容如下:
DEVICE="eth0" /*指明網(wǎng)絡(luò)設(shè)備名稱*/
IPADDR="202.112.13.204" /*指明網(wǎng)絡(luò)設(shè)備的ip地址*/
NETMASK="255.255.255.192" /*指明網(wǎng)絡(luò)掩碼*/
NETWORK=202.112.13.192 /*指明網(wǎng)絡(luò)地址*/
BROADCAST=202.112.13.255 /*指明廣播地址*/
ONBOOT="yes" /*指明在系統(tǒng)啟動時是否激活網(wǎng)卡*/
BOOTPROTO="none" /*指明是否使用bootp協(xié)議*/
所以,我們也可以修改這個文件來進(jìn)行l(wèi)inux下網(wǎng)絡(luò)參數(shù)的改變。
二 網(wǎng)絡(luò)服務(wù)的配置:
在這一部分,我們并不是詳細(xì)的介紹具體的網(wǎng)絡(luò)服務(wù)器(DNS,FTP,WWW,SENDMAIL)的配置(那將是巨大的篇幅),而是介紹一下與linux網(wǎng)絡(luò)服務(wù)的配置相關(guān)的文件.
1. LILO的配置文件
在linux系統(tǒng)中,有一個系統(tǒng)引導(dǎo)程序,那就是lilo(linux loadin),利用lilo可以實現(xiàn)多操作系統(tǒng)的選擇啟動.它的配置文件是/etc/lilo.conf.在這個配置文件中,lilo的配置參數(shù)主要分為兩個部分,一個是全局配置參數(shù),包括設(shè)置啟動設(shè)備等等.另一個是局部配置參數(shù),包括每個引導(dǎo)影像文件的配置參數(shù).在這里我就不詳細(xì)介紹每個參數(shù),特別的僅僅說明兩個重要的參數(shù)--------password和restricted選項,password選項為每個引導(dǎo)的影像文件加入口令保護(hù).我們都知道,在linux系統(tǒng)中有一個運行模式是單用戶模式,在這個模式下,用戶是以超級用戶的身份登錄到linux系統(tǒng)中.人們可以通過在lilo引導(dǎo)的時候加入?yún)?shù)(linux single 或linux init 0)就可以不需要口令直接進(jìn)入單用戶模式的超級用戶環(huán)境中,這將是十分危險的.所以在lilo.conf中增加了password的配置選項來為每個影像文件增加口令保護(hù).你可以在全局模式中使用password選項(對所有影像文件都加入相同的口令),或者為每個單獨的影像文件加入口令.這樣一來,在每次系統(tǒng)啟動時,都會要求用戶輸入口令.也許你覺得每次都要輸入口令很麻煩,可以使用restricted選項,它可以使lilo僅僅在linux啟動時輸入了參數(shù)(例如 linux single)的時候才會檢驗密碼.這兩個選項可以極大的增加系統(tǒng)的安全性,建議在lilo.conf文件中設(shè)置它們.由于password在/etc/lilo.conf文件是以明文存放的,所以必須要將/etc/lilo.conf文件的屬性改為僅僅root可讀(0400).
另外,在lilo的早期版本中,存在著引導(dǎo)扇區(qū)必須存放到前1024柱面的限制,在lilo的2.51版本中已經(jīng)突破了這個限制,同時引導(dǎo)界面也變成了圖形界面更加直觀.最新版本的下載站點:
ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz
下載解壓后,使用命令make install即可完成安裝.
注意: 物理安全才是最基本的安全,即使在lilo.conf中增加了口令保護(hù),如果沒有物理安全,惡意闖入者可以使用啟動軟盤啟動linux系統(tǒng).
2. 域名服務(wù)的配置文件
(1)/etc/HOSTNAME 在這個文件中保存著linux系統(tǒng)的主機名和域名.范例文件
ice.xanet.edu.cn
這個文件表明了主機名ice,域名是xanet.edu.cn
(2)/etc/hosts和/etc/networks文件 在域名服務(wù)系統(tǒng)中,有著主機表機制,/etc/hosts和/etc/networks就是主機表發(fā)展而來在/etc/hosts中存放著你不需要DNS系統(tǒng)查詢而得的主機ip地址和主機名的對應(yīng),下面是一個范例文件:
# 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 中,存放著網(wǎng)絡(luò)ip地址和網(wǎng)絡(luò)名稱的一一對應(yīng).它的文件格式和/etc/hosts是類似的
(3)/etc/resolv.conf 這個文件是DNS域名解析器的主要配置文件,它的格式十分簡單,每一行由一個主關(guān)鍵字組成./etc/resolv.conf的關(guān)鍵字主要有:
domain 指明缺省的本地域名,
search 指明了一系列查找主機名的時候搜索的域名列表,
nameserver 指明了在進(jìn)行域名解析時域名服務(wù)器的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 在系統(tǒng)中同時存在著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文件中的配置來實現(xiàn)在局域網(wǎng)中動態(tài)分配ip地址,一臺linux主機設(shè)置為dhcpd服務(wù)器,通過鑒別網(wǎng)卡的MAC地址來動態(tài)的分配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";
}
}
在這個文件中,最主要的是通過設(shè)置的硬件地址來鑒別局域網(wǎng)中的主機,并分配給它指定的ip地址,hardware ethernet 00:02:b3:11:f2:30指定要動態(tài)分配ip的主機得網(wǎng)卡的MAC地址,fixed-address 210.27.48.8指定分配其ip地址。filename "/tmp/image"是通過tftp服務(wù),主機所要得到的影像文件,可以通過得到的影像文件來引導(dǎo)主機啟動。
4. 超級守候進(jìn)程inetd的配置
在linux系統(tǒng)中有一個超級守候進(jìn)程inetd,inetd****由文件/etc/services指定的服務(wù)的端口,inetd根據(jù)網(wǎng)絡(luò)連接請求,調(diào)用相應(yīng)的服務(wù)進(jìn)程來相應(yīng)請求.在這里有兩個文件十分重要,/etc/inetd.conf和/etc/services,文件/etc/services定義linu系統(tǒng)中所有服務(wù)的名稱,協(xié)議類型,服務(wù)的端口等等信息,/etc/inetd.conf是inetd的配置文件,由它來指定那些服務(wù)可以由inetd來****,以及相應(yīng)的服務(wù)進(jìn)程的調(diào)用命令.首先介紹一下/etc/services文件,/etc/services文件是一個服務(wù)名和服務(wù)端口對應(yīng)的數(shù)據(jù)庫文件,如下面所示:
# /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.
#名稱 端口/協(xié)議 別名 注釋
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的一部分,限于篇幅沒有全部寫出)
在這個文件中,為了安全考慮,我們可以修改一些常用服務(wù)的端口地址,例如我們可以把telnet服務(wù)的端口地址改為52323,www的端口改為8080,ftp端口地址改為2121等等,這樣僅僅需要在應(yīng)用程序中修改相應(yīng)的端口即可.這樣可以提高系統(tǒng)的安全性.
/etc/inetd.conf文件是inetd的配置文件, 首先要了解一下linux服務(wù)器到底要提供哪些服務(wù)。一個很好的原則是" 禁止所有不需要的服務(wù)",這樣黑客就少了一些攻擊系統(tǒng)的機會./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>
#服務(wù)名 socket類型 協(xié)議 動作 擁有者 服務(wù)進(jìn)程路徑名 掉用參數(shù)
#nowait 表示在相應(yīng)一個網(wǎng)絡(luò)連接之后,服務(wù)進(jìn)程在釋放舊的聯(lián)接之前可以接受
#新的連接請求,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
大家看到的這個文件已經(jīng)修改過的文件,除了telnet 和ftp服務(wù),其他所有的服務(wù)都被禁止了.在修改了/etc/inetd.conf之后,使用命令kill -HUP (inetd的進(jìn)程號),使inetd重新讀取配置文件并重新啟動即可.
5. ip route的配置
利用linux,一臺普通的微機也可以實現(xiàn)高性價比的路由器.首先讓我們了解一下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 得到輸出結(jié)果和route -n是一樣的.它們操作的都是linux 內(nèi)核的路由表.
命令cat /proc/net/route的輸出結(jié)果是以十六進(jìn)制表示的路由表.
[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
通過計算可以知道,下面的這個路由表(十六進(jìn)制)和前面的路由表(十進(jìn)制)是一致的.
我們還可以通過命令route add (del )來操作路由表,增加和刪除路由信息.
除了上面的靜態(tài)路由,linux還可以通過routed來實現(xiàn)rip協(xié)議的動態(tài)路由.我們只需要打開linux的路由轉(zhuǎn)發(fā)功能,在/proc/sys/net/ipv4/ip_forward文件中增加一個字符1.
三.網(wǎng)絡(luò)的安全設(shè)置
在這一部分,再次強調(diào)一定要修改/etc/inetd.conf,安全的策略是禁止所有不需要的服務(wù).除此之外,還有以下幾個文件和網(wǎng)絡(luò)安全相關(guān).
(1)./etc/ftpusers ftp服務(wù)是一個不太安全的服務(wù),所以/etc/ftpusers限定了不允許通過ftp訪問linux主機的用戶列表.當(dāng)一個ftp請求傳送到ftpd,ftpd首先檢查用戶名,如果用戶名在/etc/ftpusers中,則ftpd將不會允許該用戶繼續(xù)連接.范例文件如下:
# /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系統(tǒng)中,總共有六個終端控制臺,我們可以在/etc/securetty中設(shè)置哪個終端允許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服務(wù)進(jìn)程中,通過在/etc/hosts.allow和/etc/hosts.deny中的訪問控制規(guī)則來控制外部對linux主機的訪問.它們的格式都是
service-list : hosts-list [ : command]
服務(wù)進(jìn)程的名稱 : 主機列表 可選,當(dāng)規(guī)則滿足時的操作
在主機表中可以使用域名或ip地址,ALL表示匹配所有項,EXCEPT表示除了某些項, PARANOID表示當(dāng)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
在這個文件中,網(wǎng)段202.112.13.0/24可以訪問linux系統(tǒng)中所有的網(wǎng)絡(luò)服務(wù),主機202.117.13.196只能訪問ftpd服務(wù),主機202.117.48.33只能訪問telnetd服務(wù).本機自身可以訪問所有網(wǎng)絡(luò)服務(wù).
在/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所應(yīng)該執(zhí)行的操作.spawn選項允許linux系統(tǒng)在匹配規(guī)則中執(zhí)行指定的shell命令,在我們的例子中,linux系統(tǒng)在發(fā)現(xiàn)無授權(quán)的訪問時,將會發(fā)送給超級用戶一封主題是"Port Denial noted in %d-%h"的郵件,在這里,我們先要介紹一下allow和deny文件中的變量擴展.
(4)/etc/issue和/etc/issue.net
在我們登錄linux系統(tǒng)中的時候,我們常??梢钥吹轿覀僱inux系統(tǒng)的版本號等敏感信息.在如今的網(wǎng)絡(luò)攻擊行為中,許多黑客首先要收集目標(biāo)系統(tǒng)的信息,版本號等就是十分重要的信息,所以在linux系統(tǒng)中一般要把這些信息隱藏起來./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
在文件中黑體的部分就是得到系統(tǒng)版本信息的地方.一定要將他們注釋掉.
(5)其他配置
在普通微機中,都可以通過ctl+alt+del三鍵的組合來重新啟動linux.這樣是十分不安全的,所以要在 /etc/inittab文件中注釋該功能:
# Trap CTRL-ALT-DELETE
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now
相關(guān)文章
虛擬機安裝CentOS后沒有網(wǎng)絡(luò)怎么辦
虛擬機安裝CentOS后沒有網(wǎng)絡(luò)了不能上網(wǎng),該怎么設(shè)置網(wǎng)絡(luò)呢?下面我們就來看看這個問題的解決辦法,詳細(xì)請看下文圖文介紹2024-01-18虛擬機怎么安裝CentOS? 安裝CentOS操作系統(tǒng)的保姆級圖文教程
虛擬機想要安裝CentOS操作系統(tǒng),但是CentOS操作系統(tǒng)已經(jīng)停止維護(hù)了,該怎么安裝呢?詳細(xì)請看下文圖文教程2024-01-18Centos7.8怎么更新openssh? Centos升級openssh的技巧
Centos7.8怎么更新openssh?Centos7.8系統(tǒng)想要安裝openssh,該怎么安裝呢?下面我們就來看看Centos升級openssh的技巧2023-09-02Centos7.8怎么更新openssl? CentOS升級OpenSSL的技巧
Centos7.8怎么更新openssl?Centos7.8系統(tǒng)想要升級OpenSSL,該怎么升級呢?詳細(xì)請看下文介紹2023-09-02- centos7沒有圖形化操作可能對很多人來說都不太習(xí)慣,下面我們來為centos7安裝圖形化界面,本文以安裝 GNOME 圖形化為例,需要的朋友可以參考下2023-06-29
- 今天小編在安裝RHEL7的時候,一步留神沒有安裝圖形化桌面,下面分享一下安裝圖形化桌面的過程,需要的朋友可以參考下2023-06-29
CentOS7各個版本鏡像下載地址及版本說明(包括Everything版)
下載CentOS-7.0-1406的時候,有很多可選則的版本,對于普通用戶來說,不知道選擇哪個好,下面做一下簡單介紹,需要的朋友可以參考下2023-06-01Centos 7怎么手動配置ip地址? Centos7配置IP地址的技巧
Centos 7怎么手動配置ip地址?Centos 7系統(tǒng)想要自己配置ip地址,該怎么操作呢?下面我們就來看看Centos7配置IP地址的技巧2023-05-17- 這篇文章主要介紹了Centos 7 壓縮與解壓縮命令小結(jié),需要的朋友可以參考下2023-03-28
- 由于centos8 在2022年停止服務(wù),后繼版本為8-steam。在使用阿里云的 centos8 的 yum 時報錯,這篇文章主要介紹了CentOS8使用阿里云yum源異常的解決方法,需要的朋友可以參考2022-04-19