我关闭了 Ubuntu 服务器,但启动时它却无法连接到互联网。它通过以太网连接到路由器。我该怎么办?
其结果ipaddr
是:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN grup default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:40:f4:83:81:be brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether d2:76:9a:fb:1f:ea brd ff:ff:ff:ff:ff:ff
inet 192.168.x.x/x brd 192.168.x.x scope global birbr0
valid_lft forever preferred_lft forever
其结果ifconfig
是:
lo Link encap:Loopback locale
indirizzo inet:127.0.0.1 Maschera:255.0.0.0
indirizzo inet6: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5407 error:0dropped:0 overruns:0 frame:0
TX packets:5407 error:0 dropped:0 overruns:0 carrier:0
collisioni:0 txqueuelen:0
Byte RX:374717 (374.7 KB) Byte TX:374717 (374.7 KB)
virbr0 Link encap:Ethernet IndirizzoHW d2:76:9a:fb:1f:ea
indirizzo inet:192.168.x.x Bcast:192.168.x.x Maschera:255.255.255.0
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisioni:0 txqueuelen:0
Byte RX:0 (0.0 B) Byte TX:0 (0.0 B)
谢谢
答案1
首先,您应该检查您的服务器是否收到 IP 地址。这可以通过控制台上的命令“ip addr”进行检查。这将产生类似以下内容的结果:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether d4:3d:7e:33:70:15 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::d63d:7eff:fe33:7015/64 scope link
valid_lft forever preferred_lft forever
查找您的网络接口卡(NIC)名称(在本例中为“eth0”)并查找“inet”后面的地址。
如果您确实有有效的 IP 地址,请检查是否可以 ping 已知主机。例如 Ubuntu.org:
PING ubuntu.org (82.98.134.233) 56(84) bytes of data.
64 bytes from hl231.dinaserver.com (82.98.134.233): icmp_seq=1 ttl=50 time=51.2 ms
64 bytes from hl231.dinaserver.com (82.98.134.233): icmp_seq=2 ttl=50 time=39.6 ms
64 bytes from hl231.dinaserver.com (82.98.134.233): icmp_seq=3 ttl=50 time=31.9 ms
^C
--- ubuntu.org ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3003ms
rtt min/avg/max/mdev = 31.940/40.957/51.254/7.936 ms
至少这样你就知道你的互联网连接是否正常了。如果不行,试试你的路由器连接。你能连上吗?例如在浏览器中:http://192.168.1.1(替换为您的路由器的 IP)。要确定您的路由器的 IP,请使用“route -n”命令。
martin@jupiter:~$ 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 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
以 0.0.0.0 开头的行就是您需要的行。“网关”列中的条目提供了您的路由器的 IP。
要确定您的计算机是否通过 DHCP 收到 IP 地址,请检查系统日志。使用 grep 您将看到类似下面的内容。有一个条目“DHCPACK”(DHCP 确认),它告诉您您的服务器通过 DHCP 收到 IP 地址。
martin@jupiter:~$ cat /var/log/syslog | grep DHCP
Aug 4 08:48:53 jupiter NetworkManager[1131]: <info> Activation (eth0) Beginning DHCPv4 transaction (timeout in 45 seconds)
Aug 4 08:48:53 jupiter dhclient: Internet Systems Consortium DHCP Client 4.2.4
Aug 4 08:48:53 jupiter NetworkManager[1131]: <info> (eth0): DHCPv4 state changed nbi -> preinit
Aug 4 08:48:53 jupiter dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0xfe05734f)
Aug 4 08:48:53 jupiter dhclient: DHCPREQUEST of 192.168.123.100 on eth0 to 255.255.255.255 port 67 (xid=0x4f7305fe)
Aug 4 08:48:53 jupiter dhclient: DHCPOFFER of 192.168.123.100 from 192.168.123.253
Aug 4 08:48:53 jupiter dhclient: DHCPACK of 192.168.123.100 from 192.168.123.253
Aug 4 08:48:53 jupiter NetworkManager[1131]: <info> (eth0): DHCPv4 state changed preinit -> bound
Aug 4 08:48:54 jupiter dnsmasq[2723]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
如果所有这些都不起作用,请检查您的电缆和(希望)网卡上的指示灯。应该可以看到绿灯,表示连接的最低层有工作连接。
说了这么多,还有一个问题:你的路由器是否具有提供商提供的有效 IP 地址。必须在路由器的 Web GUI 中检查。通常会有一些显示状态的页面(查找 WAN 连接信息)。