因此,如上所述,我可以使用 SSH 远程访问我的服务器,也可以在本地访问,但我无法访问“互联网”。我的意思是,我无法访问网页。
dtipp@mc-server:~$ ping www.google.com
ping: unknown host www.google.com
这就是我尝试 ping google 时得到的结果。
dtipp@mc-server:~$ curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
无法像以前一样生成 IP 地址。我的所有问题都是在尝试设置静态 IP 地址后开始的。我终于设法让我的文件看起来像我认为的那样,但直到现在问题才开始出现。
dtipp@mc-server:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:19:b9:d3:b1:fa
inet addr:192.168.1.120 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::219:b9ff:fed3:b1fa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21401 errors:0 dropped:0 overruns:0 frame:0
TX packets:20888 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3207899 (3.2 MB) TX bytes:4381547 (4.3 MB)
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:4102 errors:0 dropped:0 overruns:0 frame:0
TX packets:4102 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:353932 (353.9 KB) TX bytes:353932 (353.9 KB)
dtipp@mc-server:~$ sudo nano /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.120
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dtipp@mc-server:~$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# nameserver 192.168.1.120
dtipp@mc-server:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=29.1 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 28.564/28.827/29.108/0.329 ms
这是安装文件,以及其他一些 ping 操作的结果。我做错了什么吗?还是我需要做其他事情?
答案1
当您设置静态 IP 地址时,您还必须设置 DNS 名称服务器。我建议您将 /etc/network/interfaces 修改为:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.120
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1 8.8.8.8
重启界面:
sudo ifdown eth0 && sudo ifup -v eth0
测试:
ping -c3 www.ubuntu.com
你的 /etc/resolv.conf 也不正确。请修改:
nameserver 127.0.1.1