Dec 24 2008

debian下面的/etc/network/interfaces配置文件

Category: 技术ssmax @ 17:00:12

今天做wake up on lan,要用到ethtool设置网卡状态,但是系统关机的过程中会重设这个状态,所以放在网卡关闭脚本的最后,就是 interfaces里面的post-down,这里可以执行任何脚本。。

man 5 interfaces

INTERFACES(5) File formats INTERFACES(5)

NAME
/etc/network/interfaces – network interface configuration for ifup and
ifdown

DESCRIPTION
/etc/network/interfaces contains network interface configuration infor‐
mation for the ifup(8) and ifdown(8) commands. This is where you con‐
figure how your system is connected to the network.

Lines starting with ‘#’ are ignored. Note that end-of-line comments are
NOT supported, comments must be on a line of their own.

A line may be extended across multiple lines by making the last charac‐
ter a backslash.

The file consists of zero or more “iface”, “mapping”, “auto” and
“allow-” stanzas. Here is an example.

auto lo eth0
allow-hotplug eth1

iface lo inet loopback

mapping eth0
script /usr/local/sbin/map-scheme
map HOME eth0-home
map WORK eth0-work

iface eth0-home inet static
address 192.168.1.1
netmask 255.255.255.0
up flush-mail

iface eth0-work inet dhcp

iface eth1 inet dhcp

Lines beginning with the word “auto” are used to identify the physical
interfaces to be brought up when ifup is run with the -a option. (This
option is used by the system boot scripts.) Physical interface names
should follow the word “auto” on the same line. There can be multiple
“auto” stanzas. ifup brings the named interfaces up in the order
listed.

Lines beginning with “allow-” are used to identify interfaces that
should be brought up automatically by various subsytems. This may be
done using a command such as “ifup –allow=hotplug eth0 eth1”, which
will only bring up eth0 or eth1 if it is listed in an “allow-hotplug”
line. Note that “allow-auto” and “auto” are synonyms.

Stanzas beginning with the word “mapping” are used to determine how a
logical interface name is chosen for a physical interface that is to be
brought up. The first line of a mapping stanza consists of the word
“mapping” followed by a pattern in shell glob syntax. Each mapping
stanza must contain a script definition. The named script is run with
the physical interface name as its argument and with the contents of
all following “map” lines (without the leading “map”) in the stanza
provided to it on its standard input. The script must print a string on
its standard output before exiting. See /usr/share/doc/ifupdown/exam‐
ples for examples of what the script must print.

Mapping a name consists of searching the remaining mapping patterns and
running the script corresponding to the first match; the script outputs
the name to which the original is mapped.

ifup is normally given a physical interface name as its first
non-option argument. ifup also uses this name as the initial logical
name for the interface unless it is accompanied by a suffix of the
form =LOGICAL, in which case ifup chooses LOGICAL as the initial logi‐
cal name for the interface. It then maps this name, possibly more than
once according to successive mapping specifications, until no further
mappings are possible. If the resulting name is the name of some
defined logical interface then ifup attempts to bring up the physical
interface as that logical interface. Otherwise ifup exits with an
error.

Stanzas defining logical interfaces start with a line consisting of the
word “iface” followed by the name of the logical interface. In simple
configurations without mapping stanzas this name should simply be the
name of the physical interface to which it is to be applied. (The
default mapping script is, in effect, the echo command.) The interface
name is followed by the name of the address family that the interface
uses. This will be “inet” for TCP/IP networking, but there is also
some support for IPX networking (“ipx”), and IPv6 networking (“inet6”).
Following that is the name of the method used to configure the inter‐
face.

Additional options can be given on subsequent lines in the stanza.
Which options are available depends on the family and method, as
described below. Additional options can be made available by other
Debian packages. For example, the wireless-tools package makes avail‐
able a number of options prefixed with “wireless-” which can be used to
configure the interface using iwconfig(8). (See wireless(7) for
details.)

Options are usually indented for clarity (as in the example above) but
are not required to be.

IFACE OPTIONS
The following “command” options are available for every family and
method. Each of these options can be given multiple times in a single
stanza, in which case the commands are executed in the order in which
they appear in the stanza. (You can ensure a command never fails by
suffixing “|| true”.)

pre-up command
Run command before bringing the interface up. If this command
fails then ifup aborts, refraining from marking the interface as
configured, prints an error message, and exits with status 0.
This behavior may change in the future.

up command

post-up command
Run command after bringing the interface up. If this command
fails then ifup aborts, refraining from marking the interface as
configured (even though it has really been configured), prints
an error message, and exits with status 0. This behavior may
change in the future.

down command

pre-down command
Run command before taking the interface down. If this command
fails then ifdown aborts, marks the interface as deconfigured
(even though it has not really been deconfigured), and exits
with status 0. This behavior may change in the future.

