TCP中的NO_DELAY

1. TCP网络优化的两种机制

TCP(Transmission Control Protocol 传输控制协议)是一种面向连接的、可靠的、全双工、基于字节流的传输层通信协议,由IETF的RFC 793定义。

 TCP协议是网络编程中最重要的协议之一,TCP协议将上层的数据附上TCP报头等信息,封装成一个个报文段(segment),然后交由下层网络层去处理。TCP协议定义了TCP报文段的结构,如下图所示:

这里写图片描述

可以看出,TCP每个报文段的首部大小至少是20字节的数据,因此若用户数据为1字节,再加上网络层IP包头20字节,则整个IP数据包的大小为41字节,那么整个IP数据包的负荷率为1 / 41。这显然是不划算的,会降低网络的传输效率,当网络都充斥着这种IP数据包的时候,可想而知整个网络几乎都在传输一些无用的包头信息,这种问题被称为小包问题。特别是在Telnet协议中,当用户远程登录到一个主机,他的每一次键盘敲击实际上都会产生一个携带用户数据量小的数据包,这是典型的小包问题。

为了解决这种问题,出现了Nagle's Algorithms,这个算法是John Nagle为解决实际过程中出现的小包问题而发明的。它的思想很朴素,就是将多个即将发送的小段的用户数据,缓存并合并成一个大段数据时,一次性一并发送出去。特别的是,只要当发送者还没有收到前一次发送TCP报文段的的ACK(即连接中还存在未回执ACK的TCP报文段)时,发送方就应该一直缓存数据直到数据达到可以发送的大小,然后再统一合并到一起发送出去,如果收到上一次发送的TCP报文段的ACK则立马将缓存的数据发送出去。

以下是Nigle算法的伪代码:

if there is new data to send
  if the window size >= MSS and available data is >= MSS
    send complete MSS segment now
  else
    if there is unconfirmed data still in the pipe
      enqueue data in the buffer until an acknowledge is received
    else
      send data immediately
    end if
  end if
end if

MSS = maximum segment size

与之相呼应的还有一个网络优化的机制叫做TCP延迟确认,这个是针对接收方来讲的机制,由于ACK包属于有效数据比较少的小包,因此延迟确认机制就会导致接收方将多个收到数据包的ACK打包成一个回复包返回给发送方。这样就可以避免导致只包含ACK的TCP报文段过多导致网络额外的开销(前面提到的小包问题)。延迟确认机制有一个超时机制,就是当收到每一个TCP报文段后,如果该TCP报文段的ACK超过一定时间还未发送就启动超时机制,立刻将该ACK发送出去。因此延迟确认机制会可能会带来500ms的ACK延迟确认时间。

延迟确认机制和Nigle算法几乎是在同一时期提出来的,但是是由不同的组提出的。这两种机制在某种程度上的确对网络传输进行了优化,在通常的协议栈实现中,这两种机制是默认开启的。

但是,这两种机制结合起来的时候会产生一些负面的影响,可能会导致应用程序的性能下降。

2. write-write-read模式带来的问题

考虑这么一种情况,

  1. 假设发送方A启用了Nigle算法,接收方B启用了延迟确认机制,则当发送方A向TCP连接进行了两次write操作,每次write操作都之写入了少量的数据(少于MSS),假设写入的数据片段为w1,w2,然后紧接着调用了阻塞式的read操作。

  2. 因为连接中没有未收到ACK的TCP报文段,发送方A的第一次写入的w1会立马发送出去;

  3. 则在接收方来B来看,它会首先收到包含w1数据段的TCP报文段,但是由于延迟确认机制,接收方B会延迟发送该TCP报文段的ACK直到超时。

  4. 而对于发送方A来说,根据Nigle算法,由于连接中上一个TCP报文段未收到ACK,并且第二次写入的w2数据段过于小(小于MSS),则发送方A会将w2入队列缓存起来,不会立即发送。

  5. 然而不幸的是,发送方A此时并不继续发送数据,因此依靠发送方A将缓存填满来把w2数据段发送出是不可能的了,现在只能傻傻的等待接收方B因为超时而返回w1的ACK了。

  6. 这样当接收方B因为超时而返回ACK后,发送方A就会立即发送包含w2数据段的TCP报文段。

自此,w1、w2数据段才被完整的发送给接收方B,如果忽略传输时间等其他因素,这额外增加的数据传输延迟就是接收方B启用的延迟确认机制中的超时的值。

因此当延迟确认机制和Nigle算法都启用的时候,正好碰上了这种write-write-read模式的数据传输,就会出现这种问题,因此wiki上就有这些建议:

