Ubuntu16.04配置静态IP地址

少说话 多做事
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改成自己的机子的网卡名称,然后保存推出,重启网络,发现成功了!大功告成。

少说话 多做事

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值