ubuntu 網絡地址配置總結

http://www.linuxidc.com/Linux/2010-03/24820p3.htm

# 根據網上資料整理

  # 方式1和方式4已驗證

  # anything the matter, please contact: [email protected]

  目錄

  方式1:網卡通過DHCP自動獲取IP地址

  方式2:網卡靜態分配IP地址

  方式3:PPPoE寬帶撥號配置

  方式4:通過無線局域網接入互聯網

  方式1:網卡通過DHCP自動獲取IP地址

  $ sudo gedit /etc/network/interfaces

  # 修改文件/etc/network/interfaces如下文

  #-------------------------------------------------------------------------------

  # This file describes the network interfaces available on your system

  # and how to activate them. For more information, see interfaces(5).

  #

  # The loopback network interface(配置環回口)

  auto lo                                       # 開機自動激lo接口

  iface lo inet loopback                        # 配置lo接口爲環回口

  # The primary network interface (配置主網絡接口)

  auto eth0                                     #開機自動激活eth0接口

  iface eth0 inet dhcp                          #配置eth0接口爲DHCP自動獲取

  #-------------------------------------------------------------------------------

  $ sudo /etc/init.d/networking restart           # 重啓網絡

  方式2:網卡靜態分配IP地址

  $ sudo gedit /etc/network/interfaces

  # 修改文件/etc/network/interfaces如下文

  #-------------------------------------------------------------------------------

  # This file describes the network interfaces available on your system

  # and how to activate them. For more information, see interfaces(5).

  #

  # The loopback network interface(配置環回口)

  auto lo                                       # 開機自動激lo接口

  iface lo inet loopback                        # 配置lo接口爲環回口

  # The primary network interface (配置主網絡接口)

  auto eth0                                     #開機自動激活eth0接口

  iface eth0 inet static                        #配置eth0接口爲靜態設置IP地址

  address 10.16.3.99

  netmask 255.255.255.0

  network 10.16.3.0

  broadcast 10.16.3.255

  gateway 10.16.3.1

  ####################################################

  ## dns-* options are implemented by the resolvconf package, if installed(DNS設置)

  #dns-nameservers 61.153.177.196 61.153.177.197

  #dns-search fireteam.org

  ####################################################

  #sudo gedit /etc/resolv.conf

  ##設置DNS server(可以設置多個)

  #nameserver 192.168.1.1

  ####################################################

  #-------------------------------------------------------------------------------

  $ sudo /etc/init.d/networking restart    # 重啓網絡

  方式3:PPPoE寬帶撥號配置

  首次撥號:

  應用程序–系統工具–終端  打開一終端,輸入命令:

  sudo pppoeconf

  系統開始搜索所有網絡接口上的adsl modem,一步步的yes過來。

  │ Please enter the username which you usually need for │

  │ the PPP login to your provider in the input box below. │

  │ If you wish to see the help screen, delete the │

  │ username and press OK. │

  輸入你的寬帶帳號。

  輸入密碼。

  tip:如果是河南網通提供的PPPoE寬帶帳號,此處輸入的是加密後的用戶名

  Would you like to add these addresses automatically to the list of nameservers

  in your local /etc/resolv.conf file? (recommended)

  是否自動獲得DNS,選擇是。

  Should pppoe clamp MSS at 1452 bytes? If unsure, say yes.

  數據包長度的設置,如果跟我一樣不確定,選擇是

  Your PPPD is configured now. Would you like to start the connection at

  boot time?

  是否啓動時自動激活ADSL? 各位看着辦吧。

以後,要手工撥號,打開終端,輸入命令:

  sudo pon dsl-provider

  一般情況下,一次撥通後以後登陸Ubuntu 都會自動撥通上網的了,不用每次都輸入命令撥號。

  手工斷線:

  sudo poff

  查看連接情況:

  plog 和 ifconfig ppp0

  ifconfig ppp0 可查詢本機的上網IP。

  方式4:通過無線局域網接入互聯網

  要求安裝有無線局域網卡並已驅動

  1.插入無線網卡

  查看一下網絡設置,看看是否多出來了兩個設備

  $ ifconfig

  eth0      Link encap:Ethernet  HWaddr 00:24:7e:14:a9:a8

  inet6 addr: fe80::224:7eff:fe14:a9a8/64 Scope:Link

  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  RX packets:11998024 errors:0 dropped:0 overruns:0 frame:0

  TX packets:13667166 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:100

  RX bytes:1069420740 (1.0 GB)  TX bytes:3776606487 (3.7 GB)

  Memory:fc200000-fc220000

  eth0:avahi Link encap:Ethernet  HWaddr 00:24:7e:14:a9:a8

  inet addr:169.254.7.73  Bcast:169.254.255.255  Mask:255.255.0.0

  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  Memory:fc200000-fc220000

  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:16436  Metric:1

  RX packets:66657 errors:0 dropped:0 overruns:0 frame:0

  TX packets:66657 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:0

  RX bytes:6372151 (6.3 MB)  TX bytes:6372151 (6.3 MB)

  ppp0      Link encap:Point-to-Point Protocol

  inet addr:123.10.130.147  P-t-P:123.10.128.1  Mask:255.255.255.255

  UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1

  RX packets:149828 errors:0 dropped:0 overruns:0 frame:0

  TX packets:122796 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:3

  RX bytes:150170347 (150.1 MB)  TX bytes:16349467 (16.3 MB)

  wlan0     Link encap:Ethernet  HWaddr 00:22:fa:94:48:56

  UP BROADCAST MULTICAST  MTU:1500  Metric:1

  RX packets:0 errors:0 dropped:0 overruns:0 frame:0

  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:1000

  RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

  wmaster0  Link encap:UNSPEC  HWaddr 00-22-FA-94-48-56-00-00-00-00-00-00-00-00-

  00-00

  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  RX packets:0 errors:0 dropped:0 overruns:0 frame:0

  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:1000

  RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

  只要看見eth0就說明網卡設備設別出來了,eth0就是無線網卡設備的名字了,至於其他,暫不研究。

  2.確認無線網卡的型號

  $ lspci

  ......

  00:19.0 Ethernet controller: Intel Corporation 82567LM Gigabit Network

  Connection (rev 03)

  ......

  上面的Intel Corporation 82567LM Gigabit Network Connection (rev 03)就是無線網卡芯片

  的型號了。