The user-level solution is to avoid write-write-read sequences on sockets. write-read-write-read is fine. write-write-write is fine. But write-write-read is a killer. So, if you can, buffer up your little writes to TCP and send them all at once. Using the standard UNIX I/O package and flushing write before each read usually works.

Nigle算法在一次性写入比较大的数据段时会出现延迟的现象,特别是对于Request-Response模式的程序来讲,通常一个请求的数据会大于MMS,这样一个请求就会跨越多个TCP报文段,因此Nigle算法会导致最后一个TCP报文段被Hold住,出现延时;同样的一个回复的数据也会大于MMS,因此也会出现这种延时。

Nigle算法通常是用来防止那些写得不太好的程序,防止这些程序随意的发小包降低网络传输效率;而对于一些精心编写的程序,Nigle算法几乎没什么用,应用程序编写者应该合理的把握、判断好每次写入的数据的大小,进而采取适当的策略进行发送,要么将小包合并到MMS大小,然后一次性写入并发送;要么禁用Nigle算法。

当然以上只是一种解决方案,通常的协议栈会预留接口来禁用Nigle算法,即设置TCP_NODELAY选项。

3. TCP的NO_DELAY选项

 Socket编程模型会有一个预留接口来禁用Nigle算法,这个接口就是TCP NODELAY。
这是网上的用Java写的一个关于是否启用TCP NODELAY的实验

需要说明的是这个实验在同一台windows上是不成功的,在windows上的loopback地址的处理可能和Linux不太一样。在windows下实验,开启TCP NODELAY与否都不会出现延迟的情况。奇怪的是我选一台windows做Client,一台Max机器做Server,实验仍然失败,不知道Windows对于Nagle算法是否是否是默认的开启。但是我选windows机器做Server,Mac机器做Client,实验结果显而易见。

需要说明的是这个实验在同一台windows上是不成功的,在windows上的loopback地址的处理可能和Linux不太一样。在windows下实验,开启TCP NODELAY与否都不会出现延迟的情况。奇怪的是我选一台windows做Client,一台Max机器做Server,实验仍然失败,不知道Windows对于Nagle算法是否是否是默认的开启。但是我选windows机器做Server,Mac机器做Client,实验结果显而易见。

Server端代码


