Ubuntu 16.04 以太网帮助

Ubuntu 16.04 以太网帮助

我最近安装了 Ubuntu 16.04(服务器)。但在路由器上将其连接到互联网时遇到了问题。

ifconfig -a

enp8s0   Link encap:Ethernet  HWaddr **:**:**:**:**:**
         inet addr:192.168.1.7  Bcast:192.168.1.255 Mask:255.255.255.0
         UP 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)
         Interrupt:19

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:65536  Metric:1
         RX packets:196 errors:0 dropped:0 overruns:0 frame:0
         TX packets:196 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1
         RX bytes:15016 (15.0 KB)  TX bytes:15016 (15.0 KB)

至于我什么时候ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.1.7 icmp_seq=1 Destination Host Unreachable

最后但同样重要的是/etc/network/interfaces

source /etc/network/interfaces.d/*

auto lo enp8s0
iface lo inet loopback

auto enp8s0
iface enp8s0 inet static
address 192.168.1.7
netmask 255.255.255.0
gateway 192.168.1.1

编辑: route -n

Kernel IP routing table
Destination     Gateway       Genmask             Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1   0.0.0.0             UG    0      0        0 enp8s0
192.168.1.0     0.0.0.0       255.255.255.0       U     0      0        0 enp8s0

ip route show

default via 192.168.1.1 dev enp8s0 onlink linkdown
192.168.1.0/24 dev enp8s0  proto kernel  scope link  src 192.168.1.7 linkdown

networking.service

networking.service - Raise network interfaces
Active: active (exited) since Mon 2016-05-02 21:00:58 EDT; 10min ago

(如果您需要更多 networking.service,请评论说明)

ethtool enp8s0

Supported ports: [ TP ]
Supported link modes:   10baseT/Half 10baseT/Full
                        100baseT/Half 100baseT/Full
                        100baseT/Half 100baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
                        100baseT/Half 100baseT/Full
                        1000baseT/Half 1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Speed: Unknown!
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: g
Wake-on: g
Current message level: 0x000000ff (255)
                       drv probe link timer ifdown ifup rx_err tx_err
Link detected: no

ethtool -i enp8s0

driver: tg3
version: 3.137
firmware-version: sb
expansion-rom-version:
bus-info: 0000:08:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no

ip neigh show

192.168.1.1 dev enp8s0  INCOMPLETE

请详细回答,谢谢!:)

答案1

这仅仅是接线故障而已。

对不起大家!

答案2

Ping 8.8.8.8 是 ICMP,不涉及 DNS(但您仍然需要正确设置它 ;-)

“目标主机无法访问”,这是ICMP 控制消息类型 3 代码 1,很可能没有到达目标主机的路由。

所以第一件事就是检查你的路由表

route -n
ip route show

获取输出。

首先尝试 ping 你的网关,看看它是否能正常工作。

检查状态networking.service

systemctl status networking.service

顺便说一句:iptables可能还没有发挥作用,但如果您也可以发布输出,那就太好了iptables-save

更新

根据 ethtool 输出,存在第 2 层问题。

Speed: Unknown!
Duplex: Unknown! (255)

需要指出的几点

  1. NIC 应该支持 1000Mbps,但已设置为 100Mbps(您这样做了吗?)

  2. 交换机/路由器宣称速度为 1000Mbps

  3. 双方都开启自动协商功能

    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            100baseT/Half 100baseT/Full
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Half 1000baseT/Full
    

尝试通过ethtool -s <inferface> speed 1000 duplex full autoneg onifconfig down/ifconfig up接口将 NIC 速度设置为 1000Mbps,然后ethtool <interface>再次检查速度和Link detected值。

相关内容