1)打开命令窗口(右键单机桌面选择Open Terminal或者Ctrl+Alt+T),输入ip a查看自己的网卡编号
3)输入命令sudo vi /etc/network/interfaces,编辑该文件。注意此处eth0处用自己的网卡编号替换,address和gateway也是要视情况定的。
编辑完成后按esc(键盘左上角那个),再输入:wq!就可以保存退出了,此时ping一些自己的内网应该是可以ping通的了。Ping www.baidu.com还是ping不通的,接下来就需要继续接着做。
4)在命令行输入sudo vi /etc/systemd/resolved.conf 修改改文件:将DNS前的#号去掉,然后加上通用的DNS服务器地址即可。大家可以自行上网找,也可以就和我一样配置。
5)重启网络服务:
sudo /etc/init.d/networking force-reload ==> 重新加载网路配置文件
sudo /etc/init.d/networking restart
6)重启Ubuntu,就能ping通百度了。
7、如果正常配置出错(异常)
使用动态分配DNS:sudo dhclient linux动态分配IP
配置完成之后通过:ping www.baidu.com
一般而言这样就可以了,但是如果还不行,尝试如下操作:
①重新启停以太网卡:
sudo ifconfig eth0 down
sudo ifconfig eth0 up
②添加默认网关:
sudo route add default gw 192.168.1.1
③检查你的网线是否已经插好了!(注意这其实是第一步!!!!!)
当你的网络联通之后,使用APT软件管理器
PS:今天再次碰到这个问题ubuntun18.0.4版本,有时报错,需要修改一下/etc/hosts中的hostname没有和127.0.0.1对应。
我已经解决了这个问题,现在已经可以 ping www.baidu.com 。我修改了 50-cloud-init.yaml 、 resolv.conf 文件
这是 50-cloud-init.yaml
This file is generated from information provided by
the datasource. Changes to it will not persist across an instance.
To disable cloud-init’s network configuration capabilities, write a file
/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
network: {config: disabled}
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
optional: true
enp0s8:
addresses:
- 192.168.56.110/24
nameservers:
addresses: []
search: []
optional: true
version: 2
/run/systemd/resolve/resolv.conf
This file is managed by man:systemd-resolved(8). Do not edit.
#
This is a dynamic resolv.conf file for connecting local clients to the
internal DNS stub resolver of systemd-resolved. This file lists all
configured search domains.
#
Run “systemd-resolve –status” to see details about the uplink DNS servers
currently in use.
#
Third party programs must not access this file directly, but only through the
symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
replace this symlink by a static file or a different symlink.
#
See man:systemd-resolved.service(8) for details about the supported modes of
operation for /etc/resolv.conf.
nameserver 192.168.2.1
search lan
deploy@deploy:/etc$
这里需要特别注意 etc下的 resolv.con 文件是链接到/run/systemd/resolve目录下的那个文件。ubuntu 18.04 默认是链接到 /run/systemd/resolve/stub-resolv.conf 文件的
最新评论