public class Server {   

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            ServerSocket socket = new ServerSocket(9989);
            System.out.println("绑定端口");
            while(true) {
                Socket con  = socket.accept();
                new Thread( new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        try {
                            InputStream in = con.getInputStream();
                            OutputStream out = con.getOutputStream();
                            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                            while (true) {
                                String line = reader.readLine();
                                if(!con.isClosed())
                                    out.write((line + "\r\n").getBytes());
                            }
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }).start();
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Client端



public class Client {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Socket s = new Socket("192.168.31.235", 9989);
            s.setTcpNoDelay(true);
            OutputStream ops = s.getOutputStream();
            InputStream in = s.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 

            // write-write-read
            String head = "h";
            String body = "w\r\n";

            int i = 10;

            while ( i-- > 0) {
                long label = System.currentTimeMillis(); 
                ops.write(head.getBytes());
                ops.write(body.getBytes());// 会有延迟吧应该,有可能不会阻塞
                InputStream ips = s.getInputStream();
                String line = reader.readLine();  
                System.out.println("RTT:" + (System.currentTimeMillis() - label) + ", receive: " + line);
            }
            s.close();
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

其中Server代码跑在Windows上,Client代码跑在Mac上

未开启TCP NODELAY,write-write-read模式

这里写图片描述

开启TCP NODELAY,write-write-read模式

这里写图片描述
未开启TCP NODELAY, write-read模式

这里写图片描述
开启TCP NODELAY, write-read模式

这里写图片描述
可以明显的看出,当采用write-write-read模式,且未开启TCP NODELAY选项时(未禁用Nagle算法)时,延迟产生了,大约200ms。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PCAUSA Test TCP (PCATTCP) Release Notes Printing Communications Associates, Inc. 4201 Brunswick Court Smyrna, GA 30080 USA TEL: (770) 432-4580 FAX: (770) 436-7246 E-Mail: [email protected] ====================================================================== Component Part No.: N/A Component Name : PCAUSA Test TCP (PCATTCP) ====================================================================== Component Version : 2.01.01.11 Release Date : February 4, 2010 1.) Now flush stderr/stdout for all exit paths. ====================================================================== Component Version : 2.01.01.10 Release Date : November 3, 2009 1.) Added new -a option to specifiy local host IP address. 2.) Now built using Visual Studio 2008 (for better or worse...). ====================================================================== Component Version : 2.01.01.07 Release Date : November 23, 2003 1.) Incorporated fix identified by Clarkson University that reduces hangs when ending the UDP transmitter test. See additional comments in TTCP_TransmitUDP module. ====================================================================== Component Version : 2.01.01.06 Release Date : April 5, 2003 1.) Fixed minor bug in TTCP transmitter. PCAUSA PCATTCP preamble was not inserted correctly when building transmit buffer. ====================================================================== Component Version : 2.01.01.05 Release Date : May 31, 2002 1.) Modification to allow SO_RVCBUF and SO_SNDBUF values of zero(0) to be handled. Original implementation did not set these options if their value was zero. 2.) Added -w write delay option. ====================================================================== Component Version : 2.01.01.04 Release Date : May 30, 2002 1.) Minor fix to test exit routines. ====================================================================== Component Version : 2.01.01.03 Release Date : May 29, 2002 Externally Visible Differences ------------------------------ 1.) Added -c "continuous" option: -c -t: send continuously -r: accept multiple connections sequentially 1.) Added -R multi-threaded concurrent TCP/UDP receiver option. 2.) Fixed error codes. Now fetch using WSAGetLastError instead of perror. The latter did not handle socket errors. 3.) Revised test output messages. 4.) New PCATTCP.chm HtmlHelp documentation. Implementation Differences -------------------------- Extensive rework to suit author's style. ====================================================================== Component Version : 1.00.00.02 Release Date : January, 2000 Fix setting of setsockopt call for TCP_NODELAY. ====================================================================== Component Version : 1.00.00.01 Release Date : April, 1999 Initial release of PCAUSA's port of TTCP to Windows.
//--------------------------------------------------------------------------- // Net MAIN.C // // 8051 Web Server project // See Makefile for build notes // Written for Keil C51 V5.1 compiler, notes: // It uses big endian order, which is the same as the // network byte order, unlike x86 systems. // Use OPTIMIZE(2)or higher so that automatic variables get shared // between functions, to stay within the 256 bytes idata space //--------------------------------------------------------------------------- #include #include #include "89E564RD.H" #include "net.h" #include "eth.h" #include "serial.h" #include "timer.h" #include "arp.h" #include "tcp.h" #include "http.h" #include "ip.h" // Global variables unsigned int volatile event_word; unsigned char idata debug; unsigned char idata rcve_buf_allocated; char xdata text[20]; // This sets my hardware address to 00:01:02:03:04:05 unsigned char code my_hwaddr[6] = {0x52, 0x54, 0x4c, 0xbb, 0x50, 0xd8}; // Hardware addr to send a broadcast unsigned char code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // This sets my IP address to 192.168.0.168 unsigned long code my_ipaddr = 0xC0A800A8L; // This sets my subnet mask to 255.255.255.0 unsigned long code my_subnet = 0xFFFFFF00L; // Set to 0 if no gateway is present on network // unsigned long code gateway_ipaddr = 0; // This sets my gateway address to 192.168.0.1 unsigned long code gateway_ipaddr = 0xC0A80001L; //-------------------------------------------------------------------------- // Initialize the memory management routines // Initialize variables declared in main //-------------------------------------------------------------------------- unsigned int Count1msInc; unsigned char Count1ms,Count10ms,Count1s; unsigned char TimeSecond,TimeMinute; /***************************************************************************************** ** 函数名称: init_main(void) ** 功能描述: 主函数初始化 ** 调用参数: 无 ** 返回参数: 无 ** 调用模块: init_mempool((vo
上一页 第 1 2 3 4 页 下一页 八、再发布路由协议   九、TCP/IP症状和原因   症状 原因   本地主机不能与远程主机通讯 1) DNS工作不正常2) 没有到远程主机的路由3) 缺少缺省网关4) 管理拒绝(ACL)   某个应用程序不能正常工作 1) 管理拒绝(ACL)2) 网络没有正常配置以处理该应用程序   启动失败 1) BootP服务器没有MAC地址的实体2) 缺少IP helper-address3) ACL4) 修改NIC或MAC地址5) 重复的IP地址6) 不正常的IP配置   不能ping远程主机 1) ACL2) 没有到远程主机的路由3) 没有设置缺省网关4) 远程主机down   缺少路由 1) 没有正确配置路由协议2) 发布列表3) 被动接口4) 没有通告路由的邻居5) 路由协议版本不一致6) 邻居关系没有建立   相邻关系没有建立 1) 不正确的路由协议配置2) 不正确的IP配置3) 没有配置network或neighbor语句4) hello间隔不一致5) 不一致的area ID   高的CPU利用率 1) 不稳定的路由更新2) 没有关闭debug3) 进程过重   路由触发活跃模式 1) 不一致的间隔2) 硬件问题3) 不稳定的链路   十、TCP/IP症状和行动计划   问题 行动计划   DNS工作不正常 1)配置DNS主机的配置和DNS服务器,可以使用nslookup校验DNS服务器的工作   没有到远程主机的路由 1) 用ipconfig /all检查缺省网关2) 用show ip route查看是否相应路由3) 如果没有该路由,用show ip route查看是否有缺省网关4) 如有网关,检查到目标的下一跳;如无网关,修正问题   ACL 有分离的问题与ACL相关,必须分析ACL、或重写ACL并应用。   网络没有配置以处理应用程序 查看路由器配置   Booting失败 1) 查看DHCP或BootP服务器,并查看是否存在故障机的MAC实体2) 使用debug ip udp校验从主机接收的包3) 校验helper-address正确配置4) 查看ACL是否禁用包   缺少路由 1) 在第1台路由器上用show ip route查看所学到的路由2)校验相邻路由器3)有正确的路由network和neighbor语句4) 对OSPF,校验通配符掩码5) 检查应用到接口上的distribute list6)验证邻居的IP配置7) 如果路由被再发布,验证度量值8) 验证路由被正常的再发布   没有构成相邻关系 1) 用show ip protocol neighbors列表已构成的相邻关系2) 查看没有构成相邻关系的协议配置3)检查路由配置的network语句4)用show ip protocol/interface查看特定的接口信息,如Hello间隔 第7章 处理串行线路和帧继连接故障   一、处理串行线路故障   1、HDLC封装   High-level Data Link Control(HDLC)是用于串行链路的一种封装方法,HDLC是Cisco路由器串行接口的缺省封装方法。   处理串行链路故障的第一步就是查看链路两端要使用相同的封装类型。   Show interface serial 1 ;查看接口信息   Clear counters serial number ;复位接口的计数器到0   正常情况下,接口和line都是up的。   线缆故障、载波故障和硬件故障都可导致接口down,通过校验电缆连接、更换硬件(包括电缆)、检查载波信令定位问题。   接口up,line down:CSU/DSU故障、路由器接口问题、CSU/DSU或载波的时间不一致、没有从远端路由器接收到keepalive信令、载波问题。应验证本地接口和远端接口的配置。   接口重启的原因:   ? 数秒内排队的包没有被发送;   ? 硬件问题(路由器接口、线缆、CSU/DSU);   ? 时钟信令不一致   ? 环路接口   ? 接口关闭   ? 线协议down且接口定期重启   show controllers serial 0 ;显示接口状态、是否连有线缆、时钟速率   show buffers ;查看系统buffer池,接口buffer设置   debug serial interface ;显示HDLC或Frame Relay通信信息   2、CSU/DSU环路测试   有四种类型的环路测试:   ? 在本地CSU/DSU上测试本地环路;   ? 在远端CSU/DSU上测试本地环路;   ? 从本地NIU到远端CSU/DSU测试远端环路;   ? 从远端NIU到本地CSU/DSU测试远端环路;   用PPP封装的串行链路上,PPP用协商Magic Number检测环回网络。   3、串行线总结:   1) 症状和问题:   症状或情形 问题   Interface is administratively down;line protocol is down 1) 接口被从命令行关闭2) 不允许重复的IP地址,两个使用相同IP地址的接口将down   Interface is down;line protocol is down 1) 不合格的线缆2) 没有本地提供商的信令3) 硬件故障(接口或CSU/DSU、线缆)4) 时钟   Interface is up;line protocol is down 1) 未配置的接口:本地或远程2) 本地提供商问题3) Keepalive序号没有增加4) 硬件故障(本地或远端接口、CSU/DSU)5) 线路杂音6) 时钟不一致7) 第2层(如LMI)   Interface is up;line protocol is up(looped) 链路在某处环路   Incrementing carrier transition counter 1) 来自本地提供商的信号不稳定2) 线缆故障3) 硬件故障   Incrementing interface resets 1) 线缆故障,导致CD信号丢失2) 硬件故障3) 线路拥塞   Input drops,errors,CRC,and framing errors 1) 线路速率超过接口能力2) 本地提供商问题3) 线路杂音4) 线缆故障5) 不合格线缆6) 硬件故障   Output drops 接口传输能力超过线路速率   2) 问题和行动   问题 解决行动方案   本地提供商问题 1) 检查CSU/DSU的CD信号和其它信号,看链路是否在发送和接收信息2) 如果没有CD信号或有其它问题,联系本地提供商处理故障   不合格或故障的线缆 1) 使用符合设备要求的线缆2) 使用breakout盒检查3) 交换故障线缆   未配置的接口 1) 使用show running-config校验接口配置2) 确认链路两端使用相同的封装类型   Keepalive问题 1) 验证keepalive被发送2) 配置了keepalive发送,debug keepalive3) 验证序号在增加4) 如果序号不增加,运行环路测试5) CSU/DSU环路,序号仍不增,则硬件故障   硬件故障 1)更换硬件   接口在环路模式 1) 检查接口配置2) 如果在接口配置有环路,移除3) 如果接口配置被清除,清除CSU/DSU环路模式4) 如CSU/DSU不在环路模式,可能是提供商置环   接口administratively down 1) 检查是否有重复的IP地址2) 进行接口配置模式,执行no shutdown   线路速率大于接口能力 1) 使用hold-queue减少进入的队列尺寸2) 增加输出的队列尺寸   接口速率大于线路速率 1) 减少广播流量2) 增加输出的队列3) 如有需要,使用队列算法 二、处理帧继故障   DLCI用于在帧标识虚拟链路,DLCI仅仅是本地信令,DLCI与第3层IP地址相映射。   处理帧继的步骤:   1) 检查物理层,线缆或接口问题;   2) 检查接口封装;   3) 检查LMI类型;   4) 校验DLCI到IP的映射;   5) 校验Frame Delay的PVC;   6) 校验Frame Delay的LMI;   7) 校验Frame Delay映射;   8) 校验环路测试;   1、帧继的show命令   show interface   show frame-relay lmi ;显示LMI相关信息(LMI类型、更新、状态)   show frame-relay pvc ;输出PVC信息、每条DLCI的LMI状态、…)   show frame-relay map ;提供DLCI号信息和所有FR接口的封装   2、帧继的debug命令   debug frame-relay lmi ;显示LMI交换信息   debug frame-relay events ;显示协议和应用程序使用DLCI的细节   3、帧继总纳   1) 症状和问题   症状或情形 相关问题   Frame Realy link is down 1) 线缆故障2) 硬件故障3) 本地服务商问题4) LMI类型不一致5) Keepalive没有被发送6) 封装类型不一致7) DLCI不一致   从Frame Delay网络不能ping远端主机 1) DLCI指定了错误的接口2) 封装类型不一致3) ACL问题4) 接口配置错误   2) 问题和行动   问题 解决行动方案   线缆故障 1) 检查线缆并测试接头2) 更换线缆   硬件故障 1) 执行环路测试,以分离硬件2) 将线缆连接到路由器的另一同样配置的接口,如OK,则需更换硬件   本地服务提供商问题 1) 如环路测试使LMI状态up,但不能连接远端着站点,联系本地载波2) 包含载波问题,就好象FR配置错误,如DLCI不一致或封装不一致。   LMI类型不一致 1) 校验路由器的LMI类型与PVC上的每个设备都一致2) 如使用公共提供商网络,不能访问LMI,与提供商联系   Keepalive问题 1) 使用show interface查看是否keepalive被禁用,或校验keepalive被正常配置2) 如果keepalive设置错误,进入配置模式并在接口上指定keepalive间隔   封装类型 1) 校验两端路由器的封装方式相同,如有非Cisco路由器,必须用IETF。用show frame-relay命令显示封装信息2)用encapsulation frame-relay ietf更换封装方式,与可用frame-relay map设置某个PVC的封装。   DLCI不一致 1) 用show running-config和show frame-relay pvc显示指派给某接口的DLCI号2) 如DLCI号配置正常,联系供应商校验FR交换机是否了相同的DLCI   ACL问题 1) 使用show ip interface显示应用到接口上的ACL2) 分析ACL,如有需要,删除或修改它 第8章 处理ISDN故障   一、ISDN基本原理   二、常见ISDN故障   ISDN问题分成3类:配置不当的路由器、物理线缆和ISDN协议、配置不当的交换机。   1、配置不当的路由器   配置不当由于不同原因:typographical错误、从服务供应商提供的错误信息、本路由器配置不正确   1) SPID(Service Profile Identifiers):如SPID和LDN配置错误,将有ISDN连接问题。SPID仅用于北美,只有服务供应商要求时才设置。   2) CHAP:CHAP认证在使用PPP封装的接口上使用。两端路由器的CHAP配置一定要相同。在PPP,用户名和口令是大小写敏感的。   3) Dialer Map实体:Dialer map关联高层地址到相关的电话号码。每种协议需要一条dialer map语句。   4) 访问列表:ACL可用于ISDN连接以阻止某类型流量触发连接。   5) PPP:   2、物理层连接   1) BRI:在现有电话线上提供数字服务。   2) ISDN BRI信道:2B+D(2*64+16+48=192kbps);ISDN BRI的物理帧为48bits,链路每秒发送4000帧。   3) 本地环路:客户和CO之间的链路,连接ISDN设备到ISDN交换机。   4) 物理层:参考点(R、S、T、U);设备(LT/ET、NT1、NT2、TE1、TE2、TA)   三、配置不当的电话交换机   在新安装ISDN时,必须考虑服务供应商ISDN交换机配置错误的可能性。   1、第2层故障处理:   ISDN第2层故障处理的目标:q.921协议和PPP。   1) q.921:ISDN的第2层在q.921定义。Q.921信令在D信道上用LAPD协议传输。处理q.921故障最常用命令是debug isdn q921,问题常与TEI(terminal endpoint identifier)、SAPI(service access point identifier)和SABME(set asynchronous balanced mode extended)有关。   TEI=127表示广播;TEI=64-126保留用于动态分配。   SAPI=0表示当前第3层信令;63表示用于TEI值分配的管理SAPI;64为呼叫控制。   2) PPP:PPP使用LCP设置和维护链路;NCP配置和维护网络层协议。   2、第3层故障处理:   ISDN第3层也叫q.931,使用debug isdn q931命令可查看call setup、connect、release、cancel、status、disconnect和、user information。   ISDN第3层连接在本地路由器(TE)和远端ISDN交换机(ET)之间。   ISDN呼叫建立的过程:   1) SETUP:在本地TE和远端ET之间发送信息   2) CALL_PROC:呼叫处理信令   3) ALERT:   4) CONNECT   5) CONNECT_ACK:   3、交换机类型:   配置ISDN时,必须用isdn switch-type命令指定本地环路的交换机。
Table of Contents Table of Contents ................................................................................................................................................. 4 Overview ................................................................................................................................................................. 8 Consensus Guidance ....................................................................................................................................... 8 Intended Audience .......................................................................................................................................... 8 Acknowledgements ........................................................................................................................................ 9 Typographic Conventions .......................................................................................................................... 10 Configuration Levels ................................................................................................................................... 10 Level-I Benchmark settings/actions ................................................................................................. 10 Level-II Benchmark settings/actions................................................................................................ 10 Scoring Status ................................................................................................................................................ 10 Scorable ....................................................................................................................................................... 10 Not Scorable .............................................................................................................................................. 11 Identification Table ..................................................................................................................................... 11 Assumptions and Recommendations .................................................................................................... 11 OS Platform ................................................................................................................................................ 11 System State .............................................................................................................................................. 11 Test Actions ............................................................................................................................................... 11 Shell Environment ................................................................................................................................... 12 Order of Operations ................................................................................................................................ 12 Backup Key Files ...................................................................................................................................... 12 Create /opt/CIS Directory (optional) .......................................................................................... 12 Benchmark Items .............................................................................................................................................. 13 1. Install Updates, Patches and Additional Software ....................................................................... 13 1.1 Use the Latest OS Release .............................................................................................................. 13 1.2 Apply Latest OS Patches ................................................................................................................. 14 1.3 Install Solaris Encryption Kit ....................................................................................................... 15 2. Restrict Services ....................................................................................................................................... 17 2.1 Establish a Secure Baseline .......................................................................................................... 17 2.2 Disable Unnecessary Local Services .......................................................................................... 18 2.2.1 Disable Local CDE ToolTalk Database Server ............................................................... 19 2.2.2 Disable Local CDE Calendar Manager .............................................................................. 19 2.2.3 Disable Local Graphical Login Environment ................................................................. 20 2.2.4 Disable Local sendmail Service .......................................................................................... 21 2.2.5 Disable Local Web Console .................................................................................................. 22 2.2.6 Disable Local WBEM ............................................................................................................... 22 2.2.7 Disable Local BSD Print Protocol Adapter ..................................................................... 23 2.3 Disable Other Services .................................................................................................................... 24 2.3.1 Disable RPC Encryption Key ................................................................................................ 24 2.3.2 Disable NIS Server Daemons ............................................................................................... 25 2.3.3 Disable NIS Client Daemons................................................................................................. 26 2.3.4 Disable NIS+ Daemons ........................................................................................................... 26 2.3.5 Disable LDAP Cache Manager ............................................................................................. 27 2.3.6 Disable Kerberos TGT Expiration Warning ................................................................... 28 2.3.7 Disable Generic Security Services (GSS) Daemons ..................................................... 28 2.3.8 Disable Volume Manager ...................................................................................................... 29 2.3.9 Disable Samba Support .......................................................................................................... 30 2.3.10 Disable automount Daemon......................................................................................... 31 2.3.11 Disable Apache Services ................................................................................................... 32 2.3.12 Disable Solaris Volume Manager Services ................................................................. 33 2.3.13 Disable Solaris Volume Manager GUI .......................................................................... 34 2.3.14 Disable Local RPC Port Mapping Service ................................................................... 35 2.4 Configure TCP Wrappers ............................................................................................................... 36 3. Kernel Tuning ........................................................................................................................................... 38 3.1 Restrict Core Dumps to Protected Directory ......................................................................... 38 3.2 Enable Stack Protection ................................................................................................................. 39 3.3 Enable Strong TCP Sequence Number Generation .............................................................. 40 3.4 Modify Network Parameters ........................................................................................................ 41 3.4.1 Disable Source Packet Forwarding ................................................................................... 44 3.4.2 Disable Broadcast Packet Forwarding............................................................................. 45 3.4.3 Disable Response to ICMP Timestamp Requests ........................................................ 46 3.4.4 Disable Response to ICMP Broadcast Timestamp Requests ................................... 47 3.4.5 Disable Response to ICMP Netmask Requests ............................................................. 48 3.4.6 Disable ICMPv6 Redirect Messages .................................................................................. 50 3.4.7 Disable Response to Broadcast ICMPv4 Echo Request ............................................. 51 3.4.8 Disable Response to Multicast Echo Request ............................................................... 52 3.4.9 Set Interval for Scanning IRE_CACHE .............................................................................. 53 3.4.10 Ignore ICMP Redirect Messages .................................................................................... 55 3.4.11 Set Strict Multihoming ....................................................................................................... 56 3.4.12 Disable ICMPv4 Redirect Messages .............................................................................. 57 3.4.13 Set ARP Cleanup Interval .................................................................................................. 59 3.4.14 Disable TCP Reverse IP Source Routing ..................................................................... 60 Set Maximum Number of Half-open TCP Connections ...................................................... 61 3.4.15 ............................................................................................................................................................ 61 3.4.16 Set Maximum Number of Incoming Connections.................................................... 62 3.4.17 Lock down dtspcd(8) ................................................................................................... 64 3.5 Disable Network Routing .............................................................................................................. 65 4. Logging ........................................................................................................................................................ 66 4.1 Enable inetd Connection Logging ............................................................................................... 66 4.2 Enable FTP daemon Logging ........................................................................................................ 67 4.3 Enable Debug Level Daemon Logging ...................................................................................... 68 4.4 Capture syslog AUTH Messages.............................................................................................. 69 4.5 Enable Login Records ..................................................................................................................... 70 4.6 Capture All Failed Login Attempts ............................................................................................. 71 4.7 Enable cron Logging ........................................................................................................................ 71 4.8 Enable System Accounting ............................................................................................................ 72 4.9 Enable Kernel Level Auditing ...................................................................................................... 73 5. File/Directory Permissions/Access .................................................................................................. 76 5.1 Set daemon umask ........................................................................................................................... 76 5.2 Restrict Set-UID on User Mounted Devices ............................................................................ 77 5.3 Set Sticky Bit on World Writable Directories ........................................................................ 78 6. System Access, Authentication, and Authorization ..................................................................... 79 6.1 Disable login: Prompts on Serial Ports ............................................................................... 79 6.2 Disable "nobody" Access for RPC Encryption Key Storage Service .............................. 80 6.3 Configure SSH.................................................................................................................................... 80 6.3.1 Set SSH Protocol to 2 .............................................................................................................. 81 6.3.2 Disable SSH X11Forwarding ................................................................................................ 82 6.3.3 Set SSH MaxAuthTries to 3 ................................................................................................... 83 6.3.4 Set SSH MaxAuthTriesLog to 0 ........................................................................................... 84 6.3.5 Set SSH IgnoreRhosts to yes ................................................................................................ 85 6.3.6 Set SSH RhostsAuthentication to no ................................................................................. 86 6.3.7 Set SSH RhostsRSAAuthentication to no......................................................................... 87 6.3.8 Disable SSH root login ............................................................................................................ 87 6.3.9 Set SSH PermitEmptyPasswords to no ............................................................................ 88 6.3.10 Set SSH Banner ..................................................................................................................... 89 6.4 Disable .rhosts Support in /etc/pam.conf ............................................................................... 90 6.5 Restrict FTP Use ............................................................................................................................... 91 6.6 Set Delay between Failed Login Attempts to 4 ..................................................................... 92 6.7 Set Default Screen Lock for CDE Users ..................................................................................... 93 6.8 Set Default Screen Lock for GNOME Users ............................................................................. 94 6.9 Restrict at/cron to Authorized Users ....................................................................................... 95 6.10 Restrict root Login to System Console .............................................................................. 96 6.11 Set Retry Limit for Account Lockout ..................................................................................... 97 6.12 Set EEPROM Security Mode and Log Failed Access ........................................................ 98 6.13 Secure the GRUB Menu ............................................................................................................ 100 7. User Accounts and Environment ...................................................................................................... 101 7.1 Disable System Accounts ............................................................................................................. 101 7.2 Set Password Expiration Parameters on Active Accounts ............................................. 103 7.3 Set Strong Password Creation Policies .................................................................................. 104 7.4 Set Default Group for root Account ...................................................................................... 106 7.5 Change Home Directory for root Account ........................................................................ 107 7.6 Set Default umask for Users ....................................................................................................... 108 7.7 Set Default umask for FTP Users .............................................................................................. 109 7.8 Set "mesg n" as Default for All Users ....................................................................................... 110 7.9 Lock Inactive User Accounts ...................................................................................................... 111 8. Warning Banners ................................................................................................................................... 112 8.1 Create Warnings for Standard Login Services..................................................................... 113 8.2 Create Warning Banner for CDE Users .................................................................................. 114 8.3 Create Warning Banner for GNOME Users ........................................................................... 115 8.4 Create Warning Banner for FTP daemon .............................................................................. 116 8.5 Check Banner Setting for telnet is Null ............................................................................. 117 9. System Maintenance ............................................................................................................................. 117 9.1 Check for Remote Consoles ........................................................................................................ 118 9.2 Verify System File Permissions ................................................................................................. 118 9.3 Ensure Password Fields are Not Empty ................................................................................ 119 9.4 Verify No Legacy “+” Entries Exist in passwd, shadow, and group Files ............. 120 9.5 Verify No UID 0 Accounts Exist Other than root ................................................................ 120 9.6 Ensure root PATH Integrity ........................................................................................................ 121 9.7 Check Permissions on User Home Directories .................................................................... 122 9.8 Check User Dot File Permissions .............................................................................................. 123 9.9 Check Permissions on User .netrc Files ............................................................................ 124 9.10 Check for Presence of User .rhosts Files............................................................................ 125 9.11 Check Groups in /etc/passwd ............................................................................................... 126 9.12 Check That Users Are Assigned Home Directories ....................................................... 127 9.13 Check That Defined Home Directories Exist .................................................................... 128 9.14 Check User Home Directory Ownership ........................................................................... 130 9.15 Check for Duplicate UIDs ......................................................................................................... 131 9.16 Check for Duplicate GIDs ......................................................................................................... 132 9.17 Check That Reserved UIDs Are Assigned to System Accounts ................................. 132 9.18 Check for Duplicate User Names .......................................................................................... 133 9.19 Check for Duplicate Group Names ....................................................................................... 134 9.20 Check for Presence of User .netrc Files .............................................................................. 135 9.21 Check for Presence of User .forward Files ........................................................................ 136 9.22 Find World Writable Files ....................................................................................................... 137 9.23 Find SUID/SGID System Executables ................................................................................. 137 9.24 Find Un-owned Files and Directories ................................................................................. 138 9.25 Find Files and Directories with Extended Attributes ................................................... 139 Appendix A: File Backup Script .................................................................................................................. 141 Appendix B: Service Manifest for /lib/svc/method/cis_netconfig.sh ........................................ 142 Appendix C: Additional Security Notes .................................................................................................. 144 SN.1 Enable process accounting at boot time ............................................................................ 144 SN.2 Use full path names in /etc/dfs/dfstab file ...................................................................... 145 SN.3 Restrict access to power management functions .......................................................... 145 SN.4 Restrict access to sys-suspend feature .............................................................................. 146 SN.5 Create symlinks for dangerous files .................................................................................... 147 SN.7 Remove Support for Internet Services (inetd) ............................................................... 148 Appendix D: Application Notes ................................................................................................................... 150 AN.1 Samba: Enable SSH Port Forwarding in Web Admin Tool ......................................... 150 AN.2 Samba: Set Secure Permissions on smb.conf File...................................................... 150 AN.3 Samba: Set Group Ownership of smb.conf File .......................................................... 151 AN.4 Samba: Set Secure Permissions on smbpasswd File ................................................... 152 AN.5 Samba: Set Group Ownership of smbpasswd File ....................................................... 152 AN.6 Samba: Set Secure smb.conf File Options ......................................................................... 153 AN.7 sendmail: Set Secure Logfile Ownership to the root User ....................................... 154 AN.8 sendmail: Set Secure Permissions on Log File ................................................................ 154 Appendix E: References ................................................................................................................................ 156 Appendix F: Change History ........................................................................................................................ 159

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值