linux网卡是否连接网线、判断网络问题

linux网卡是否连接网线、判断网络问题

作者:myadmin |  时间:2014-07-09 |  浏览:6021 |  0 条评论

linux网卡是否连接网线、判断网络问题

linux网卡是否连接网线,对于配置多网卡服务器还是很有帮助的。

其实,linux连网问题的排查完全可以参考windows下的解决方案

首先,网卡要up(网卡驱动要启动,否则怎么设置都白搭);然后判断是否插上网线。

满足以上两点后,设置一下ip等参数,重启一下网卡(windows不用重启网卡)。至此一般的网络都解决了。

下面我们逐一的说说每个步骤

1、网卡up,启动网卡驱动

法一:

[root@localhost ~]# ifconfig em2 up

法二:

[root@localhost ~]# ifup em2
Determining if ip address 192.168.1.147 is already in use for device em2...
[root@localhost ~]# 

相对于ifconfig ethX up 我更倾向于 ifup ethX。但是有一点要说明,那就是 ifup 与 ifdown 是以 /etc/sysconfig/network-scripts/ifcfg-ethX 的档案来进行启动的!所以 ifcfg-eth0 必须存在才能使用 ifup

下面检测一下em2网卡是否启动成功了

[root@localhost ~]# ifconfig -a
em1       Link encap:Ethernet  HWaddr 00:A0:D1:EB:69:74  
          inet addr:183.*.*.*  Bcast:183.*.*.* Mask:255.255.255.224
          inet6 addr: fe80::2a0:d1ff:feeb:6974/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13031 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7863 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1757497 (1.6 MiB)  TX bytes:7508235 (7.1 MiB)
          Memory:fbde0000-fbe00000 

em2       Link encap:Ethernet  HWaddr 00:A0:D1:EB:69:75  
          inet addr:192.168.1.148  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2a0:d1ff:feeb:6975/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7484 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1248463 (1.1 MiB)  TX bytes:552 (552.0 b)
          Memory:fbd60000-fbd80000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3444 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3444 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:339405 (331.4 KiB)  TX bytes:339405 (331.4 KiB)

[root@localhost ~]# 
通过 UP BROADCAST RUNNING MULTICAST  可以看到em2网卡已经up了(内网我已经配置成功了),由此可见em2启动成功了。

2、检测网卡是否连接网线

法一、

[root@localhost ~]# mii-tool em2
em2: negotiated 100baseTx-FD, link ok

如果要查看详细信息,可以这样

[root@localhost ~]# mii-tool -v em2
em2: negotiated 100baseTx-FD, link ok
  product info: vendor 00:aa:00, model 57 rev 1
  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
[root@localhost ~]# 

以上内容中显示 link ok  说明已经连接网线了。

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

法二、

[root@localhost ~]# ethtool em2
Settings for em2:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: Symmetric
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: Symmetric
	Advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 1
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: Unknown
	Supports Wake-on: pumbg
	Wake-on: g
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes
[root@localhost ~]# 

最后一句 Link detected:yes 说明em2网卡已经连接网线了。

法三、

[root@localhost ~]# /etc/init.d/network status
Configured devices:
lo em1 em2 em2_bak
Currently active devices:
lo em1 em2

以上是通过查看 network 服务的状态,查看网卡的状态。当然我们也可以查看服务器上所有服务的状态来查看了

[root@localhost ~]# service --status-all
auditd (pid  1277) is running...
crond (pid  1483) is running...
htcacheclean is stopped
httpd (pid  1505) is running...
ip6tables: Firewall is not running.
iptables: Firewall is not running.
lvmetad is stopped
mdmonitor (pid  1310) is running...
messagebus (pid  1321) is running...
mongod (pid 1462) is running...
netconsole module not loaded
Configured devices:
lo em1 em2 em2_bak
Currently active devices:
lo em1 em2
master (pid  1446) is running...
rdisc is stopped
restorecond is stopped
rsyslogd (pid  1293) is running...
sandbox is stopped
saslauthd is stopped
openssh-daemon (pid  1369) is running...
[root@localhost ~]# 

以上显示的更明确了,lo em1 和em2 网络是联通的。

法四、

[root@localhost ~]# ifconfig -a
em1       Link encap:Ethernet  HWaddr 00:A0:D1:EB:69:74  
          inet addr:183.*.*.*  Bcast:183.*.*.* Mask:255.255.255.224
          inet6 addr: fe80::2a0:d1ff:feeb:6974/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13031 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7863 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1757497 (1.6 MiB)  TX bytes:7508235 (7.1 MiB)
          Memory:fbde0000-fbe00000 

em2       Link encap:Ethernet  HWaddr 00:A0:D1:EB:69:75  
          inet addr:192.168.1.148  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2a0:d1ff:feeb:6975/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7484 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1248463 (1.1 MiB)  TX bytes:552 (552.0 b)
          Memory:fbd60000-fbd80000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3444 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3444 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:339405 (331.4 KiB)  TX bytes:339405 (331.4 KiB)

[root@localhost ~]# 

UP BROADCAST RUNNING MULTICAST  这句说明 em2 网卡已经up 并且是在 runing 状态了。

法五、

[root@localhost ~]# lspci
-bash: lspci: command not found
[root@localhost ~]# 

由于我的服务器没有安装 lspci 命令对应的包,所以这里就不掩饰了。有兴趣的鞋童可以自己研究一下。

3、配置网卡

[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-em2

DEVICE="em2"
BOOTPROTO="static"
IPADDR="192.168.1.148"
NETMASK="255.255.255.0"
ONBOOT="yes"
NM_CONTROLLED=yes

保存退出

4、重启网卡

[root@localhost network-scripts]# ifdown em2
[root@localhost network-scripts]# ifup em2
Determining if ip address 192.168.1.148 is already in use for device em2...
[root@localhost network-scripts]# 

5、测试网卡是否配置成功

[root@localhost network-scripts]# ping -c 4 192.168.1.147
PING 192.168.1.147 (192.168.1.147) 56(84) bytes of data.
64 bytes from 192.168.1.147: icmp_seq=1 ttl=64 time=0.229 ms
64 bytes from 192.168.1.147: icmp_seq=2 ttl=64 time=0.265 ms
64 bytes from 192.168.1.147: icmp_seq=3 ttl=64 time=0.239 ms
64 bytes from 192.168.1.147: icmp_seq=4 ttl=64 time=0.249 ms

--- 192.168.1.147 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.229/0.245/0.265/0.020 ms
[root@localhost network-scripts]# 

哈哈,网卡配置成功!

linux网卡是否连接网线、判断网络问题

希望对各位小伙伴有所帮助哈!

相关推荐
更多

发表评论