ubuntu14下配置靜態ip地址
阿新 • • 發佈:2019-01-09
安裝系統時添加了兩個網絡卡,安裝完成後,網絡卡資訊如下所示
想把eth0的ip配置成靜態的10.180.141.130[email protected]:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a inet addr:10.180.0.189 Bcast:10.180.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7486 errors:0 dropped:0 overruns:0 frame:0 TX packets:181 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:476030 (476.0 KB) TX bytes:19795 (19.7 KB) eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74 inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7375 errors:0 dropped:0 overruns:0 frame:0 TX packets:51 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:453195 (453.1 KB) TX bytes:8376 (8.3 KB)
開啟網絡卡配置檔案vi /etc/network/interfaces
新增eth0的配置如下
auto eth0
iface eth0 inet static
address 10.180.141.130
netmask 255.255.255.0
gateway 10.180.0.1
儲存後,重啟網路
sudo /etc/init.d/networking restart
再檢視網路配置 ifconfig
[email protected]:/etc/network# ifconfig eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a inet addr:10.180.0.189 Bcast:10.180.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:38934 errors:0 dropped:0 overruns:0 frame:0 TX packets:187 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2371872 (2.3 MB) TX bytes:20377 (20.3 KB) eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74 inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:38823 errors:0 dropped:0 overruns:0 frame:0 TX packets:95 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2349037 (2.3 MB) TX bytes:11238 (11.2 KB)
發現網絡卡地址並沒有變
注意:如果Ubuntu系統採用的是desktop版,由於desktop版安裝了NetworkManager,修改完interfaces文件中的內容後,不會生效。需要先修改 /etc/NetworkManager/NetworkManager.conf 文件中的managed引數,使之為true,並重啟系統,
然後在修改 /etc/network/interfaces 檔案,設定靜態IP。這是桌面版和伺服器版的不同之處
[email protected]:~# cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=yes
[email protected]:~#
重啟後,發現網絡卡配置正確了
[email protected]:/etc/network# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.141.130 Bcast:10.180.141.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2043569 errors:0 dropped:0 overruns:0 frame:0
TX packets:564 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:123158350 (123.1 MB) TX bytes:65430 (65.4 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20284 errors:0 dropped:0 overruns:0 frame:0
TX packets:232 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1252816 (1.2 MB) TX bytes:32046 (32.0 KB)
其實可以採用命令列的方式來配置ip地址ifconfig eth0 10.180.141.130 netmask 255.255.0.0
檢視網絡卡資訊,發現資訊正確,只是這種方式重啟後網路配置不能儲存
[email protected]:/etc/network# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.141.130 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43771 errors:0 dropped:0 overruns:0 frame:0
TX packets:230 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2662710 (2.6 MB) TX bytes:27458 (27.4 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43699 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2646716 (2.6 MB) TX bytes:11778 (11.7 KB)
至此,ip地址配置完畢。
配置dns請參考博主的下一篇部落格