<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>木客网 &#187; ifconfig</title>
	<atom:link href="http://woodfeed.com/tag/ifconfig/feed/" rel="self" type="application/rss+xml" />
	<link>http://woodfeed.com</link>
	<description></description>
	<lastBuildDate>Wed, 09 Jun 2010 12:15:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Linux网络配置详解</title>
		<link>http://woodfeed.com/detailed-description-of-linux-network-configuration/</link>
		<comments>http://woodfeed.com/detailed-description-of-linux-network-configuration/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 09:45:12 +0000</pubDate>
		<dc:creator>vayu</dc:creator>
				<category><![CDATA[网络配置]]></category>
		<category><![CDATA[ifconfig]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://woodfeed.com/?p=369</guid>
		<description><![CDATA[从linux诞生的那一天起,就注定了它的网络功能空前地强大.所以在linux系统中如何配置网络,使其高效,安全的工作就显得十分重要.下面我们就从网络设备的安装,网络服务的设置和网络安全性三个方面来介绍一下linux系统中网络的设置.
一.安装和配置网络设备
二 网络服务的配置
三.网络的安全设置]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: small;">从linux诞生的那一天起,就注定了它的网络功能空前地强大.所以在linux系统中如何配置网络,使其高效,安全的工作就显得十分重要.下面我们就从网络设备的安装,网络服务的设置和网络安全性三个方面来介绍一下linux系统中网络的设置. </span></p>
<p><span style="font-size: small;">　　一.安装和配置网络设备<br />
　　在安装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.在了解了这些基本的驱动程序之后,我们就可以通过修改模块配置文件来更换网卡或者增加网卡.</span></p>
<p><span style="font-size: small;">　　1. 修改/etc/conf.modules 文件</span></p>
<p><span style="font-size: small;">　　这个配置文件是加载模块的重要参数文件,大家先看一个范例文件</span></p>
<p><span style="font-size: small;">　　#/etc/conf.modules<br />
　　alias eth0 eepro100<br />
　　alias eth1 eepro100</span></p>
<p><span style="font-size: small;">　　这个文件是一个装有两块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文件.</span></p>
<p><span style="font-size: small;">　　alias eth0 ne<br />
　　options ne io=0&#215;300 irq=5</span></p>
<p><span style="font-size: small;">　　在修改完conf.modules文件之后,就可以使用命令来加载模块,例如要插入inter的第二块网卡:</span></p>
<p><span style="font-size: small;">　　#insmod /lib/modules/2.2.14/net/eepro100.o</span></p>
<p><span style="font-size: small;">　　这样就可以在以太口加载模块eepro100.o.同时,还可以使用命令来查看当前加载的模块信息:</span></p>
<p><span style="font-size: small;">　　[root@ice /etc]# lsmod<br />
　　Module Size Used by<br />
　　eepro100 15652 2 (autoclean)</span></p>
<p><span style="font-size: small;">　　返回结果的含义是当前加载的模块是eepro100,大小是15652个字节,使用者两个,方式是自动清除.</span></p>
<p><span style="font-size: small;">　　2. 修改/etc/lilo.conf文件</span></p>
<p><span style="font-size: small;">　　在一些比较新的linux版本中,由于操作系统自动检测所有相关的硬件,所以此时不必修改/etc/lilo.conf文件.但是对于ISA网卡和老的版本,为了在系统初始化中对新加的网卡进行初始化,可以修改lilo.conf文件.在/etc/lilo.conf文件中增加如下命令:</span></p>
<p><span style="font-size: small;">　　append=&#8221;ether=5,0&#215;240,eth0 ether=7,0&#215;300,eth1&#8243;</span></p>
<p><span style="font-size: small;">　　这条命令的含义是eth0的io地址是0&#215;240,中断是5,eth1的io地址是0&#215;300,中断是7.</span></p>
<p><span style="font-size: small;">　　实际上,这条语句来自在系统引导影像文件时传递的参数,</span></p>
<p><span style="font-size: small;">　　LILO: linux ether=5,0&#215;240,eth0 ether=7,0&#215;300,eth1</span></p>
<p><span style="font-size: small;">　　这种方法也同样能够使linux系统配置好两个网卡.类似的,在使用三个以上网卡的时候,也可以依照同样的方法.</span></p>
<p><span style="font-size: small;">　　在配置好网卡之后，就应该配置TCP/IP的参数，在一般情况下,在安装linux系统的同时就会提示你配置网络参数.但是之后如果我们想要修改网络设置，可以使用如下的命令：</span></p>
<p><span style="font-size: small;">　　#ifconfig eth0 A.B.C.D netmask E.F.G.H</span></p>
<p><span style="font-size: small;">　　A.B.C.D 是eth0的IP地址,E.F.G.H是网络掩码.</span></p>
<p><span style="font-size: small;">　　其实,在linux系统中我们可以给一块网卡设置多个ip地址,例如下面的命令:</span></p>
<p><span style="font-size: small;">　　#ifconfig eth0:1 202.112.11.218 netmask 255.255.255.192</span></p>
<p><span style="font-size: small;">　　然后,使用命令#ifconfig -a 就可以看到所有的网络接口的界面:</span></p>
<p><span style="font-size: small;">　　eth0 　　Link encap:Ethernet HWaddr 00:90:27:58:AF:1A<br />
　　　　　　 inet addr:202.112.13.204 Bcast:202.112.13.255 Mask:255.255.255.192<br />
　　　　　　 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1<br />
　　　　　　 RX packets:435510 errors:0 dropped:0 overruns:0 frame:2<br />
　　　　　　 TX packets:538988 errors:0 dropped:0 overruns:0 carrier:0<br />
　　　　　　 collisions:318683 txqueuelen:100<br />
　　　　　　 Interrupt:10 Base address:0xc000</span></p>
<p><span style="font-size: small;">　　eth0:1　 Link encap:Ethernet HWaddr 00:90:27:58:AF:1A<br />
　　　　　　 inet addr:202.112.11.218 Bcast:202.112.11.255 Mask:255.255.255.192<br />
　　　　　　 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1<br />
　　　　　　 Interrupt:10 Base address:0xc000</span></p>
<p><span style="font-size: small;">　　lo 　　　Link encap:Local Loopback<br />
　　　　　　 inet addr:127.0.0.1 Mask:255.0.0.0<br />
　　　　　　 UP LOOPBACK RUNNING MTU:3924 Metric:1<br />
　　　　　　 RX packets:2055 errors:0 dropped:0 overruns:0 frame:0<br />
　　　　　　 TX packets:2055 errors:0 dropped:0 overruns:0 carrier:0<br />
　　　　　　 collisions:0 txqueuelen:0</span></p>
<p><span style="font-size: small;">　　我们看到网络接口有三个,eth0 , eth0:1,lo,eth0是真实的以太网络接口,eth0:1和eth0是同一块网卡,只不过绑定了另外的一个地址,lo是会送地址。eth0和eth0：1可以使用不同网段的ip地址，这在同一个物理网段却使用不同的网络地址的时候十分有用。</span></p>
<p><span style="font-size: small;">　　另外,网卡有一种模式是混杂模式(prosimc),在这个模式下,网卡将会接收网络中所有的数据包,一些linux下的网络监听工具例如tcpdump,snort等等都是把网卡设置为混杂模式.</span></p>
<p><span style="font-size: small;">　　ifconfig命令可以在本次运行的时间内改变网卡的ip地址，但是如果系统重新启动，linux仍然按照原来的默认的设置启动网络接口。这时候，可以使用netconfig或netconf命令来重新设置默认网络参数。</span></p>
<p><span style="font-size: small;">　　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配置的信息。</span></p>
<p><span style="font-size: small;">　　在linuxconf命令下，同样也可以配置网络信息，但是大家可以发现，linuxconf程序是调用netconf来进行网络配置的。</span></p>
<p><span style="font-size: small;">　　另外，在/etc/sysconfig/network-scripts目录下存放着系统关于网络的配置文件，范例如下：</span></p>
<p><span style="font-size: small;">　　ifcfg-eth0* 　ifdown-post* 　ifup-aliases*　 ifup-ppp*<br />
　　ifcfg-eth1*　 ifdown-ppp* 　 ifup-ipx* 　　　ifup-routes*<br />
　　ifcfg-lo*　　 ifdown-sl* 　　ifup-plip* 　　 ifup-sl*<br />
　　ifdown@ 　　　ifup@ 　　　　 ifup-post* 　　 network-functions</span></p>
<p><span style="font-size: small;">　　ifcfg-eth0是以太口eth0的配置信息，它的内容如下：</span></p>
<p><span style="font-size: small;">　　DEVICE=&#8221;eth0&#8243;　　　　　　　　　　　　　 /*指明网络设备名称*/<br />
　　IPADDR=&#8221;202.112.13.204&#8243;　　　　　　　　 /*指明网络设备的ip地址*/<br />
　　NETMASK=&#8221;255.255.255.192&#8243;　　　　　　　 /*指明网络掩码*/<br />
　　NETWORK=202.112.13.192　　　　　　　　　/*指明网络地址*/<br />
　　BROADCAST=202.112.13.255 　　　　　　　 /*指明广播地址*/<br />
　　ONBOOT=&#8221;yes&#8221; 　　　　　　　　　　　　　 /*指明在系统启动时是否激活网卡*/<br />
　　BOOTPROTO=&#8221;none&#8221; 　　　　　　　　　　　 /*指明是否使用bootp协议*/<br />
　　<br />
　　所以，我们也可以修改这个文件来进行linux下网络参数的改变。</span></p>
<p><span style="font-size: small;">　　二 网络服务的配置</span></p>
<p><span style="font-size: small;">　在这一部分,我们并不是详细的介绍具体的网络服务器(DNS,FTP,WWW,SENDMAIL)的配置(那将是巨大的篇幅),而是介绍一下与linux网络服务的配置相关的文件.</span></p>
<p><span style="font-size: small;">1. LILO的配置文件</span></p>
<p><span style="font-size: small;">　　在linux系统中,有一个系统引导程序,那就是lilo(linux loadin),利用lilo可以实现多操作系统的选择启动.它的配置文件是/etc/lilo.conf.在这个配置文件中,lilo的配置参数主要分为两个部分,一个是全局配置参数,包括设置启动设备等等.另一个是局部配置参数,包括每个引导影像文件的配置参数.在这里我就不详细介绍每个参数,特别的仅仅说明两个重要的参数&#8212;&#8212;&#8211;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).</span></p>
<p><span style="font-size: small;">　　另外,在lilo的早期版本中,存在着引导扇区必须存放到前1024柱面的限制,在lilo的2.51版本中已经突破了这个限制,同时引导界面也变成了图形界面更加直观.最新版本的下载站点:</span></p>
<p><span style="font-size: small;">　　</span><a href="ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz"></a><a href="ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz" target="_blank">ftp://166.111.136.3/pub/linux/lilo/lilo-2.51.tar.gz</a></p>
<p><span style="font-size: small;">　　下载解压后,使用命令make install即可完成安装.</span></p>
<p><span style="font-size: small;">　　注意: 物理安全才是最基本的安全,即使在lilo.conf中增加了口令保护,如果没有物理安全,恶意闯入者可以使用启动软盘启动linux系统.</span></p>
<p><span style="font-size: small;">2. 域名服务的配置文件</span></p>
<p><span style="font-size: small;">　　(1)/etc/HOSTNAME 在这个文件中保存着linux系统的主机名和域名.范例文件<br />
　　ice.xanet.edu.cn<br />
　　这个文件表明了主机名ice,域名是xanet.edu.cn</span></p>
<p><span style="font-size: small;">　　(2)/etc/hosts和/etc/networks文件 在域名服务系统中,有着主机表机制,/etc/hosts和/etc/networks就是主机表发展而来在/etc/hosts中存放着你不需要DNS系统查询而得的主机ip地址和主机名的对应,下面是一个范例文件:</span></p>
<p><span style="font-size: small;">　　# ip 地址 主机名 别名<br />
　　127.0.0.1 　　　　　localhosts 　　　　　　　loopback<br />
　　202.117.1.13　　　　</span><span style="font-size: small;"><a href="http://www.xjtu.edu.cn">www.xjtu.edu.cn</a>　　　www<br />
　　202.117.1.24 　　　 </span><span style="font-size: small;">ftp.xjtu.edu.cn</span><span style="font-size: small;"> 　　　　 ftp</span></p>
<p><span style="font-size: small;">　　在/etc/networks 中,存放着网络ip地址和网络名称的一一对应.它的文件格式和/etc/hosts是类似的</span></p>
<p><span style="font-size: small;">　　(3)/etc/resolv.conf 这个文件是DNS域名解析器的主要配置文件,它的格式十分简单,每一行由一个主关键字组成./etc/resolv.conf的关键字主要有:</span></p>
<p><span style="font-size: small;">　　domain 　　指明缺省的本地域名,<br />
　　search 　　指明了一系列查找主机名的时候搜索的域名列表,<br />
　　nameserver 指明了在进行域名解析时域名服务器的ip地址.下面给出一个范例文件:<br />
　　#/etc/resolv.conf<br />
　　domain 　　　xjtu.edu.cn<br />
　　search 　　　xjtu.edu.cn edu.cn<br />
　　nameserver 　202.117.0.20<br />
　　nameserver 　202.117.1.9<br />
　　(4)/etc/host.conf 在系统中同时存在着DNS域名解析和/etc/hosts的主机表机制时,由文件/etc/host.conf来说明了解析器的查询顺序.范例文件如下:<br />
　　#/etc/host.conf<br />
　　order hosts,bind 　　　　#解析器查询顺序是文件/etc/hosts,然后是DNS<br />
　　multi on 　　　　　　　　#允许主机拥有多个ip地址<br />
　　nospoof on 　　　　　　　#禁止ip地址欺骗<br />
3. DHCP的配置文件<br />
　　/etc/dhcpd.conf是DHCPD的配置文件,我们可以通过在/etc/dhcpd.conf文件中的配置来实现在局域网中动态分配ip地址,一台linux主机设置为dhcpd服务器,通过鉴别网卡的MAC地址来动态的分配ip地址.范例文件如下:<br />
　　option domain-name &#8220;chinapub.com&#8221;;<br />
　　use-host-decl-names off;<br />
　　subnet 210.27.48.0 netmask 255.255.255.192 {<br />
　　　　　　filename &#8220;/tmp/image&#8221;;<br />
　　　　　　host dial_server {<br />
　　　　　　　　　　　hardware ethernet 00:02:b3:11:f2:30;<br />
　　　　　　　　　　　fixed-address 210.27.48.8;<br />
　　　　　　　　　　　filename &#8220;/tmp/image&#8221;;<br />
　　　　　　}<br />
　　}</span></p>
<p><span style="font-size: small;">　　在这个文件中，最主要的是通过设置的硬件地址来鉴别局域网中的主机，并分配给它指定的ip地址，hardware ethernet 00:02:b3:11:f2:30指定要动态分配ip的主机得网卡的MAC地址，fixed-address 210.27.48.8指定分配其ip地址。filename &#8220;/tmp/image&#8221;是通过tftp服务，主机所要得到的影像文件，可以通过得到的影像文件来引导主机启动。</span></p>
<p><span style="font-size: small;">4. 超级守候进程inetd的配置<br />
　　在linux系统中有一个超级守候进程inetd,inetd监听由文件/etc/services指定的服务的端口,inetd根据网络连接请求,调用相应的服务进程来相应请求.在这里有两个文件十分重要,/etc/inetd.conf和/etc/services,文件/etc/services定义linu系统中所有服务的名称,协议类型,服务的端口等等信息,/etc/inetd.conf是inetd的配置文件,由它来指定那些服务可以由inetd来监听,以及相应的服务进程的调用命令.首先介绍一下/etc/services文件,/etc/services文件是一个服务名和服务端口对应的数据库文件,如下面所示:<br />
# /etc/services:<br />
# $Id: services,v 1.4 2000/01/23 21:03:36 notting Exp $<br />
#<br />
# Network services, Internet style<br />
#<br />
# Note that it is presently the policy of IANA to assign a single well-known<br />
# port number for both TCP and UDP; hence, most entries here have two entries<br />
# even if the protocol doesn&#8217;t support UDP operations.<br />
# Updated from RFC 1700, &#8220;Assigned Numbers&#8221; (October 1994). Not all ports<br />
# are included, only the more common ones.<br />
#名称 　　　端口/协议　　　　 别名 　　　　　　　注释<br />
tcpmux 　　 1/tcp 　　　　　　　　　　　　　　　# TCP port service multiplexer<br />
echo 　　　 7/tcp<br />
echo 　　　 7/udp<br />
discard 　　9/tcp 　　　　　sink null<br />
discard 　　9/udp 　　　　　sink null<br />
systat　　　11/tcp 　　　　 users<br />
daytime 　　13/tcp<br />
daytime 　　13/udp<br />
netstat 　　15/tcp<br />
qotd 　　　 17/tcp 　　　　　quote<br />
msp 　　　　18/tcp 　　　　　　　　　　　　　　　　# message send protocol<br />
msp 　　　　18/udp　　　　　　　　　　　　　　　　 # message send protocol<br />
chargen 　　19/tcp 　　　　ttytst source<br />
chargen　　 19/udp　　　　 ttytst source<br />
ftp-data 　 20/tcp<br />
ftp　　　　 21/tcp<br />
fsp　　　　21/udp　　　　　 fspd<br />
ssh 　　　　22/tcp 　　　　　　　　　　　　　　　　# SSH Remote Login Protocol<br />
ssh　　　　22/udp　　　　　　　　　　　　　　　　　# SSH Remote Login Protocol<br />
telnet 　　23/tcp<br />
# 24 &#8211; private<br />
smtp 　　　25/tcp 　　　　　mail<br />
# 26 &#8211; unassigned<br />
time　　　　37/tcp　　　　 timserver<br />
time 　　　37/udp 　　　　　timserver<br />
rlp 　　　　39/udp　　　　　 resource　　　　　　　　 # resource location<br />
nameserver 42/tcp 　　　　　name　　　　　　　　　　　# IEN 116<br />
whois 　　　43/tcp 　　　　　nicname<br />
re-mail-ck 　50/tcp 　　　　　　　　　　　　　　　　　# Remote Mail Checking Protocol<br />
re-mail-ck　50/udp 　　　　　　　　　　　　　　　　　 # Remote Mail Checking Protocol<br />
domain 　　 53/tcp 　　　　nameserver 　　　　　　　　# name-domain server<br />
domain　　　53/udp 　　　　nameserver<br />
mtp 　　　　57/tcp　　　　　　　　　　　　　　　　　　 # deprecated<br />
bootps 　　 67/tcp 　　　　　　　　　　　　　　　　　　# BOOTP server<br />
bootps 　　 67/udp<br />
bootpc 　　 68/tcp 　　　　　　　　　　　　　　　　　　# BOOTP client<br />
bootpc 　　 68/udp<br />
tftp 　　　 69/udp<br />
gopher 　　 70/tcp # Internet Gopher<br />
gopher 　　 70/udp<br />
rje 　　　　77/tcp netrjs<br />
finger 　　 79/tcp<br />
www 　　　　80/tcp 　　　　http　　　　　　　　　　　　 # WorldWideWeb HTTP<br />
www　　　　 80/udp 　　　　　　　　　　　　　　　　　　 # HyperText Transfer Protocol<br />
link 　　　 87/tcp 　　　　ttylink<br />
kerberos 　 88/tcp 　　　　kerberos5 krb5 　　　　　　　# Kerberos v5<br />
kerberos 　 88/udp 　　　　kerberos5 krb5 　　　　　　　# Kerberos v5<br />
supdup　　　95/tcp<br />
# 100 &#8211; reserved<br />
hostnames 　101/tcp 　　　　hostname 　　　　　　　　　　# usually from sri-nic<br />
iso-tsap 　102/tcp　　　　　tsap 　　　　　　　　　　　　# part of ISODE.<br />
csnet-ns 　105/tcp 　　　　cso-ns　　　　　　　　　　　　 # also used by CSO name server<br />
csnet-ns 　105/udp　　　　 cso-ns<br />
rtelnet 　　107/tcp 　　　　　　　　　　　　　　　　　　　# Remote Telnet<br />
rtelnet 　　107/udp<br />
pop2 　　　　109/tcp 　　　pop-2 postoffice　　　　　　　 # POP version 2<br />
pop2 　　　　109/udp　　　 pop-2<br />
pop3 　　　　110/tcp 　　　pop-3　　　　　　　　　　　　　 # POP version 3<br />
pop3　　　　 110/udp　　　 pop-3<br />
sunrpc 　　　111/tcp 　　portmapper　　　　　　　　　　　 # RPC 4.0 portmapper TCP<br />
sunrpc 　　　111/udp 　　portmapper 　　　　　　　　　　　# RPC 4.0 portmapper UDP<br />
auth 　　　　113/tcp　　 authentication tap ident<br />
sftp 　　　　115/tcp<br />
uucp-path 　　117/tcp<br />
nntp 　　　　119/tcp 　　　readnews untp　　　　　　　　　 # USENET News Transfer Protocol<br />
ntp 　　　　　123/tcp<br />
ntp 　　　　　123/udp　　　　　　　　　　　　　　　　　　　# Network Time Protocol<br />
netbios-ns 　　137/tcp　　　　　　　　　　　　　　　　　　 # NETBIOS Name Service<br />
netbios-ns 　　137/udp<br />
netbios-dgm 　　138/tcp 　　　　　　　　　　　　　　　　　　# NETBIOS Datagram Service<br />
netbios-dgm 　　138/udp<br />
netbios-ssn 　　139/tcp　　　　　　　　　　　　　　　　　　　# NETBIOS session service<br />
netbios-ssn 　　139/udp<br />
imap2 　　　　　143/tcp 　　imap 　　　　　　　　　　　　　　# Interim Mail Access Proto v2<br />
imap2 　　　　　143/udp　　 imap</span></p>
<p><span style="font-size: small;">(实际上,以上仅仅是/etc/services的一部分,限于篇幅没有全部写出)</span></p>
<p><span style="font-size: small;">　　在这个文件中,为了安全考虑,我们可以修改一些常用服务的端口地址,例如我们可以把telnet服务的端口地址改为52323,www的端口改为8080,ftp端口地址改为2121等等,这样仅仅需要在应用程序中修改相应的端口即可.这样可以提高系统的安全性.</span></p>
<p><span style="font-size: small;">/etc/inetd.conf文件是inetd的配置文件, 首先要了解一下linux服务器到底要提供哪些服务。一个很好的原则是&#8221; 禁止所有不需要的服务&#8221;，这样黑客就少了一些攻击系统的机会./etc/inetd.conf范例文件如下:<br />
#<br />
# inetd.conf　　　　This file describes the services that will be available<br />
# 　　　　　　　　　through the INETD TCP/IP super server. To re-configure<br />
# 　　　　　　　　　the running INETD process, edit this file, then send the<br />
# 　　　　　　　　　NETD process a SIGHUP signal.<br />
#<br />
# Version:　　　 @(#)/etc/inetd.conf 　　3.10 　　05/27/93<br />
#<br />
# Authors: 　　　Original taken from BSD UNIX 4.3/TAHOE.<br />
# 　　　　　　　　Fred N. van Kempen,<br />
#<br />
# Modified for Debian Linux by Ian A. Murdock<br />
#<br />
# Modified for RHS Linux by Marc Ewing<br />
#<br />
#<br />
#服务名 socket类型 协议 动作 拥有者 服务进程路径名 掉用参数<br />
#nowait 表示在相应一个网络连接之后,服务进程在释放旧的联接之前可以接受<br />
#新的连接请求,wait 则表示必须在旧连接清除之后才能接收新的连接.<br />
# Echo, discard, daytime, and chargen are used primarily for testing.<br />
# To re-read this file after changes, just do a &#8216;killall -HUP inetd&#8217;<br />
#<br />
#echo 　stream 　tcp　 nowait　 root 　internal<br />
#echo 　dgram 　　udp　 wait 　　root 　internal<br />
#discard　　　 stream 　tcp　 nowait　 root 　internal<br />
#discard　　　 dgram 　　udp 　wait 　　root 　internal<br />
#daytime stream　 tcp　　 nowait　　 root 　　internal<br />
#daytime dgram　　udp 　　wait 　　　root 　　internal<br />
#chargen 　　　　stream 　tcp 　　nowait 　root 　internal<br />
#chargen 　　　　dgram 　udp 　wait　　 root 　　internal<br />
#time 　　stream 　　tcp 　　nowait 　　root 　internal<br />
#time 　　dgram　　 udp 　　wait 　　root 　　internal<br />
#<br />
# These are standard services.<br />
#<br />
ftp 　　stream　　 tcp　　 nowait　　 root　　 /usr/sbin/tcpd 　　in.wuftpd -l -a<br />
telnet　stream 　　tcp 　　nowait 　　root 　　/usr/sbin/tcpd 　　in.telnetd<br />
#<br />
# Shell, login, exec, comsat and talk are BSD protocols.<br />
#<br />
#shell 　stream　 tcp 　nowait 　root 　　/usr/sbin/tcpd 　　in.rshd<br />
#login 　stream　 tcp　 nowait　 root　　 /usr/sbin/tcpd 　　in.rlogind<br />
#exec 　stream 　tcp　 nowait　 root 　　/usr/sbin/tcpd　　 in.rexecd<br />
#comsat dgram　 udp 　wait 　　root　　 /usr/sbin/tcpd　　 in.comsat<br />
#talk 　dgram 　udp 　wait 　　root　　 /usr/sbin/tcpd 　　in.talkd<br />
#ntalk　 dgram 　udp　wait 　　root 　　/usr/sbin/tcpd 　　in.ntalkd<br />
#dtalk　 stream　tcp　 waut　　 nobody 　/usr/sbin/tcpd 　　in.dtalkd<br />
# Pop and imap mail services et al<br />
#<br />
#pop-2 stream tcp nowait root /usr/sbin/tcpd ipop2d<br />
#pop-3 stream tcp nowait root /usr/sbin/tcpd ipop3d<br />
#imap stream tcp nowait root /usr/sbin/tcpd imapd<br />
#<br />
# The Internet UUCP service.<br />
#<br />
#uucp stream tcp nowait uucp /usr/sbin/tcpd /usr/lib/uucp/uucico -l<br />
#<br />
# Tftp service is provided primarily for booting. Most sites<br />
# run this only on machines acting as &#8220;boot servers.&#8221; Do not uncomment<br />
# this unless you *need* it.<br />
#<br />
#tftp 　dgram 　udp　 wait 　root 　/usr/sbin/tcpd 　in.tftpd<br />
#bootps dgram　 udp　 wait　 root 　/usr/sbin/tcpd　 bootpd<br />
#　<br />
# Finger, systat and netstat give out user information which may be<br />
# valuable to potential &#8220;system crackers.&#8221; Many sites choose to disable<br />
# some or all of these services to improve security.<br />
#<br />
#finger stream　 tcp 　　nowait 　　root 　　/usr/sbin/tcpd 　　in.fingerd<br />
#cfinger stream 　tcp 　　nowait　　 root 　　/usr/sbin/tcpd 　　in.cfingerd<br />
#systat stream　 tcp　　 nowait 　　guest 　　/usr/sbin/tcpd /bin/ps -auwwx<br />
#netstat stream 　tcp　　 nowait 　　guest 　　/usr/sbin/tcpd /bin/netstat 　-f inet<br />
#<br />
# Authentication<br />
#<br />
#auth　　　 stream 　tcp 　nowait　 nobody 　/usr/sbin/in.identd in.identd -l -e -o<br />
#linuxconf stream　　 tcp 　wait 　　root 　　/bin/linuxconf linuxconf -http</span></p>
<p><span style="font-size: small;">　　大家看到的这个文件已经修改过的文件,除了telnet 和ftp服务,其他所有的服务都被禁止了.在修改了/etc/inetd.conf之后,使用命令kill -HUP (inetd的进程号),使inetd重新读取配置文件并重新启动即可.<br />
5. ip route的配置</span></p>
<p><span style="font-size: small;">　　利用linux,一台普通的微机也可以实现高性价比的路由器.首先让我们了解一下linux的查看路由信息的命令:<br />
　　[root@ice /etc]# route -n<br />
　　Kernel IP routing table<br />
　　Destination　　　 Gateway　　　 Genmask 　　　　Flags Metric Ref　　 Use Iface<br />
　　202.112.13.204　　0.0.0.0 　　　255.255.255.255 UH 　0　 0 　0 　　　　eth0<br />
　　202.117.48.43 　　0.0.0.0　　　 255.255.255.255 UH　 0　 0　 0 　　　　eth1<br />
　　202.112.13.192　 202.112.13.204 255.255.255.192 UG　 0 　0 　0 　　　　eth0<br />
　　202.112.13.192 　0.0.0.0　　　　255.255.255.192 U 　0 　0 　0　　　　　 eth0<br />
　　202.117.48.0　　 202.117.48.43　255.255.255.0 　UG 　0 　0　 0 　　　　eth1<br />
　　202.117.48.0　　 0.0.0.0　　　　 255.255.255.0　 U 　0　 0　 0　　　　 eth1<br />
　　127.0.0.0 　　　0.0.0.0 　　　　255.0.0.0　　　　 U 　0 　0 　0 　　　　lo<br />
　　0.0.0.0 　　　　202.117.48.1　　 0.0.0.0 　　　　UG 　0 　0　 0 　　　　eth1<br />
　　命令netstat -r n 得到输出结果和route -n是一样的.它们操作的都是linux 内核的路由表.<br />
　　命令cat /proc/net/route的输出结果是以十六进制表示的路由表.<br />
[root@ice /etc]# cat /proc/net/route<br />
Iface　 Destination　　 Gateway 　Flags 　RefCnt 　Use　　 Metric Mask<br />
eth0 　CC0D70CA　　　　 00000000 0005 　0 　　0 　　　0 　　　　FFFFFFF<br />
eth1 　2B3075CA　　　　 00000000 0005 　0　　 0　　　 0 　　　　FFFFFFF<br />
eth0　 C00D70CA 　　　　CC0D70CA 0003 　0　　 0 　　　0 　　　　C0FFFFF<br />
eth0 　C00D70CA 　　　　00000000 0001　 0　　 0 　　　0 　　　　C0FFFFF<br />
eth1　 003075CA　　　　 2B3075CA 0003　 0　 　0 　　　0 　　　　00FFFFF<br />
eth1　　003075CA　　　　 00000000 0001 　0 　　0 　　　0 　　　　00FFFFF<br />
lo 　　0000007F 　　　　　00000000 0001　 0　　 0 　　　0　　　 000000F<br />
eth1　　 00000000 　　　　　013075CA 0003　 0　 0 　　　0　　　　 0000000<br />
　　通过计算可以知道,下面的这个路由表(十六进制)和前面的路由表(十进制)是一致的.</span></p>
<p><span style="font-size: small;">　　我们还可以通过命令route add (del )来操作路由表,增加和删除路由信息.</span></p>
<p><span style="font-size: small;">除了上面的静态路由,linux还可以通过routed来实现rip协议的动态路由.我们只需要打开linux的路由转发功能,在/proc/sys/net/ipv4/ip_forward文件中增加一个字符1.</span></p>
<p><span style="font-size: small;">　　三.网络的安全设置</span></p>
<p><span style="font-size: small;">　　在这一部分,再次强调一定要修改/etc/inetd.conf,安全的策略是禁止所有不需要的服务.除此之外,还有以下几个文件和网络安全相关.<br />
　　(1)./etc/ftpusers ftp服务是一个不太安全的服务,所以/etc/ftpusers限定了不允许通过ftp访问linux主机的用户列表.当一个ftp请求传送到ftpd,ftpd首先检查用户名,如果用户名在/etc/ftpusers中,则ftpd将不会允许该用户继续连接.范例文件如下:<br />
# /etc/ftpusers &#8211; users not allowed to login via ftp<br />
root<br />
bin<br />
daemon<br />
adm<br />
lp<br />
sync<br />
shutdown<br />
halt<br />
mail<br />
news<br />
uucp<br />
operator<br />
games<br />
nobody<br />
nadmin</span></p>
<p><span style="font-size: small;">　　(2)/etc/securetty 在linux系统中,总共有六个终端控制台,我们可以在/etc/securetty中设置哪个终端允许root登录,所有其他没有写入文件中的终端都不允许root登录.范例文件如下:</span></p>
<p><span style="font-size: small;"># /etc/securetty &#8211; tty&#8217;s on which root is allowed to login<br />
tty1<br />
tty2<br />
tty3<br />
tty4<br />
(3)tcpd的控制登录文件/etc/hosts.allow和/etc/hosts.deny<br />
　　在tcpd服务进程中,通过在/etc/hosts.allow和/etc/hosts.deny中的访问控制规则来控制外部对linux主机的访问.它们的格式都是<br />
　　service-list : hosts-list [ : command]<br />
　　服务进程的名称 : 主机列表 可选,当规则满足时的操作<br />
　　在主机表中可以使用域名或ip地址,ALL表示匹配所有项,EXCEPT表示除了某些项, PARANOID表示当ip地址和域名不匹配时(域名伪装)匹配该项.</span></p>
<p><span style="font-size: small;">　　范例文件如下:<br />
#<br />
# hosts.allow This file describes the names of the hosts which are<br />
# allowed to use the local INET services, as decided<br />
# by the &#8216;/usr/sbin/tcpd&#8217; server.<br />
#<br />
ALL : 202.112.13.0/255.255.255.0<br />
ftpd: 202.117.13.196<br />
in.telnetd: 202.117.48.33<br />
ALL : 127.0.0.1</span></p>
<p><span style="font-size: small;">　　在这个文件中,网段202.112.13.0/24可以访问linux系统中所有的网络服务,主机202.117.13.196只能访问ftpd服务,主机202.117.48.33只能访问telnetd服务.本机自身可以访问所有网络服务.<br />
　　在/etc/hosts.deny文件中禁止所有其他情况:<br />
　　#/etc/hosts.deny<br />
　　ALL : DENY : spawn (/usr/bin/finger -lp @%h | /bin/mail -s &#8220;Port Denial noted in %d-%h&#8221; root)</span></p>
<p><span style="font-size: small;">　　在/etc/hosts.allow中,定义了在所有其他情况下,linux所应该执行的操作.spawn选项允许linux系统在匹配规则中执行指定的shell命令,在我们的例子中,linux系统在发现无授权的访问时,将会发送给超级用户一封主题是&#8221;Port Denial noted in %d-%h&#8221;的邮件,在这里,我们先要介绍一下allow和deny文件中的变量扩展.</span></p>
<p><span style="font-size: small;">　　(4)/etc/issue和/etc/issue.net</span></p>
<p><span style="font-size: small;">　　在我们登录linux系统中的时候,我们常常可以看到我们linux系统的版本号等敏感信息.在如今的网络攻击行为中,许多黑客首先要收集目标系统的信息,版本号等就是十分重要的信息,所以在linux系统中一般要把这些信息隐藏起来./etc/issue和/etc/issue.net就是存放这些信息的文件.我们可以修改这些文件来隐藏版本信息.</span></p>
<p><span style="font-size: small;">另外,在每次linux重新启动的时候,都会在脚本/etc/rc.d/rc.local中再次覆盖上面那两个文件./etc/rc.d/rc.local文件的范例如下:<br />
# This script will be executed *after* all the other init scripts.<br />
# You can put your own initialization stuff in here if you don&#8217;t<br />
# want to do the full Sys V style init stuff.</span></p>
<p><span style="font-size: small;">if [ -f /etc/redhat-release ]; then<br />
R=$(cat /etc/redhat-release)</span></p>
<p><span style="font-size: small;">arch=$(uname -m)<br />
a=&#8221;a&#8221;<br />
case &#8220;_$arch&#8221; in<br />
_a*) a=&#8221;an&#8221;;;<br />
_i*) a=&#8221;an&#8221;;;<br />
esac</span></p>
<p><span style="font-size: small;">NUMPROC=`egrep -c &#8220;^cpu[0-9]+&#8221; /proc/stat`<br />
if [ "$NUMPROC" -gt "1" ]; then<br />
SMP=&#8221;$NUMPROC-processor &#8221;<br />
if [ "$NUMPROC" = "8" -o "$NUMPROC" = "11" ]; then<br />
a=&#8221;an&#8221;<br />
else<br />
a=&#8221;a&#8221;<br />
fi<br />
fi</span></p>
<p><span style="font-size: small;"># This will overwrite /etc/issue at every boot. So, make any changes you<br />
# want to make to /etc/issue here or you will lose them when you reboot.<br />
#echo &#8220;&#8221; &gt; /etc/issue<br />
#echo &#8220;$R&#8221; &gt;&gt; /etc/issue<br />
# echo &#8220;Kernel $(uname -r) on $a $SMP$(uname -m)&#8221; &gt;&gt; /etc/issue</span></p>
<p><span style="font-size: small;">cp -f /etc/issue /etc/issue.net<br />
echo &gt;&gt; /etc/issue</span></p>
<p><span style="font-size: small;">　　在文件中黑体的部分就是得到系统版本信息的地方.一定要将他们注释掉.</span></p>
<p><span style="font-size: small;">　　(5)其他配置<br />
　　在普通微机中,都可以通过ctl+alt+del三键的组合来重新启动linux.这样是十分不安全的,所以要在/etc/inittab文件中注释该功能:<br />
　　# Trap CTRL-ALT-DELETE<br />
　　#ca::ctrlaltdel:/sbin/shutdown -t3 -r now<br />
<span style="font-size: small;">from:http://blog.chinaunix.net/u3/93926/showart_1874547.html</span></span></p>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li><a href="http://woodfeed.com/vmware-virtual-machine-under-linux-network/" title="VMWare虚拟机下linux联网">VMWare虚拟机下linux联网</a><br /><small>VMWare虚拟机下安装的RedHat 9.0 linux有三种方式实现上网，桥接、na...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://woodfeed.com/detailed-description-of-linux-network-configuration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
