一、设置静态IP步骤:
1、ifconfig查看目前的IP和获取网卡名,可以看出网卡名是eno1。
2、这个时候测试一下ping 外网和ping内外,确保网络是通的。
3、ubuntu 系统分配固定 ip 修改配置文件interfaces
,输入 sudo vi /etc/network/interfaces
xxx@ubuntu:~$ sudo vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eno1
iface eno1 inet dhcp
4、按如下修改
5、配置说明
配置说明:
auto ens33:使用的网络接口
iface ens33 inet static:ens33这个接口,使用静态IP设置
address 192.168.43.50:设置IP地址
netmask 255.255.255.0:设置子网掩码
gateway 192.168.43.1:设置网关
修改完之后,按ESC键,然后输入:qw即可保存并关闭文件
5、 然后reboot系统,得reboot,我测试过用命令行重启网络 systemctl restart networking,但是无效。
6、reboot后ifconfig查看ip,ip已经是修改成静态ip了。
二、按第一步修改配置文件interfaces
后,可以ping内网,但是不能ping外网,提示ping: unknown host。
1、可以ping内网不能ping外网图。
2、解决方法,DNS有问题成设置8.8.8.8,ps:尝试设置成跟gateway 一样,但是还是不能ping外网。
3、然后执行下面命令重启网卡
xxx@ubuntu:~$ sudo /etc/init.d/networking restart
Restarting networking (via systemctl): networking.service.
或者
xxx@ubuntu:~$ sudo systemctl restart networking
4、测试ok,内外网都可以ping了
三、参考文章
https://www.jianshu.com/p/d808fa099edb
https://blog.csdn.net/lzhitwh/article/details/82773335
https://www.jb51.cc/ubuntu/497709.html
https://www.cnblogs.com/yunwangjun-python-520/p/10433378.html