3.打開無線網卡電源

  $ sudo iwconfig eth0 txpower on

  4.檢索區域內的無線網絡

  $ iwlist eth0 scan

  eth0      Scan completed :

  Cell 01 - Address: 00:1D:0F:4D:8B:E4

  ESSID:"TP-LINK"

  Mode:Master

  Frequency:2.437 GHz (Channel 6)

  Quality=28/70  Signal level=-67 dBm  Noise level=-95 dBm

  Encryption key:off

  Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s

  12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s

  48 Mb/s; 54 Mb/s

  Extra:bcn_int=100

  Extra:ath_ie=dd0900037f01010008ff7f

  Cell 02 - Address: 00:21:27:3A:37:0A

  ESSID:"TP-LINK"

  Mode:Master

  Frequency:2.437 GHz (Channel 6)

  Quality=12/70  Signal level=-83 dBm  Noise level=-95 dBm

  Encryption key:on

  Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s

  12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s

  48 Mb/s; 54 Mb/s

  Extra:bcn_int=100

  Extra:ath_ie=dd0900037f01010008ff7f

  Cell 03 - Address: 00:18:39:A6:98:E2

  ESSID:"linksys"

  Mode:Master

  Frequency:2.437 GHz (Channel 6)

  Quality=3/70  Signal level=-92 dBm  Noise level=-95 dBm

  Encryption key:on

  Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s

  9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s

  48 Mb/s; 54 Mb/s

  Extra:bcn_int=100

  IE: WPA Version 1

  Group Cipher : CCMP

  Pairwise Ciphers (1) : CCMP

  Authentication Suites (1) : PSK

  我附近有三個無線AP,ESSID所標記的就是無線AP的名字了,其中有兩個無線AP都叫做 TP-LINK,另一個叫

  linksys,記下這幾個無線AP的名字,一會得挨個試。

  5.連接無線AP

  $ sudo iwconfig ath0 essid "linksys"

  $ ifconfig

  不管連上還是連不上都不會給出任何提示,到底連沒連上還需要使用命令查看一下才行

  $ iwconfig eth0

  eth0      IEEE 802.11g  ESSID:"linksys"  Nickname:""

  Mode:Managed  Frequency:2.462 GHz  Access Point: Not-Associated

  Bit Rate:0 kb/s   Tx-Power:18 dBm   Sensitivity=1/1

  Retry:off   RTS thr:off   Fragment thr:off

  Power Management:off

  Link Quality=0/70  Signal level=-95 dBm  Noise level=-95 dBm

  Rx invalid nwid:8172  Rx invalid crypt:0  Rx invalid frag:0

  Tx excessive retries:0  Invalid misc:0   Missed beacon:0

  上面的黑體字的部分說明沒有連接成功,沒關係再換一個就是了。

  $ sudo iwconfig eth0 essid "TP-LINK"

  $ ifconfig

  執行後再查看一下接入狀態

  $ iwconfig eth0

  eth0      IEEE 802.11g  ESSID:"TP-LINK"  Nickname:""

  Mode:Managed  Frequency:2.437 GHz  Access Point: 00:1D:0F:4D:8B:E4

  Bit Rate:36 Mb/s   Tx-Power:18 dBm   Sensitivity=1/1

  Retry:off   RTS thr:off   Fragment thr:off

  Power Management:off

  Link Quality=26/70  Signal level=-69 dBm  Noise level=-95 dBm

  Rx invalid nwid:8268  Rx invalid crypt:0  Rx invalid frag:0

  Tx excessive retries:0  Invalid misc:0   Missed beacon:0

  ok,總算是連上了。

  注意:如果連接AP需要密碼,而你確實也知道AP的密碼,那麼可以用下面的辦法連接

  假設密碼是 123456789,密碼需要四位一組用”-“分開。

  $ sudo iwconfig ath0 essid "TP-LINK" key 1234-5678-9

  6.啓用無線網卡

  $ sudo ifconfig ath0 up

  7.設置無線網卡採用dhcp方式自動獲取ip

  $ sudo dhclient ath0

  Internet Systems Consortium DHCP Client V3.0.6

  Copyright 2004-2007 Internet Systems Consortium.

  All rights reserved.

  For info, please visit http://www.isc.org/sw/dhcp/

  wifi0: unknown hardware address type 801

  wifi0: unknown hardware address type 801

  Listening on LPF/ath0/00:19:e0:85:73:70

  Sending on   LPF/ath0/00:19:e0:85:73:70

  Sending on   Socket/fallback

  DHCPDISCOVER on ath0 to 255.255.255.255 port 67 interval 6

  DHCPOFFER of 192.168.1.104 from 192.168.1.1

  DHCPREQUEST of 192.168.1.104 on ath0 to 255.255.255.255 port 67

  DHCPACK of 192.168.1.104 from 192.168.1.1

  bound to 192.168.1.104 -- renewal in 3125 seconds.

  現在就可以拔掉網線,使用無線網卡上網了。

  8.斷開網絡

  如果需要斷開網絡,可以使用下面的命令

  $ sudo ifconfig ath0 down

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章