post-down command
Run command after taking the interface down. If this command
fails then ifdown aborts, marks the interface as deconfigured,
and exits with status 0. This behavior may change in the
future.

There exists for each of the above mentioned options a directory
/etc/network/if-

All of these commands have access to the following environment vari‐
ables.

IFACE physical name of the interface being processed

LOGICAL
logical name of the interface being processed

ADDRFAM
address family of the interface

METHOD method of the interface (e.g., static)

MODE start if run from ifup, stop if run from ifdown

PHASE as per MODE, but with finer granularity, distinguishing the pre-
up, post-up, pre-down and post-down phases.

VERBOSITY
indicates whether –verbose was used; set to 1 if so, 0 if not.

PATH the command search path: /usr/local/sbin:/usr/local/bin:‐
/usr/sbin:/usr/bin:/sbin:/bin

Additionally, all options given in an interface definition stanza are
exported to the environment in upper case with “IF_” prepended and with
hyphens converted to underscores and non-alphanumeric characters dis‐
carded.

INET ADDRESS FAMILY
This section documents the methods available in the inet address fam‐
ily.

The loopback Method
This method may be used to define the IPv4 loopback interface.

Options

(No options)

The static Method
This method may be used to define ethernet interfaces with statically
allocated IPv4 addresses.

Options

address address
Address (dotted quad) required

netmask netmask
Netmask (dotted quad) required

broadcast broadcast_address
Broadcast address (dotted quad)

network network_address
Network address (dotted quad) required for 2.0.x kernels

metric metric
Routing metric for default gateway (integer)

gateway address
Default gateway (dotted quad)

pointopoint address
Address of other end point (dotted quad). Note the
spelling of “point-to”.

media type
Medium type, driver dependent

hwaddress class address
Hardware Address. class is one of ether, ax25, ARCnet or
netrom. address is dependent on the above choice.

mtu size
MTU size

The manual Method
This method may be used to define interfaces for which no configuration
is done by default. Such interfaces can be configured manually by means
of up and down commands or /etc/network/if-*.d scripts.

Options

(No options)

The dhcp Method
This method may be used to obtain an address via DHCP with any of the
tools: dhclient, pump, udhcpc, dhcpcd. (They have been listed in their
order of precedence.) If you have a complicated DHCP setup you should
note that some of these clients use their own configuration files and
do not obtain their configuration information via ifup.

Options

hostname hostname
Hostname to be requested (pump, dhcpcd, udhcpc)

leasehours leasehours
Preferred lease time in hours (pump)

leasetime leasetime
Preferred lease time in seconds (dhcpcd)

vendor vendor
Vendor class identifier (dhcpcd)

client client
Client identifier (dhcpcd, udhcpc)

hwaddress class address
Hardware Address. class is one of ether, ax25, ARCnet or
netrom. address is dependent on this choice.

The bootp Method
This method may be used to obtain an address via bootp.

Options

bootfile file
Tell the server to use file as the bootfile.

server address
Use the IP address address to communicate with the
server.

hwaddr addr
Use addr as the hardware address instead of whatever it
really is.

The ppp Method
This method uses pon/poff to configure a PPP interface. See those com‐
mands for details.

Options

provider name
Use name as the provider (from /etc/ppp/peers).

The wvdial Method
This method uses wvdial to configure a PPP interface. See that command
for more details.

Options

provider name
Use name as the provider (from /etc/ppp/peers).

IPX ADDRESS FAMILY
This section documents the methods available in the ipx address family.

The static Method
This method may be used to setup an IPX interface. It requires the
ipx_interface command.

Options

frame type
type of ethernet frames to use (e.g. 802.2)

netnum id
Network number

The dynamic Method
This method may be used to setup an IPX interface dynamically.

Options

frame type
type of ethernet frames to use (e.g. 802.2)

INET6 ADDRESS FAMILY
This section documents the methods available in the inet6 address fam‐
ily.

The loopback Method
This method may be used to define the IPv6 loopback interface.

Options

(No options)

The static Method
This method may be used to define interfaces with statically assigned
IPv6 addresses.

Options

address address
Address (colon delimited) required

netmask mask
Netmask (number of bits, eg 64) required

gateway address
Default gateway (colon delimited)

media type
Medium type, driver dependent

hwaddress class address
Hardware Address. class is one of ether, ax25, ARCnet or
netrom. address is dependent on this choice.

mtu size
MTU size

The manual Method
This method may be used to define interfaces for which no configuration
is done by default. Such interfaces can be configured manually by means
of up and down commands or /etc/network/if-*.d scripts.

Options

(No options)

