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改成自己的機子的網卡名稱,然后保存推出,重啟網絡,發現成功了!大功告成。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM