Submitted by admin on 2011, July 9, 10:05 PM
Name
tcpshow - decode a tcpdump savefile
Synopsis
tcpshow [ -b ] [ -sb ] [ -w width ] [ -nolink ] [ -noip ]
- [ -nodata ] [ -data ] [ -track ] [ -terse ]
- [ -cooked ] [ -pp ] [ -s ] [ -h ]
- [ expression ]
Description
tcpshow reads a tcpdump(1) savefile and provides a reasonably complete decode of Ethernet, IP, ICMP, UDP and TCP headers, in packets that match the boolean expression. The data belonging to these packets is displayed in ASCII.
Currently, protocol data is not decoded. This is not considered a serious problem for applications that use ASCII data streams.
Also, IP and TCP options are not decoded.
The input file must be in the format produced by tcpdump -enx. This file can be generated from
1. a prior run of tcpdump -w file
2. a live run of tcpdump (without -w)
3. any other program that produces a correctly formatted
trace
See under EXAMPLES for each of these different methods, plus a description of the format the input file needs to be in.
Except when -cooked is used, tcpdump(1) is required to be on your PATH, to process the raw savefile.
Options
The following options can be used in just about any sane combination.
- -b
break long lines so they don't wrap
- This produces a neater, more readable display of the application data. The default width is 60 columns. See the -w flag for how to change this default.
- -sb
show line breaks
- When -b is used, it may be useful to see exactly where tcpshow wrapped each line, in its display of application data. This option causes the string ''<break>'' to be displayed at the end of each wrapped line. (Lines which were not wrapped, but terminated before the page width, are not so marked.)
- -w width
- set pagewidth to width columns
- This determines where tcpshow will fold long lines, when the -b switch is used.
- -nolink
- don't decode the link header
- The data link header (Ethernet header) is not decoded and displayed.
- -noip
don't decode the IP header
- The IP header is not decoded and displayed.
- -nodata
- don't show the data
- The protocol data is not displayed (a count of data bytes is shown).
- -data
display only the data
- The data, plus a minimal decode of the IP and transport/ICMP headers, is displayed.
- -track
track TCP sequence numbers
- An additional field is produced in the output which shows the TCP acknowledgement number which this side of the connection should receive once the current packet has been received by its peer.
- -terse
show the header decode in compact format
- Without this option, the display of the decoded header is verbose, occupying a lot of display-space real-estate. With this option, the decoded header information is much more compact and terse. Once you're familiar with the meanings of the header fields, you'll probably always use this option. (Maybe this should be the default, with a -verbose flag to get long-winded header decodes?)
- -cooked
- don't run tcpdump(1) to pre-process the input
- If the input file is already in the expected format, this option must be used. See EXAMPLES below of where this flag is appropriate.
- -pp
point-to-point link
- If the input file was collected from data travelling over a point-to-point link (one which doesn't make an Ethernet header available), this option needs to be used.
- -s
also display a hex dump of spurious data at packet-end
- For a reason unknown to the author, tcpdump(1) output sometimes contains data at the end of packets which don't belong to those packets. This spurious data is suppressed from the output, except when this option is used.
- -h
display a help summary
- This list of options is displayed, with one-liner descriptions.
- expression
- filter the input file using a tcpdump(1) expression
- If the -cooked option is not used, then tcpdump(1) is required to be on your PATH. It is used to read the raw savefile, producing output in the format tcpshow expects. The expression should be a valid tcpdump(1) expression. It is not parsed or interpreted by tcpshow, but passed on to tcpdump(1) for its consumption.
Examples
In the following examples, where tcpdump(1) is used, the flag -s 1518 is used to be sure of saving the complete Ethernet frame.
Also, where tcpdump(1) expressions are used, these could equally have been given to tcpdump(1) directly, if it was known at this time what data you're interested in.
Capture a raw savefile and decode it later.
- # tcpdump -s 1518 -w savefile
# tcpshow < savefile - Decode the data as quickly as tcpdump(1) gives it to us.
- # tcpdump -s 1518 -lenx | tcpshow
- Display headers only.
- # tcpshow -nodata < savefile
- Display data only (minimal header decode).
- # tcpshow -data
- Display a decode of Telnet traffic only, omitting the link and IP headers.
- # tcpdump -s 1518 -w savefile
# tcpshow -nolink -noip tcp port telnet < savefile - Give a compact display of the TCP headers, and a full display of the data, for all packets going into or coming from the host "sam" -- this host is on a LAN accessible through a PPP link.
- # tcpdump -i ppp0 -s 1518 -w savefile
# tcpshow -pp -terse host sam < savefile - Show all SMTP mail transfers, omitting the headers and wrapping the message bodies to make it easy to read them (you're not supposed to do this).
- # tcpdump -s 1518 -w savefile
# tcpshow -b -w 40 -data port smtp < savefile - To display a decode of data not captured via tcpdump(1), you would typically use the application that captured the trace to dump that trace into a file in ASCII-hex format. You feed that file into a Perl/sh/awk script (that you write), which produces a file in the format tcpshow expects. Such scripts are easy to write. For example, if your application is "capture" and your script is "convert", then tcpshow might be used as follows.
- # capture -hexoutput | convert | tcpshow
- A loose definition of the format tcpshow expects is: the 1st line of each packet must begin in column 1. All other lines must begin with a TAB. The hex bytes can be separated from each other by any amount of whitespace, including none.
When using -cooked, the first field should be the time the packet was captured (or a string like "no-time-recorded" if the time isn't available). The remaining fields should be the bytes of the IP datagram.
When -cooked is not used, the first field should be as above, with the next three fields being the Ethernet source address, the Ethernet destination address and the DIX Ethernet Type field.
Files
tcpshow reads from standard input and writes to standard output.
See Also
tcpdump(1), nit(4P), bpf(4)
linux | 评论:0
| Trackbacks:0
| 阅读:937
Submitted by admin on 2011, July 8, 1:57 PM
IPIP是在两台主机之间的IP层上建立一条虚拟的通道(没有加密,没有压缩),相当于建立一条VPN.
下面是一个例子:
我们想在两台机器之间建立ipip,它们分别为:Router A 和 Router B. 它们分别都连接到网络上.
Router A:
外网地址是: 192.0.2.34
内网地址是: 192.168.1.1
Router B:
外网地址是: 192.0.2.69
内网地址是: 192.168.1.254
在Router A上执行命令:
ip tunnel add tunnel0 mode ipip remote 192.0.2.69 local 192.0.2.34
ip link set tunnel0 up
ip addr add 192.168.1.1/24 dev tunnel0
在Router B执行命令:
ip tunnel add tunnel0 mode ipip remote 192.0.2.34 local 192.0.2.69
ip link set tunnel0 up
ip addr add 192.168.1.254/24 dev tunnel0Skip to 'testing the tunnel'.
Debian sample setup
Router A
Edit /etc/network/interfaces:
auto tunnel0
iface tunnel0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
pre-up /sbin/ip tunnel add tunnel0 mode ipip remote 192.0.2.69 local 192.0.2.34
post-down /sbin/ip tunnel del tunnel0Then execute
ifup tunnel0.
Router B
Edit /etc/network/interfaces:
auto tunnel0
iface tunnel0 inet static
address 192.168.1.254
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
pre-up /sbin/ip tunnel add tunnel0 mode ipip remote 192.0.2.34 local 192.0.2.69
post-down /sbin/ip tunnel del tunnel0Then execute
ifup tunnel0
Testing your tunnel
After you have configured your tunnel via one of the examples above you should be able to ping the remote end:
Router A
ping 192.168.1.254
Router B
ping 192.168.1.1
Both pings should succeed without problems.
使用你建立的IP tunnel
You can now use your tunnel - just pretend it's a piece of Ethernet between the two computers.
Remember the MTU on the tunnel will be lower than normal because of the extra IP header.
You can setup routing and whatever you like over the tunnel.
If you lose your route to the tunnel endpoint, the tunnel will not work either.
--------------------------------------------------------------------------------
More complex situations
When tunneling between 2 routers, and 1 router has a private network on another interface, routing between the two can be confusing. Here is the network layout:
Router 1
eth0: 1.2.3.4 (public)Router 2
eth0: 4.3.2.1 (public)
eth1: 10.0.0.1In my particular case, Router 1 is an asterisk system on a public network, and Router 2 is a NAT router that is also a gateway for my private 10.0.0.0/24 network. I have multiple SIP phones (which don't work through NAT) on the 10.0.0.0/24 network and I need to establish routes between the 2.
IN THIS ORDER ENTER THESE COMMANDS
Router 1
iptunnel add iptun mode ipip remote 4.3.2.1
ifconfig iptun 10.0.1.1
route add -net 10.0.2.0/24 dev iptunRouter 2
iptunnel add iptun mode ipip remote 1.2.3.4
ifconfig iptun 10.0.2.1
route add -net 10.0.1.0/24 dev iptunRouter 1
route add -net 10.0.0.0/24 dev iptun
route add -net 10.0.0.0/24 gw 10.0.0.1Now from Router 2 you can ping any device on the 10.0.0.0/24 network behind Router 1, and from any device on the 10.0.0.0/24 network, you can ping Router 1 using the address 10.0.1.1
linux | 评论:0
| Trackbacks:0
| 阅读:1402
Submitted by admin on 2011, July 8, 1:56 PM
一.实现
在Linux中,隧道的实现主要基于两个文件new_tunnel.c和ipip.c
同时Linux定义了一种新的协议类型--IPIP(IPPROTO_IPIP),与上面所说封包类型类似。
基本思路
在Linux中IP Tunnel的实现也分为两个部件:封装部件和解封部件,分别司职发送和接收。但这两个部分是在不同的层次以不同的方式实现的。封装部件是在数据链路层以虚设备的方式实现。所有源代码见
/usr/src/linux/drivers/net/new_tunnel.c
为实现封装,Linux实现一个称为tunl的网络设备(类似loopback设备),此设备具有其他网络设备共有的特征,对于使用此设备的上层应用来说,对这些网络设备不加区分,调用及处理方法当然也完全一样。
tunnel_init()和tunnel_xmit()是new_tunnel.c中的两个主要过程。
tunnel_init()初始化与设备tunl相关的device结构。
而tunnel_xmit()在从tunl设备发送数据时被调用,tunl设备作为实现IP隧道技术的封装部分,在此过程中完成对相应的数据报进行封装所需的全部操作,形成IPIP类型的IP包,并重新转发此数据包(ip_forward())。
解码器在IP的上层实现,系统把它作为一个虚的传输层(实际上与传输层毫无关系),具体处理见文件
/usr/src/linux/net/ipv4/ipip.c。
我们知道,每一个IP数据包均交由ip_rcv函数处理,在进行一些必要的判断后,ip_rcv对于发送给本机的数据包将交给上层处理程序。对于IPIP包来说,其处理函数是ipip_rcv(就如TCP包的处理函数是tcp_rcv一样,IP层不加区分)。也就是说,当一个目的地址为本机的封包到达后,ip_rcv函数进行一些基本检查并除去IP头,然后交由ipip_rcv解封。ipip_rcv所做的工作就是去掉封包头,还原数据包,然后把还原后的数据包放入相应的接收队列(netif_rx())。
从以上IP Tunnel实现的思想来看,思路十分清晰,但由于IP Tunnel的特殊性,其实现的层次并不单纯。实际上,它的封装和解封部件不能简单地象上面所说的那样分层。tunl设备虽应算进链路层,但其发送程序中做了更多的工作,如制作IPIP头及新的IP头(这些一般认为是传输层或网络层的工作),调用ip_forward转发新包也不是一个网络设备应当做的事。可以说,tunl借网络设备之名,一把抓干了不少工作,真是‘高效’。而解封部件宏观上看在网络层之上,解出IPIP头,恢复原数据包是它分内的事,但在它解出数据包(即原完整的协议数据包)后,它把这个包放入相应的协议接收队列。这种事可不是一个上层协议干的,这是网络设备中断接收程序的义务。看到了,在这点上,它好象到了数据链路层。
二.协议
1. 点对点隧道协议(PPTP)
PPTP协议允许对IP,IPX或NetBEUI数据流进行加密,然后封装在IP包头中通过企业IP网络或公共互联网络发送。
2. 第2层隧道协议(L2TP)
L2TP协议允许对IP,IPX或NetBEUI数据流进行加密,然后通过支持点对点数据报传递的任意网络发送,如IP,X.25,桢中继或ATM。
3.安全IP(IPSec)隧道模式
IPSec隧道模式允许对IP负载数据进行加密,然后封装在IP包头中通过企业IP网络或公共IP互联网络如Internet发送。
隧道协议
为创建隧道,隧道的客户机和服务器双方必须使用相同的隧道协议。
隧道技术可以分别以第2层或第3层隧道协议为基础。上述分层按照开放系统互联(OSI)的参考模型划分。第2层隧道协议对应OSI模型中的数据链路层,使用桢作为数据交换单位。PPTP,L2TP和L2F(第2层转发)都属于第2层隧道协议,都是将数据封装在点对点协议(PPP)桢中通过互联网络发送。第3层隧道协议对应OSI模型中的网络层,使用包作为数据交换单位。IP overIP以及IPSec隧道模式都属于第3层隧道协议,都是将IP包封装在附加的IP包头中通过IP网络传送。
提供PPTP客户机和PPTP服务器之间的加密通信。PPTP客户机是指运行了该协议的PC机,如启动该协议的Windows95/98;PPTP服务器是指运行该协议的服务器,如启动该协议的WindowsNT服务器。PPTP是PPP协议的一种扩展。它提供了一种在互联网上建立多协议的安全虚拟专用网(VPN)的通信方式。远端用户能够透过任何支持PPTP的ISP访问公司的专用网。
通过PPTP,客户可采用拨号方式接入公用IP网。拨号用户首先按常规方式拨到ISP的接入服务器(NAS),建立PPP连接;在此基础上,用户进行二次拨号建立到PPTP服务器的连接,该连接称为PPTP隧道,实质上是基于IP协议的另一个PPP连接,其中的IP包可以封装多种协议数据,包括TCP/IP、IPX和NetBEUI。PPTP采用了基于RSA公司RC4的数据加密方法,保证了虚拟连接通道的安全。对于直接连到互联网的用户则不需要PPP的拨号连接,可以直接与PPTP服务器建立虚拟通道。PPTP把建立隧道的主动权交给了用户,但用户需要在其PC机上配置PPTP,这样做既增加了用户的工作量,又会给网络带来隐患。另外,PPTP只支持IP作为传输协议。
第2层转发(L2F)
L2F是Cisco公司提出隧道技术,作为一种传输协议L2F支持拨号接入服务器将拨号数据流封装在PPP桢内通过广域网链路传送到L2F服务器(路由器)。L2F服务器把数据包解包之重新注入(inject)网络。与PPTP和L2TP不同,L2F没有确定的客户方。应当注意L2F只在强制隧道中有效。(自愿和强制隧道的介绍参看“隧道类型”)。
第2层隧道协议(L2TP)
L2TP隧道协议是典型的被动式隧道协议,它结合了L2F和PPTP的优点,可以让用户从客户端或访问服务器端发起VPN连接。L2TP是把链路层PPP帧封装在公共网络设施如IP、ATM、帧中继中进行隧道传输的封装协议。
L2TP主要由LAC(L2TP Access Concentrator) 和LNS(L2TP Network Server) 构成,LAC支持客户端的L2TP,用于发起呼叫、接收呼叫和建立隧道;LNS是所有隧道的终点,LNS终止所有的PPP流。在传统的PPP连接中,用户拨号连接的终点是LAC,L2TP使得PPP协议的终点延伸到LNS。
L2TP的好处在于支持多种协议,用户可以保留原有的IPX、Appletalk等协议或公司原有的IP地址。L2TP还解决了多个PPP链路的捆绑问题,PPP链路捆绑要求其成员均指向同一个NAS(Network Access Server),L2TP可以使物理上连接到不同NAS的PPP链路,在逻辑上的终结点为同一个物理设备。L2TP还支持信道认证,并提供了差错和流量控制。
L2TP利用IPsec增强了安全性,支持数据包的认证、加密和密钥管理。L2TP/IPSec因此能为远程用户提供设计精巧并有互操作性的安全隧道连接。这对安全的远程访问和安全的网关之间连接来说,它是一个很好的解决方案。因此,安全的VPN需要同时解决好L2TP和IPSec这两个不同的问题。L2TP协议解决了穿过IP网络的不同用户协议的转换问题;IPSec协议(加密/解密协议)解决了通过公共网络传输信息的保密问题。
IP网上的L2TP使用UDP和一系列的L2TP消息对隧道进行维护。L2TP同样使用UDP将L2TP协议封装的PPP桢通过隧道发送。可以对封装PPP桢中的负载数据进行加密或压缩。 PPTP与L2TP
PPTP和L2TP都使用PPP协议对数据进行封装,然后添加附加包头用于数据在互联网络上的传输。尽管两个协议非常相似,但是仍存在以下几方面的不同:
PPTP要求互联网络为IP网络。L2TP只要求隧道媒介提供面向数据包的点对点的连接。L2TP可以在IP(使用UDP),桢中继永久虚拟电路(PVCs),X.25虚拟电路(VCs)或ATM VCs网络上使用。
PPTP只能在两端点间建立单一隧道。L2TP支持在两端点间使用多隧道。使用L2TP,用户可以针对不同的服务质量创建不同的隧道。
L2TP可以提供包头压缩。当压缩包头时,系统开销(overhead)占用4个字节,而PPTP协议下要占用6个字节。
L2TP可以提供隧道验证,而PPTP则不支持隧道验证。但是当L2TP或PPTP与IPSEC共同使用时,可以由IPSEC提供隧道验证,不需要在第2层协议上验证隧道。
IPSec隧道模式
IPSec在IP层上对数据包进行高强度的安全处理,提供数据源地验证、无连接数据完整性、数据机密性、抗重播和有限业务流机密性等安全服务。各种应用程序可以享用IP层提供的安全服务和密钥管理,而不必设计和实现自己的安全机制,因此减少密钥协商的开销,也降低了产生安全漏洞的可能性。IPSec可连续或递归应用,在路由器、防火墙、主机和通信链路上配置,实现端到端安全、虚拟专用网络(VPN)和安全隧道技术。
IPSEC是第3层的协议标准,支持IP网络上数据的安全传输。本文将在“高级安全”一部分中对IPSEC进行详细的总体介绍,此处仅结合隧道协议讨论IPSEC协议的一个方面。除了对IP数据流的加密机制进行了规定之外,IPSEC还制定了IPoverIP隧道模式的数据包格式,一般被称作IPSEC隧道模式。一个IPSEC隧道由一个隧道客户和隧道服务器组成,两端都配置使用IPSEC隧道技术,采用协商加密机制。
为实现在专用或公共IP网络上的安全传输,IPSEC隧道模式使用的安全方式封装和加密整个IP包。然后对加密的负载再次封装在明文IP包头内通过网络发送到隧道服务器端。隧道服务器对收到的数据报进行处理,在去除明文IP包头,对内容进行解密之后,获的最初的负载IP包。负载IP包在经过正常处理之后被路由到位于目标网络的目的地。
IPSEC隧道模式具有以下功能和局限:
只能支持IP数据流
工作在IP栈(IPstack)的底层,因此,应用程序和高层协议可以继承IPSEC的行为。
由一个安全策略(一整套过滤机制)进行控制。安全策略按照优先级的先后顺序创建可供使用的加密和隧道机制以及验证方式。当需要建立通讯时,双方机器执行相互验证,然后协商使用何种加密方式。此后的所有数据流都将使用双方协商的加密机制进行加密,然后封装在隧道包头内。
linux | 评论:0
| Trackbacks:0
| 阅读:875
Submitted by admin on 2011, July 8, 1:56 PM
在Linux中,隧道的实现主要基于两个文件new_tunnel.c和ipip.c
同时Linux定义了一种新的协议类型--IPIP(IPPROTO_IPIP),与上面所说封包类型类似。
基本思路
在Linux中IP Tunnel的实现也分为两个部件:封装部件和解封部件,分别司职发送和接收。但这两个部分是在不同的层次以不同的方式实现的。封装部件是在数据链路层以虚设备的方式实现。所有源代码见
/usr/src/linux/drivers/net/new_tunnel.c
为实现封装,Linux实现一个称为tunl的网络设备(类似loopback设备),此设备具有其他网络设备共有的特征,对于使用此设备的上层应用来说,对这些网络设备不加区分,调用及处理方法当然也完全一样。
tunnel_init()和tunnel_xmit()是new_tunnel.c中的两个主要过程。
tunnel_init()初始化与设备tunl相关的device结构。
而tunnel_xmit()在从tunl设备发送数据时被调用,tunl设备作为实现IP隧道技术的封装部分,在此过程中完成对相应的数据报进行封装所需的全部操作,形成IPIP类型的IP包,并重新转发此数据包(ip_forward())。
解码器在IP的上层实现,系统把它作为一个虚的传输层(实际上与传输层毫无关系),具体处理见文件
/usr/src/linux/net/ipv4/ipip.c。
我们知道,每一个IP数据包均交由ip_rcv函数处理,在进行一些必要的判断后,ip_rcv对于发送给本机的数据包将交给上层处理程序。对于 IPIP包来说,其处理函数是ipip_rcv(就如TCP包的处理函数是tcp_rcv一样,IP层不加区分)。也就是说,当一个目的地址为本机的封包 到达后,ip_rcv函数进行一些基本检查并除去IP头,然后交由ipip_rcv解封。ipip_rcv所做的工作就是去掉封包头,还原数据包,然后把 还原后的数据包放入相应的接收队列(netif_rx())。
从以上IP Tunnel实现的思想来看,思路十分清晰,但由于IP Tunnel的特殊性,其实现的层次并不单纯。实际上,它的封装和解封部件不能简单地象上面所说的那样分层。tunl设备虽应算进链路层,但其发送程序中 做了更多的工作,如制作IPIP头及新的IP头(这些一般认为是传输层或网络层的工作),调用ip_forward转发新包也不是一个网络设备应当做的 事。可以说,tunl借网络设备之名,一把抓干了不少工作,真是‘高效’。而解封部件宏观上看在网络层之上,解出IPIP头,恢复原数据包是它分内的事, 但在它解出数据包(即原完整的协议数据包)后,它把这个包放入相应的协议接收队列。这种事可不是一个上层协议干的,这是网络设备中断接收程序的义务。看到 了,在这点上,它好象到了数据链路层。
为实现VPN的扩展
实际上Linux只为实现隧道机制提供了一个框架,图二中的封包协议头在Linux中被忽略了,也就是说,封包头只含封包IP头,其后紧跟原IP数据 包。这样的结构用于传输公开数据没有关系,但对于一个VPN来说,安全保密是不可缺少的重要功能。我们希望通过隧道的数据可靠且不可窃取和冒充的,那么, 加密和认证就必不可少。为实现这一构想,设计以下封包协议头:
0 4 8 16 24 31
+-----+-----+-----------+------------------------+
| ver |type | hlen | OldPacketLen |
+-----------------------+------------------------+
| DeviceID | EncapID |
+-----------------------+------------------------+
| Flags | CheckSum |
+------------------------------------------------+
| IPIP Options( If any ) |
+------------------------------------------------+
. | padding |
. .
+------------------------------------------------+
图三、 IPIP头设想图
ver: 版本号,利于扩展
type: 用于建立不同目的的隧道(可能处理上有差别)
OldPacketLen: 进入隧道的原数据包长度
DeviceID: 对数据包进行封装的设备标识
EncapID: 此封包的ID号
Flags: 标志位,共16位,初步定义如下:
0 保留
1 有否加密
2 有否做摘要
3 有否签名
4 保留
5 有否传送消息密钥
6 消息密钥有否加密
7 消息密钥是否需保留
8-15 保留
CheckSum: 头校验
IPIP Options: 用来传送一些必要的数据,比如消息密钥、签名等
格式:
+-------------------------------------+
| 类型 | 长度 | 数据 ... |
+-------------------------------------+
好了,有了这个东西,我们就可以扩展Linux IP Tunnel为我们的VPN服务了。首先,改写new_tunnel.c和ipip.c两个文件,加入对IPIP头的处理。
接着,我们要实现一种密钥的管理和传送机制。
当然,对称密钥是必需的,而对IP数据包加密要使用序列密码。从全体考虑,
我们可以提出建立VPN的逻辑步骤;
1、准备工作:建网安装系统完成配置等等
2、隧道的两端分别向对方发送自己的公开密码和设备号
3、如有必要,产生序列密码,后加密签名传给对方
4、正常通信,----放心,你的数据已经很保险了。
在一个VPN的隧道中,一个封包的格式应如图四所示。
/ +-----------------+
| | 封包IP头 |
封包头 | +-----------------+
| | 封包协议头 |
+-----------------+
/ | |
| | 原协议头 |
| | 及 |
封包数据 | | 原协议数据 |
| . (密文) .
| . .
| | |
+-----------------+
图四. VPN封包结构
你的几种使用方法
事情往往不能两全其美,你在安全强度和通信速度上必须作出选择,(不然你就需要在安全强度和Money的耗费中做选择。)使用这样的协议,根据你的需求不同,你可有不同的使用方法,下面列举一些:
跨Internet的公司多个内部网之间进行通信,保密性并不重要直接使用原框架机制,无任何加密措施这样速度快、效率高,公司也不用申请多个IP地址,方便可行
一般性的商业应用,具有保密要求利用事先产生的序列密码,每次对原数据包加密安全度提高了,是一种十分实用的方法。只要强度足够,一般很难破译速度快密码 不变的方式你认为不够安全你可以自己实现一种密码传送方法,每隔一段时间更换一次密码。其中一些握手关系需要完善,有兴趣的欢迎探讨。如果发展成熟,此法 相信很有前途。
高度机密领域:敬请使用一次一密,并进行每次签名。每次产生新密钥和签名十分费时,在目前我国Internet网络的速度下几乎不可行。但相信有此需要的 部门也能够设法提高其网络带宽,让网络状况适合这种应用。另外,当然还可以就加密强度自身作出选择,比如选择128位,还是512位、1024位
待完善
主要牵涉 到隧道的管理,在封包的传送过程中如果出现错误是十分正常的,当一台路由器检测到错误时,它会发送一个ICMP包给隧道的发送端,但遗憾的是ICMP返回 的数据除了IP头外,只含8个字节的上层协议信息。只凭这个难以对ICMP信息作出反应,因此,在隧道端保留一些状态信息是必须的。这些信息主要包括:
隧道的另一端的可达性
隧道的拥塞状况
隧道的MTU
同时所发送的封包信息也是需要保留的,举例说,当一个路由不可达信息到来时,封包的发送者要能够找出所封装的数据来自何方,并发送相应的ICMP包。
linux | 评论:0
| Trackbacks:0
| 阅读:906
Submitted by admin on 2011, July 7, 6:25 PM
This article is focusing installing and configure MRTG with CPU,Memory and Disk Usage Graphs examples for Debian Ubuntu and Kubuntu Users and may be work for some debian based distributions.
MRTG is Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network links. MRTG generates HTML pages containing PNG images which provide a LIVE visual representation of this traffic.
MRTG Requirements
Apache webserver with perl support
NET-SNMP
GD
Libpng
zlib
If you want to download MRTG you can download from here
Preparing you System for MRTG Instalaltion
First you need to install the required compilers
#apt-get install gcc make g++
Apache 2 Installation with perl support
Follow these instructions to install apache2 with perl support
MRTG Installation
Now we need to install mrtg and snmp
Installing MRTG in Debian, Ubuntu and Kubuntu
#apt-get install mrtg snmpd
The installation will create an mrtg subdirectory where the Apache Web pages reside. On your Debian,ubnutu,kubuntu systems the path of this subdirectory is:
/var/www/mrtg
Now you need to edit the mrtg configuration file to edit the some of the settings
File is located at /etc/mrtg.cfg you need to change the global settings as follows
# Global Settings
RunAsDaemon: yes
EnableIPv6: no
WorkDir: /var/www/mrtg
Options[_]: bits,growright
WriteExpires: Yes
Title[^]: Traffic Analysis for
You will find a crontab running every 5 minutes as user root
# cat /etc/cron.d/mrtg
0-55/5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi
Now we need to assign the snmp community name in snmp configration file /etc/snmp/snmpd.conf
# sec.name source community
# com2sec paranoid default public
com2sec readonly default public
#com2sec readwrite default private
Now you need to restart the snmp service
#/etc/init.d/snmpd restart
The configuration file creating using
#cfgmaker public@localhost > /etc/mrtg.cfg
Creating a configuration file for a device using cfgmaker
#cfgmaker public@192.168.0.1 >> /etc/mrtg.cfg
With the configuration file created correctly there’s only one other thing you have to do and that’s to use the indexmaker utility to create the summary home page. Since you have to re-run this command every time you make certain changes to the /etc/mrtg.cfg configuration file.
Creating index file for the webserver using indexmaker
#indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html
Now you need to reboot your system wait for five minutes or so and then take a look at your summary home page. If your Debian,ubuntu,kubuntu system’s IP address is 192.168.0.1 then you’d type in the following in the address bar of a browser running on a system on the same network:
http://192.168.0.1/mrtg/
Your summary home page should come up with a graph for each target entry in the configuration file. If a graph looks like there’s no data on it, click on it and check the statistics to see if any traffic is being seen. Small amounts of traffic won’t show up on the graphs because we used the Unscaled statement
Some of examples how to monitor cpu , memory , Disk usage
CPU Usage
/etc/mrtg/cpu.cfg
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1+
ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1
RouterUptime[localhost.cpu]: public@127.0.0.1
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]: Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
Memory Usage
/etc/mrtg/mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost
PageTop[localhost.mem]:Free Memory
WorkDir: /var/www/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]: Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes
Memory Monitoring (Total Versus Available Memory)
/etc/mrtg/memfree.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.memory]: memAvailReal.0&memTotalReal.0:public@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: < H1 >Free Memory< /H1 >
MaxBytes[server.memory]: 100000000000
ShortLegend[server.memory]: B
YLegend[server.memory]: Bytes
LegendI[server.memory]: Free
LegendO[server.memory]: Total
Legend1[server.memory]: Free memory, not including swap, in bytes
Legend2[server.memory]: Total memory
Options[server.memory]: gauge,growright,nopercent
kMG[server.memory]: k,M,G,T,P,X
Memory Monitoring (Percentage usage)
/etc/mrtg/mempercent.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: < H1 >Percentage Free Memory< /H1 >
Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:publicy@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@localhost )
options[server.mempercent]: growright,gauge,transparent,nopercent
Unscaled[server.mempercent]: ymwd
MaxBytes[server.mempercent]: 100
YLegend[server.mempercent]: Memory %
ShortLegend[server.mempercent]: Percent
LegendI[server.mempercent]: Free
LegendO[server.mempercent]: Free
Legend1[server.mempercent]: Percentage Free Memory
Legend2[server.mempercent]: Percentage Free Memory
Disk Usage
/etc/mrtg/disk.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.disk]: dskPercent.1&dskPercent.2:public@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: < H1 >Disk Partition Usage /home and /var< /H1 >
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /home
LegendO[server.disk]: /var
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd
Creating jobs for CPU , Memory and Disk Usage
CPU
/etc/cron.mrtg/cpu
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/cpu.cfg
Memory
/etc/cron.mrtg/mem
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mem.cfg
Memory Free
/etc/cron.mrtg/memfree
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/memfree.cfg
Memory Percentage
/etc/cron.mrtg/mempercent
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mempercent.cfg
Disk
/etc/cron.mrtg/disk
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/disk.cfg
Run each script 3 times (disregard the warnings)
/etc/cron.mrtg/cpu
/etc/cron.mrtg/mem
/etc/cron.mrtg/memfree
/etc/cron.mrtg/mempercent
/etc/cron.mrtg/disk
Make the Index Files
#/usr/bin/indexmaker --output=/var/www/mrtg/index.html \
--title=”Memory and CPU Usage ” \
--sort=name \
--enumerate \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/cron.mrtg/memfree \
/etc/cron.mrtg/mempercent \
/etc/cron.mrtg/disk
Make the mrtg.cfg file
#cfgmaker --global “WorkDir: /var/www/mrtg/” \
--global “Options[_]: growright,bits” \
--ifref=ip \
public@localhost > /etc/mrtg/mrtg.conf
Cronjob setup
/bin/cat >> /var/spool/cron/crontabs/root
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null
Now you logon to your web browser http://192.168.0.1/mrtg/ and Now you should see CPU,Memory and Disk Usage graphs.
If you want more documentation about MRTG check here
linux | 评论:0
| Trackbacks:0
| 阅读:880
Submitted by admin on 2011, July 1, 2:13 PM
服务器系统CentOS 5, 网内还有其它设备对外提供服务。
# uname -rvp
2.6.18-238.12.1.el5 #1 SMP Tue May 31 13:22:04 EDT 2011 x86_64
# ethtool -i eth0
driver: bnx2
version: 2.0.8-rh
firmware-version: bc 4.4.1 UMP 1.1.9
bus-info: 0000:03:00.0
---------------
服务器性能足够,通过80端口提供服务,不限量的话流量能跑满eth0,现在我想限速到最高450mbit,以免影响到其它设备的服务,但是限速貌似不是很灵,还是跑到600左右(之后使用iptables 把新连接给REJECT喽)请达人帮忙看看脚本有什么问题没? #!/bin/bash
tc qdisc del dev eth0 root 2>/dev/null
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:1 htb rate 450mbit ceil 450mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 400mbit ceil 400mbit
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 50mbit
tc class add dev eth0 parent 1:1 classid 1:30 htb rate 20mbit ceil 50mbit
tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 80 0xffff flowid 1:10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 22 0xffff flowid 1:30
问题的解决方案:见8楼。
tc -s class ls dev eth0
class htb 1:1 root rate 450000Kbit ceil 450000Kbit burst 57825b cburst 57825b
Sent 410270340209 bytes 188442731 pkt (dropped 0, overlimits 0 requeues 0)
rate 619391Kbit 35404pps backlog 0b 0p requeues 0
lended: 109 borrowed: 0 giants: 151676252
tokens: 835 ctokens: 835
ethtool -K tso off
关闭tso后,貌似正常了吖
see here -> https://bugzilla.redhat.com/show_bug.cgi?id=481546#c32
rpm -ivh http://people.redhat.com/jwilson/el5/269.el5/x86_64/kernel-2.6.18-269.el5.x86_64.rpm http://people.redhat.com/jwilson/el5/269.el5/x86_64/kernel-devel-2.6.18-269.el5.x86_64.rpm && reboot
跑了一下午,目前看起来蛮正常的
转
linux | 评论:0
| Trackbacks:0
| 阅读:1131
Submitted by admin on 2011, June 19, 9:21 AM
查看/修改Linux时区和时间
一、时区
1. 查看当前时区
date -R
2. 修改设置时区
方法(1)
tzselect
方法(2) 仅限于RedHat Linux 和 CentOS
timeconfig
方法(3) 适用于Debian
dpkg-reconfigure tzdata
3. 复制相应的时区文件,替换系统时区文件;或者创建链接文件
cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime
在中国可以使用:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、时间
1、查看时间和日期
date
2、设置时间和日期
将系统日期设定成1996年6月10日的命令
date -s 06/22/96
将系统时间设定成下午1点52分0秒的命令
date -s 13:52:00
3. 将当前时间和日期写入BIOS,避免重启后失效
hwclock -w
三、定时同步时间
* * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1
------
发现用tzselect改的似乎不生效,重起也不行
linux | 评论:0
| Trackbacks:0
| 阅读:1008
Submitted by admin on 2011, June 19, 9:20 AM
安装虚拟机的时候,没太注意时区,装好后发现时区比中国上海的慢了16个小时,寻得一些方法,分享给大家:
时区的配置文件是/etc/sysconfig/clock。用tzselect命令就可以修改这个配置文件,根据命令的提示进行修改就好了。
但是在实际工作中,发现这种方式是不能够使得服务器上的时间设置马上生效的,而且使用ntpdate去同步时间服务器也不能够更改时间。即使你使用了 date命令手工设置了时间的话,如果使用ntpdate去进行时间同步的话,时间又会被改动到原来的错误时区的时间。而生产的机器往往是非常重要的,不能够进行重启等操作。
如果要修改时区并且马上生效,可以更换/etc/localtime 文件来实现。比如修改时区为中国上海,那么就可以使用如下的命令来使得时区的更改生效。
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
然后最好使用下面的命令将更改写入bios。
hwclock
--------------------------------
具体操作:
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@localhost ~]# date
Sat Feb 20 16:04:43 CST 2010
[root@localhost ~]# hwclock
Sat 20 Feb 2010 04:05:12 PM CST -0.474966 seconds
linux | 评论:0
| Trackbacks:0
| 阅读:921