首页 技术 正文
技术 2022年11月14日
0 收藏 355 点赞 3,925 浏览 1177 个字

ubuntu如何设置静态IP?

设置静态IP

1.编辑/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 eth0#etho为通常的Ubuntu的网关名称,有时也会改变,可通过ifconfig命令查看,有时会出现如ens160,ens33等名称

iface eth0 inet static#设置IP为静止IP,

address 192.168.1.103#你想设置的静态IP地址

netmask 255.255.255.0#子网掩码,通常为255.255.255.0

#network 192.168.1.0

broadcast 192.168.1.255 #广播地址,可以通过ifconfig查看现有的。,

gateway 192.168.1.8#网关, #netstat -r 命令或者   nm-tool   查看现有的

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 61.139.2.69#国内常见的dns解析,

#dns-search localhost

dns-nameservers 8.8.8.8#谷歌dns解析,但是速度较慢

配置好后就重启网卡:sudo /etc/init.d/networking restart

即可查看修改后的系统IP信息。如果无networking文件,则自己创建。

执行该命令时,可能出现的错误:

[….] Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code. See “systemctl status networking.service” and “journalctl -xe” for details.

failed!

后来发现出现这个错误的原因,是因为Ubuntu16.04中的网卡名称不是eth0。

具体是网卡名称可以通过ifocnfig命令查看,我的机子的网卡名称为enp0s25,有些机子的网卡名称可能是ens33,将eth0改成自己的机子的网卡名称,然后保存推出,重启网络,发现成功了!大功告成。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919