您的位置:首页 > 运维架构 > Linux

查看Linux下网卡状态与是否连接

2013-06-20 11:51 337 查看
1) 通过mii-tool指令

(貌似也可以通过/proc/sys/net/ipv4/conf/来查看)

[root@localhost root]# mii-tool

eth0: negotiated 100baseTx-FD, link ok

eth1: no link



[root@localhost root]# mii-tool -v

eth0: negotiated 100baseTx-FD, link ok

product info: vendor 00:50:43, model 2 rev 3

basic mode: autonegotiation enabled

basic status: autonegotiation complete, link ok

capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control

link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

eth1: no link

product info: vendor 00:50:43, model 2 rev 3

basic mode: autonegotiation enabled

basic status: no link

capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control



[root@localhost root]# mii-tool -w

21:20:33 eth0: negotiated 100baseTx-FD, link ok

21:20:33 eth1: no link

//mii-tool主要是用于配置网卡工作模式的指令,同时也可以进行查询、监控等工作!

2)

[root@localhost /]# /etc/init.d/network status

Configured devices:

lo eth0 eth1

Currently active devices:

lo eth0

等同于

[root@localhost root]# service --status-all

............

............

Configured devices:

lo eth0 eth1

Currently active devices:

lo eth0

............

............

3)ifconfig -a

[root@localhost /]# ifconfig -a

eth0 Link encap:Ethernet HWaddr 00:09:6B:09:08:FC

inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0

inet6 addr: fe80::209:6bff:fe09:8fc/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:106732953 errors:0 dropped:0 overruns:0 frame:0

TX packets:104379788 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:2351331877 (2.1 GiB) TX bytes:391707945 (373.5 MiB)

Base address:0x2500 Memory:fbfe0000-fc000000

eth1 Link encap:Ethernet HWaddr 00:09:6B:09:08:FD

BROADCAST MULTICAST MTU:1500 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Base address:0x2540 Memory:fbfc0000-fbfe0000

4)ethtool

ethtool eth0

Settings for eth0:

Supported ports: [ MII ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Advertised auto-negotiation: Yes

Speed: 100Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 1

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: g

Wake-on: d

Current message level: 0x000000ff (255)

Link detected: yes

ethtool eth1

Settings for eth1:

Supported ports: [ MII ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Advertised auto-negotiation: Yes

Speed: Unknown! (0)

Duplex: Half

Port: Twisted Pair

PHYAD: 1

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: g

Wake-on: d

Current message level: 0x000000ff (255)

Link detected: no

从上面可以看出eth0 处于连接状态,eth1没有连接

二. 查看网卡的配置

一般在linux下查看网络配置可以使用ifconfig命令,可以显示当前网卡的基本配置信息。

终端输入ifconfig 会出现一下内容:

eth0

Link encap:Ethernet HWaddr 00:0C:29:0C:4B:0F

inet addr:192.168.37.128 Bcast:192.168.37.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:33 errors:0 dropped:0 overruns:0 frame:0

TX packets:17 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:2823 (2.7 Kb)

TX bytes:2722 (2.6 Kb)

Interrupt:10 Base address:0x1080

他们分别表示:

Eth0:网络接口

link encap:网络类型

HWaddr:网卡物理地址

Inet addr :IP地址

Bcast:广播地址

Mask:子网掩码

UP:正在使用的网络接口

RX packets,TX packets接收和传输的数据包个数

RX byte,TX byte表示接搜和传输的具体数目

Interrupt:终端信息

Base address:内存地址

三. 网卡配置文件

如果希望每次启动linux时,都能为你的网卡配置正确的网络地址,可以采用下列两种方法:

1. 每次开机后,使用ifconfig手动重新设置网卡的配置;

2. 在开机流程中,将网络配置的设置保存在某些RC Script中。

第一种方式麻烦,第二种方式涉及到在哪个RC Script中配置网卡是比较适当的?

Linux启动过程中会执行以下三个RC Script。

1. /etc/rc.d/init.d/rc.sysinit;

2. /etc/rc.d/init.d/rc;

3. /etc/rc.d/init.d/rc.local

为了维护Linux的稳定性,建议不要修改前两项。但是,用ifconfig配置第三个RC Script的话,导致严重的问题:由于最后执行这个程序,在其执行之前,可能已经执行了数十项网络服务。因此,会造成一堆网络服务因为网卡尚未启动而无法顺利的启动。

四、网卡配置文件

解决上述问题的方法:每一个网络介质都对应一个配置文件,超级用户可以通过这些配置文件来配置网卡。

网卡配置文件存放在 /etc/sysconfig/network-scripts/目录中;

/etc/sysconfig/network-scripts/ifcfg-interface-name

设置文件ifcfg-interface-name包含了初始化接口所需的大部分周详信息。其中interface-name将根据网卡的类型和排序而不同,一般其名字为eth0、eth1、ppp0等,其中eth表示以太(eth0)类型网卡,0表示第一块网卡,1表示第二块网卡,而ppp0则表示第一个point-to-poirt protocol网络接口。在ifcfg文件中定义的各项目取决于接口类型。

下面的值较问常见:

》DEVICE=name ,其中,name是物理设备名。

》IPADDR=addr,其中,addr是IP地址。

》NETMASK=mask,其中,mask是网络掩码值。

》NETWORK=addr,其中addr是网络地址。

》BROADCAST=addr,其中,addr是广播地址。

》GATEWAY=addr,其中addr是网关地址。

》ONBOOT=answer,其中,answer是yes(引导时激活设备)或no(引导时不激活设备)

》USERCTL=answer,其中,answer是yes(非root用户能控制该设备)或no

》BOOTPROTO=proto,其中,proto取下列值之一:none,引导时不使用协议;static静态分配地址;bootp,使用BOOTP协议,或dhcp,使用DHCP协议。

(2)根据上述各参数的意义,设定linpcl.lintec.edu.cn机器的设置文件如下:

[root@linpcl root]#cat /etc/sysconfig/networking/devices/ifcfg-rth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.0.2

NETMASK=255.255.255.0

GATEWAY=192.168.0.1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: