Spark修煉之道(基礎篇)——Linux大資料開發基礎:第八節:網路管理

五柳-先生發表於2015-11-14

本節主要內容

  1. ifconfig命令
  2. 網路配置
  3. 其它常用網路管理命令

1. ifconfig命令

ifconfig命令主要用於配置網路介面,如果不加任何引數,則ifconfig命令用於檢視當前所有活動網路介面的狀態資訊,例如: 
這裡寫圖片描述 
圖中的eth0表示活動的乙太網介面,對應的描述資訊中給出了網路的整體狀況資訊包括網路型別、MAC地址、IP地址、子網掩碼等等,lo表示本地環回網路地址。從圖中可以看到,所有的網路型別都是inet即基於TCP/IP協議的網路。

<code class="hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">目前支援的主流協議包括:
 inet (TCP/IP, 預設), 
 inet6 (IPv6), 
 ax25 (AMPR Packet Radio),
 ipx (Novell  IPX)  
 netrom (AMPR Packet radio).
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

ifconfig其它常用選項包括:

<code class="hljs haml has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> -<span class="ruby" style="box-sizing: border-box;">a     顯示所有網路介面,包括停用的
</span>
 -<span class="ruby" style="box-sizing: border-box;">s     短格式顯示網路資訊,同netstat -i
</span> -<span class="ruby" style="box-sizing: border-box;">v     顯示詳細資訊,在網路出錯的情況下適用
</span> interface  指定網路介面
 up     啟用網路介面

 down   關閉網路介面
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>

例子: 
(1)ifconfig -a 
這裡寫圖片描述 
圖中的pan0表示藍芽裝置,預設不開啟 
(2) ifconfig pan0 up 
開啟前 ifconfig -a顯示的資訊

<code class="hljs css has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">pan0</span>      <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">Link</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">encap</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:Ethernet</span>  <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">HWaddr</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">d6</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:98</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:40</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:b0</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:9e</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:9d</span>  
          <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">BROADCAST</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">MULTICAST</span>  <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">MTU</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:1500</span>  <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">Metric</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:1</span>
          <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">RX</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">packets</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">errors</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">dropped</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">overruns</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">frame</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span>
          <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">TX</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">packets</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">errors</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">dropped</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">overruns</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">carrier</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span>
          <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">collisions</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">txqueuelen</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> 
          <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">RX</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bytes</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> (0<span class="hljs-class" style="box-sizing: border-box; color: rgb(155, 112, 63);">.0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">B</span>)  <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">TX</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">bytes</span><span class="hljs-pseudo" style="color: rgb(0, 0, 0); box-sizing: border-box;">:0</span> (0<span class="hljs-class" style="box-sizing: border-box; color: rgb(155, 112, 63);">.0</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">B</span>)
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

執行完命令ifconfig pan0 up後

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">pan0      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Link</span> encap:Ethernet  HWaddr d6:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">98</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>:b0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>e:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>d  
          inet6 addr: fe80<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;">::d498</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>ff:feb0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9e9</span>d/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> Scope:<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Link</span>
          UP BROADCAST RUNNING MULTICAST  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1500</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">RX</span> packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> 
          <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">RX</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> B)  TX <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468.0</span> B)
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>

(3) ifconfig eth0 down禁用網路 
這裡寫圖片描述

2. 網路配置

目前網路配置採用的仍然是NAT即網路地址轉換的形式 
這裡寫圖片描述 
除NAT連網方式,VMWare還提供橋接(Bridged)與Host-only網路連線方式。它們之間的相關描述如下(部分內容引自http://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646007.html):

(1)橋接 
橋接網路是指本地物理網路卡和虛擬機器網路卡通過VMnet0虛擬交換機進行橋接,物理網路卡和虛擬網路卡在拓撲圖上處於同等地位,即物理網路卡和虛擬網路卡就相當於處於同一個網段,虛擬交換機就相當於一臺現實網路中的交換機,因此兩個網路卡的IP地址也要設定為同一網段。 
如果區域網中還有其他裝置需要登入到虛擬機器上,例如虛擬機器提供ssh登入,此時最適用於使用橋接方式進行連網。

(2)NAT 
NAT模式中,就是讓虛擬機器藉助NAT(網路地址轉換)功能,通過宿主機器所在的網路來訪問網路。NAT模式中,虛擬機器的網路卡和物理網路卡的網路,不在同一個網路,虛擬機器的網路卡,是在vmware提供的一個虛擬網路。

(3)Host-Only 
在Host-Only模式下,虛擬網路是一個全封閉的網路,它唯一能夠訪問的就是主機。其實Host-Only網路和NAT網路很相似,不同的地方就是Host-Only網路沒有NAT服務,所以虛擬網路不能連線到Internet。主機和虛擬機器之間的通訊是通過VMware Network Adepter VMnet1虛擬網路卡來實現的。

  Host-Only的宗旨就是建立一個與外界隔絕的內部網路,來提高內網的安全性。這個功能或許對普通使用者來說沒有多大意義,但大型服務商會常常利用這個功能。如果你想為VMnet1網段提供路由功能,那就需要使用RRAS,而不能使用XP或2000的ICS,因為ICS會把內網的IP地址改為192.168.0.1,但虛擬機器是不會給VMnet1虛擬網路卡分配這個地址的,那麼主機和虛擬機器之間就不能通訊了。

NAT和橋接的比較:

(1) NAT模式和橋接模式虛擬機器都可以上外網。

(2) 由於NAT的網路在vmware提供的一個虛擬網路裡,所以區域網其他主機是無法訪問虛擬機器的,而宿主機可以訪問虛擬機器,虛擬機器可以訪問區域網的所有主機,因為真實的區域網相對於NAT的虛擬網路,就是NAT的虛擬網路的外網,不懂的人可以查查NAT的相關知識。

(3) 橋接模式下,多個虛擬機器之間可以互相訪問;NAT模式下,多個虛擬機器之間也可以相互訪問。

如果你建一個虛擬機器,只是給自己用,不需要給區域網其他人用,那麼可以選擇NAT,畢竟NAT模式下的虛擬系統的TCP/IP配置資訊是由VMnet8(NAT)虛擬網路的DHCP伺服器提供的,只要虛擬機器的網路配置是DHCP,那麼你不需要進行任何其他的配置,只需要宿主機器能訪問網際網路即可,就可以讓虛擬機器聯網了。

綜述 
  在VMware的3中網路模式中,NAT模式是最簡單的,基本不需要手動配置IP地址等相關引數。至於橋接模式則需要額外的IP地址,如果是在內網環境中還很容易,如果是ADSL寬頻就比較麻煩了,ISP一般是不會大方的多提供一個公網IP的。

在後期Hadoop、Spark叢集搭建時,我們不建議使用NAT網路連線方式,因為NAT方式,每次關閉虛擬機器重新啟動後,分配的IP地址可能會不一樣,這樣的話不利用主機與IP地址的對映,因此推薦使用橋接方式,本節將著重講解如果通過橋接方式進行網路配置,在配置之前先將虛擬機器的網路連線方式設定為橋接,如下圖 
這裡寫圖片描述

完成後按如下步驟進行網路配置:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> 修改 /etc/network/interfaces 檔案內容,修改後的內容如下:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.120</span>
netmask <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>
gateway <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span>

<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> 使配置後的網路地址生效
root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># vim /etc/network/interfaces </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">
//啟動網路</span>
root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ifconfig eth0 up</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">
//檢視ip地址,發現沒有產生變化</span>
root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ifconfig</span>
eth0      Link encap:Ethernet  HWaddr <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">29</span>:e1:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>f  
          inet addr:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.47</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.130</span>  Bcast:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.47</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.255</span>  Mask:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>
          inet6 addr: fe80::<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">29</span>ff:fee1:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>c1f/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1500</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25217</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7879</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15912320</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15.9</span> MB)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">588004</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">588.0</span> KB)
          Interrupt:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> Base address:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0x2024</span> 

lo        Link encap:Local Loopback  
          inet addr:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">127.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span>  Mask:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>
          inet6 addr: ::<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span> Scope:Host
          UP LOOPBACK RUNNING  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16436</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">153</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">153</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11580</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11.5</span> KB)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11580</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11.5</span> KB)

pan0      Link encap:Ethernet  HWaddr d6:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">98</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>:b0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>e:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>d  
          inet6 addr: fe80::d498:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>ff:feb0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9e9</span>d/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1500</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> B)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468.0</span> B)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">
//通過下列命令之後,修改後的ip地址才會生效</span>
root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># /etc/init.d/networking restart</span>
 * Reconfiguring network interfaces...                                       SIOCDELRT: No such <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">process</span>
ssh stop/waiting
ssh start/running, <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">process</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14692</span>
                                                                      [ OK ]
root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ifconfig</span>
eth0      Link encap:Ethernet  HWaddr <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">29</span>:e1:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>f  
          inet addr:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.120</span>  Bcast:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.255</span>  Mask:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.255</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>
          inet6 addr: fe80::<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>c:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">29</span>ff:fee1:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>c1f/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1500</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25217</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7899</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15912320</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15.9</span> MB)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">591109</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">591.1</span> KB)
          Interrupt:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> Base address:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0x2024</span> 

