ubuntu 16.04 设置静态IP

ZephyrXT 发布于 阅读:73

https://www.jianshu.com/p/d69a95aa1ed7


在上一篇文章「hustoj 管理员和后台设置」中,提到过一个设置静态ip的问题,后来发现,还是存在问题,重新启动机器后,出现无法上网的问题。在「百度」中搜索了许久,没有找到合适的处理方法,最后使用英文关键字搜索才解决 「ubuntu 16.04 static ip」,最后参照[http://askubuntu.com/questions/766131/set-static-ip-ubuntu-16-04] 这篇文章后才解决,以下是我的解决方法。



1、查询网络接口的名字

打开命令行,输入ifconfig [区别windows是ipconfig]。



ifconfig

查询网络接口



第一行最左边的名字,就是本机的网络接口,此处为 enp7s0 ,不同机器可能不同。



2、打开修改文件

修改/etc/network/interfaces 文件 [注意是interfaces,有s]。

输入以下命令行



sudo gedit /etc/network/interfaces // gedit 是用gedit进行编译打开,也可以用其他编译器打开

打开文件

3、修改文件

在打开的文件中,输入以下代码



auto enp7s0

iface enp7s0 inet static

address 10.0.208.222

netmask 255.255.240.0

gateway 10.0.208.1

dns-nameservers 10.0.208.1

对以上代码进行简单解释:



auto enp7s0 // 使用的网络接口,之前查询接口是为了这里

iface enp7s0 inet static // enp7s0这个接口,使用静态ip设置

address 10.0.208.222 // 设置ip地址

netmask 255.255.240.0 // 设置子网掩码

gateway 10.0.208.1 // 设置网关

dns-nameservers 10.0.208.1 // 设置dns服务器地址



修改设置

修改完之后,点「保存」,然后关闭文件。



4、刷新ip

单纯使用断开连接再重新连接,并不是正确的方式,正确的方式是,使用以下命令行。



sudo ip addr flush enp7s0

sudo systemctl restart networking.service

注意,第一条代码中,你要修改成本机的网络接口。



5、重启系统

重新启动系统,重启后,会提示未找到合法连接,打开浏览器也是无法使用网络的,还要进行最后一步。

收到2条评论
avatar
ZephyrXT 2019-10-13 19:02
https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/
avatar
ZephyrXT 2019-10-13 18:57
https://michael.mckinnon.id.au/2016/05/05/configuring-ubuntu-16-04-static-ip-address/
https://forum.ubuntu.org.cn/viewtopic.php?f=73&t=190174
https://wiki.buyvm.net/doku.php/kvm
https://blog.csdn.net/xing_hao/article/details/6074197