最近須要在虛擬機當中裝個Ubuntu Server 16.04
的系統,可是在虛擬機安裝的時候,並不像Ubuntu Server 18.04
那樣能一步步的進行配置,所以致使裝好後的虛擬機是動態IP地址。而該虛擬機要做爲測試服務器來使用,因此要將IP地址設置爲靜態IP。vim
經過命令行查看當前IP信息。bash
ifconfig # 輸出結果以下: ens33 Link encap:Ethernet HWaddr 00:0c:29:98:5f:81 inet addr:192.168.4.246 Bcast:192.168.4.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe98:5f81/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:28536 errors:0 dropped:0 overruns:0 frame:0 TX packets:17938 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3741540 (3.7 MB) TX bytes:2286437 (2.2 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:193 errors:0 dropped:0 overruns:0 frame:0 TX packets:193 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:16356 (16.3 KB) TX bytes:16356 (16.3 KB)
在新安裝的系統當中,默認安裝vi
編輯器,可是本人以爲這個編輯器的操做沒有vim
熟悉,所以要安裝vim
編輯器。服務器
# 先更新apt-get源 sudo apt-get update # 安裝vim sudo apt-get install vim
修改/etc/network/interfaces
文件。注意:是interfaces
,有s。網絡
sudo vim /etc/network/interfaces
在打開的文件中,若是是動態IP,以下所示:編輯器
# 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 ens33 iface ens33 inet dhcp
若是要修改成靜態IP,則輸入以下代碼:oop
# 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 ens33 iface ens33 inet static address 192.168.4.246 netmask 255.255.255.0 gateway 192.168.4.1 dns-nameservers 8.8.8.8
注意:若是已經有網卡ens33
,則按對應名稱編寫便可。
配置說明:測試
修改完以後,按ESC
鍵,而後輸入:qw
便可保存並關閉文件。命令行
在網上找到的一些教程當中,要使用刷新IP的命令,可是我發現有些時候那些命令無法使用。
所以,最簡單的方法就是直接重啓系統。code
sudo reboot
執行命令orm
ping [局域網IP] | [外網IP] | [具體域名]