The v4tunnel Method
This method may be used to setup an IPv6-over-IPv4 tunnel. It requires
the ip command from the iproute package.

Options

address address
Address (colon delimited)

netmask mask
Netmask (number of bits, eg 64)

endpoint address
Address of other tunnel endpoint (IPv4 dotted quad)
required

local address
Address of the local endpoint (IPv4 dotted quad)

gateway address
Default gateway (colon delimited)

ttl time
TTL setting

KNOWN BUGS/LIMITATIONS
The ifup and ifdown programs work with so-called “physical” interface
names. These names are assigned to hardware by the kernel. Unfortu‐
nately it can happen that the kernel assigns different physical inter‐
face names to the same hardware at different times; for example, what
was called “eth0” last time you booted is now called “eth1” and vice
versa. This creates a problem if you want to configure the interfaces
appropriately. A way to deal with this problem is to use mapping
scripts that choose logical interface names according to the properties
of the interface hardware. See the get-mac-address.sh script in the
examples directory for an example of such a mapping script. See also
Debian bug #101728.

It is not currently possible to divide up /etc/network/interfaces into
multiple files. A feature that would make this possible is some sort
of inclusion directive. No such feature exists in the current ifupdown
program. For more information see Debian bug #159884.

AUTHOR
The ifupdown suite was written by Anthony Towns . This manpage was contributed by Joey Hess
.

SEE ALSO
ifup(8), iwconfig(8), run-parts(8).

For advice on configuring this package read the Network Configuration
chapter of the Debian Reference manual, available at
http://www.debian.org/doc/manuals/reference/ch-gateway.en.html or in
the debian-reference-en package.

Examples of how to set up interfaces can be found in
/usr/share/doc/ifupdown/examples/network-interfaces.

ifupdown 5 April 2004 INTERFACES(5)


Dec 23 2008

substring返回类型在mysql驱动 3.x 和 5.x中的区别

Category: 技术ssmax @ 17:16:52

tnnd,有人竟然用jdbcType来决定mysql查询返回的对象类型。。。但是mysql驱动也在3.x -> 5.x 这个升级过程中改变了一点,造成jdbcType来判断就有问题了。。。

ResultSet rs = stmt.executeQuery(“select substring(now(),12,2) as gtime;”);
ResultSetMetaData rsmd = rs.getMetaData();
for(int i=1; i<=rsmd.getColumnCount(); i++) { System.out.print(rsmd.getColumnName(i)); System.out.print("::"); System.out.print(rsmd.getColumnType(i)); System.out.print("::"); System.out.print(rsmd.getColumnTypeName(i)); System.out.print("::"); System.out.println(); } 这样子,在3.x的驱动里面,会认为: gtime::12::VARCHAR 但是在 5.x的驱动里面,就会认为这个是: gtime::-3::VARBINARY jdbcType判断有有问题了,很无奈啊。。。虽然有办法,但是要改代码, select cast(substring(now(),12,2) as CHAR(2)) as gtime 这样子就可以了,但是效率肯定有点影响,懒得改了,只有升级到mysql 3.1的最新版算了,不用5.x了


Dec 22 2008

传真的几种开源实现

Category: 乱up当秘笈ssmax @ 17:07:48

比较好的貌似就是 HylaFAX 了
还有一个与Asterisk配合的SpanDSP
还有一个 Eicon/ Dialogic ,都不知道是什么东东来的,看来要一个个研究了
如果HylaFAX 直接支持E1的卡,那就貌似很简单了,懒得去搞Asterisk的配置。。。


Dec 19 2008

ipv6的一点笔记

Category: 技术ssmax @ 16:03:56

昨天帮别人搞ipv6的代理服务器,要求是内网ipv6的主机能访问,但是出去的时候要是ipv4的,其实就是一个只有ipv6的内网想正常访问现在的ipv4的系统了。
squid 3.1开始就集成了ipv6的代码,而且还是在这两种协议中切换,如果域名有AAAA解释的就用ipv6,只有A的就用ipv4了,哈哈,本来是十分简单的东西,但是自己对ipv6并不是太熟悉,所以还是搞了半天。。。

首先就是ipv6的格式了,ifconfig 一般就可以看到
inet6 addr: fe80::212:3fff:fe24:f258/64 Scope:Link

这个inet6就是默认配置上去的ipv6地址了,但是没有路由,所以ipv6只能从本机访问了。
ipv6一般就是6段,每段是4个十六进制数
而缩略符号可以代表任意多个0000段,但是在一个地址里面只能出现一次
比如 fe80::212:3fff:fe24:f258 就是 fe80:0000:212:3fff:fe24:f258

而本机地址 ::1 就是 0000:0000:0000:0000:0000:1