lo        Link encap:Local Loopback  
          inet addr:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">127.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span>  Mask:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>
          inet6 addr: ::<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span> Scope:Host
          UP LOOPBACK RUNNING  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16436</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">156</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">156</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11826</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11.8</span> KB)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11826</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11.8</span> KB)

pan0      Link encap:Ethernet  HWaddr d6:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">98</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>:b0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>e:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>d  
          inet6 addr: fe80::d498:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">40</span>ff:feb0:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9e9</span>d/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1500</span>  Metric:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
          RX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> frame:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          TX packets:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> errors:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> dropped:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> overruns:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> carrier:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
          collisions:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> txqueuelen:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> 
          RX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> B)  TX <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">468.0</span> B)

<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> 設定DNS
光通過前面的設定,只能進行同一網路下的主機之間通訊,如果要連線公網,還需要設定DNS,方法如下:
vim /etc/resolv.conf</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li></ul>

這裡寫圖片描述

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">將nameserver修改為<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8.8</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.8</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.8</span>(google提供的域名解析服務)
,儲存完成後,再執行
/etc/init<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.d</span>/networking restart命令使域名設定生效。
完成後,如果使用<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">ping</span> www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.baidu</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span>命令,能<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">ping</span>通則說明配置成功
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

這裡寫圖片描述

3. 其它常用網路管理命令

(1)host進行DNS查詢

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root@ubuntu:/var/lib/aptitude<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># host www.baidu.com</span>
www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.baidu</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span> is an alias for www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.a</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.shifen</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span>.
www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.a</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.shifen</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span> has address <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.218</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.70</span>
www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.a</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.shifen</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span> has address <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.217</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.109</span>
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

(2)netstat命令

netstat命令可以顯示網路介面的很多統計資訊,包括開啟的socket和路由表

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/var/lib/aptitude</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># netstat -r </span>
<span class="hljs-constant" style="box-sizing: border-box;">Kernel</span> <span class="hljs-constant" style="box-sizing: border-box;">IP</span> routing table
<span class="hljs-constant" style="box-sizing: border-box;">Destination</span>     <span class="hljs-constant" style="box-sizing: border-box;">Gateway</span>         <span class="hljs-constant" style="box-sizing: border-box;">Genmask</span>         <span class="hljs-constant" style="box-sizing: border-box;">Flags</span>   <span class="hljs-constant" style="box-sizing: border-box;">MSS</span> <span class="hljs-constant" style="box-sizing: border-box;">Window</span>  irtt <span class="hljs-constant" style="box-sizing: border-box;">Iface</span>
<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.0</span>     *               <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.255</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.0</span>   <span class="hljs-constant" style="box-sizing: border-box;">U</span>         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>          <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> eth<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
link-local      *               <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.255</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>     <span class="hljs-constant" style="box-sizing: border-box;">U</span>         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>          <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> eth<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
default         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.1</span>     <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>         <span class="hljs-constant" style="box-sizing: border-box;">UG</span>        <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>          <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> eth<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

(3)traceroute命令

traceroute命令進行路由追蹤

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/var/lib/aptitude</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># traceroute www.baidu.com</span>
traceroute to www.baidu.com (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">217.109</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span> hops max, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">60</span> byte packets
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.1</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.1</span>)  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.382</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.164</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.610</span> ms
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">218.108</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.67</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">218.108</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">255.67</span>)  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.354</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.114</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.884</span> ms
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">218.109</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.70</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">218.109</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.70</span>)  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.683</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.798</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.300</span> ms
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30.250</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9.6</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30.250</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9.6</span>)  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.634</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.524</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.535</span> ms
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30.207</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6.97</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30.207</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6.97</span>)  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.085</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.257</span> ms  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.891</span> ms
 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>  *
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>

(4)ping命令

ping命令常用來測試網路連線是否正常

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root@ubuntu:/var/lib/aptitude<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ping www.baidu.com </span>
PING www.<span class="hljs-operator" style="box-sizing: border-box;">a</span>.shifen.com (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.218</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.70</span>) <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">56</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">84</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-operator" style="box-sizing: border-box;">of</span> data.
<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">from</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.218</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.70</span>: icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">55</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">68.3</span> ms
<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">from</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.218</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.70</span>: icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">55</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">113</span> ms
<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">from</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">119.75</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.218</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.70</span>: icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">55</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">69.4</span> ms
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>

轉載:http://blog.csdn.net/lovehuangjiaju/article/details/48183485

相關文章