1. 网络设置:
2. 修改/etc/network/interfaces文件,配置网络信息
sudo gedit /etc/network/interfaces
替换为以下内容
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto ens33 //网卡
iface ens33 inet static //静态IP
address 192.168.1.200 //IP地址
gateway 192.168.1.1 //网关
netmask 255.255.255.0 //子网掩码
重启网络
sudo /etc/init.d/networking restart
此时可以ping通主机/路由IP了
3.设置DNS,连接外网
sudo gedit /etc/resolv.conf
添加
nameserver 202.112.125.53
nameserver 8.8.8.8
此时可以ping一下www.baidu.com,可通
后来发现此方法在Ubuntu重启后会失效,推荐用以下方法:
打开resolved.conf文件
sudo gedit /etc/systemd/resolved.conf
添加DNS一栏,效果如下
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
DNS = 211.142.211.124 8.8.8.8
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
然后重启Ubuntu,再ping一下www.baidu.com发现可以正常上网了