ipv6这东西,由于规则不同,基本就和ipv4不兼容,各个软件都有自己一套转换方法,但是实际上的时候还是自己定义路由的,没有什么全球性的网络,所以还是和当前的ipv4系统是完全独立出来了。

一些基本命令在ipv6下面的使用
比如ping命令,ipv6下面就有个ping6的命令
但是这个命令一定要加上指定的网卡端口,否则就会出错。。。
ping6 -I eth0 fe80::212:3fff:fe24:f258
PING fe80::212:3fff:fe24:f258(fe80::212:3fff:fe24:f258) from fe80::212:3fff:fe24:f258 eth0: 56 data bytes
64 bytes from fe80::212:3fff:fe24:f258: icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from fe80::212:3fff:fe24:f258: icmp_seq=2 ttl=64 time=0.019 ms

另外一个有用的命令就是telnet了
比如要连接3128端口
telnet -6 fe80::212:3fff:fe24:f258%eth0 80

而这里的%eth0 也是制定网卡设备了,和ping一样的问题。


Dec 18 2008

http 代理的两种模式

Category: 技术ssmax @ 17:38:00

今天帮别人做代理,用squid来做,以前一直都是用来做反向代理,其实正向代理设置也基本一样。。。

代理有两种模式,一种直接就是http代理,另外一种就是CONNECT 代理
第一种方式:
发包的方式是改变http的GET头:

浏览器的请求包模式应该是
GET http://www.163.com/ HTTP/1.1
Accept: */*
Proxy-Connection: Keep-Alive
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MAXTHON 2.0)
Host: www.163.com
Pragma: no-cache

而第二种模式,是可以建立TCP连接的,当初是为了ssl而建立的。
发包的过程是:

先发送:
CONNECT www.163.com:80 HTTP/1.1

然后代理服务器收到这个包之后,就会去和www.163.com 80建立连接

成功的话会返回:
HTTP/1.0 200 Connection established

然后客户端再发送正常的http请求:
GET / HTTP/1.1
Accept: */*
Proxy-Connection: Keep-Alive
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MAXTHON 2.0)
Host: www.163.com
Pragma: no-cache

就会拿到正常的结果了


Dec 17 2008

显卡啊显卡

Category: 乱up当秘笈ssmax @ 10:20:28

我的GTX280终于又降价了,淘宝上面只要1900就可以拿下了,应该是下一代又快要出来了吧,等大规模铺货之后就要出手啦,哈哈,要不就浪费了我的750w电源了。


Dec 12 2008

核高基

Category: 乱up当秘笈ssmax @ 16:27:10

核心电子器件、高端通用芯片及基础软件产品 的简写,我还以为是造核弹呢,tmd,中午突然间说要去帮副总开会,什么东东都不知道。临时准备一个小时,那种垃圾项目都可以申请1yi经费。。。到场的全部不是大学院长就是市领导,还有就是xx企业的董事长,这种级别的会议还要发言,完全不是我这个层次去发言了,硬着头皮讲了点概要,听了点情况,然后汇报了一下,逃回来了,我只关心偶的taxi费能不能报销。。。


Dec 11 2008

NFS12

Category: 乱up当秘笈ssmax @ 21:27:19

画面还算不错,但是不知道为啥,现在的游戏对CPU频率要求太高了,反而对显卡要求不是那么高了,NFS12是如此,真三国无双5的PC版本也是如此,那GPU有多强大都无用。。。

NFS12更恶心就是用3byte来存储整型值,一条CPU汇编指令拆成3条运算,就整数运算相当于消耗多2倍了,还不算其它的没有做优化的了,晕晕,呵呵。


Dec 10 2008

linux 下面看文件被哪个进程打开了

Category: 乱up当秘笈ssmax @ 13:06:56

Usage: fuser [ -a | -s | -c ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME…
             [ – ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME…
       fuser -l
       fuser -V
Show which processes use the named files, sockets, or filesystems.

    -a        display unused files too
    -c        mounted FS
    -f        silently ignored (for POSIX compatibility)
    -i        ask before killing (ignored without -k)
    -k        kill processes accessing the named file
    -l        list available signal names
    -m        show all processes using the named filesystems
    -n SPACE  search in this name space (file, udp, or tcp)
    -s        silent operation
    -SIGNAL   send this signal instead of SIGKILL
    -u        display user IDs
    -v        verbose output
    -V        display version information
    -4        search IPv4 sockets only
    -6        search IPv6 sockets only
    –         reset options

  udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

如果windows下面有这样子的工具该多好啊。。。。找一下看看有没有先


Dec 09 2008

从netstat中统计ip连接数

Category: 技术ssmax @ 14:21:23

看看是不是有人攻击了,不过一般都看不出什么东东来的了

 

netstat -n | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort |uniq -c|sort -n


Next Page »