感謝冷月夜2008分享:http://chengyoyo2006.blog.163.com/blog/static/8451734820102510257522/ 在Debian中網(wǎng)卡的設置可以通過(guò)/etc/network/interfaces文件來(lái)進(jìn)行,具體可分為三種不同的配置方式:DHCP自動(dòng)獲取、靜態(tài)分配IP地址和PPPoE寬帶撥號。 具體設置如下: 在進(jìn)行配置之前,首先進(jìn)入/etc/network目錄中,用nano命令編輯interfaces文件: 網(wǎng)卡通過(guò)DHCP自動(dòng)獲取IP地址 # 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(配置環(huán)回口) # 開(kāi)機自動(dòng)激lo接口 auto lo # 配置lo接口為環(huán)回口 iface lo inet loopback # # The primary network interface (配置主網(wǎng)絡(luò )接口) #開(kāi)機自動(dòng)激活eth0接口 auto eth0 #配置eth0接口為DHCP自動(dòng)獲取 iface eth0 inet dhcp 網(wǎng)卡靜態(tài)分配IP地址 # 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(配置環(huán)回口) # 開(kāi)機自動(dòng)激lo接口 auto lo # 配置lo接口為環(huán)回口 iface lo inet loopback # # The primary network interface (配置主網(wǎng)絡(luò )接口) #開(kāi)機自動(dòng)激活eth0接口 auto eth0 #配置eth0接口為靜態(tài)設置IP地址 iface eth0 inet static 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 #單網(wǎng)卡配置多個(gè)ip,設置第二個(gè)ip地址 auto eth0:1 iface eth0:1 inet static address x.x.x.x 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 feelnet.org 配置好后推出編輯/etc/resolv.conf,配置DNS,加入以下信息: nameserver 219.146.0.130 基本文件格式 Debian的網(wǎng)絡(luò )配置文件在目錄/etc/network中,其中的interfaces文件中保存了每一個(gè)網(wǎng)絡(luò )設備在啟動(dòng)時(shí)的屬性。下面是一個(gè)很簡(jiǎn)單的配置文件: 例子 1. 簡(jiǎn)單的配置文件 auto lo eth0 ① iface lo inet loopback ② iface eth0 inet dhcp ③ iface eth1 inet static ④ address 10.1.133.165 netmask 255.255.255.0 gateway 10.1.133.1 ① 表示系統中的lo和eth0兩個(gè)網(wǎng)絡(luò )設備在系統啟動(dòng)網(wǎng)絡(luò )時(shí)自動(dòng)啟動(dòng)。 ② 表示網(wǎng)絡(luò )設備lo使用TCP/IP網(wǎng)絡(luò )并且是一個(gè)loopback設備,如果是IPV6網(wǎng)絡(luò )則使用"inet6",IPX網(wǎng)絡(luò )使用"ipx"。 ③ 表示網(wǎng)絡(luò )設備eth0使用TCP/IP網(wǎng)絡(luò ),同時(shí)使用DHCP自動(dòng)獲取IP地址。 ④ 表示網(wǎng)絡(luò )設備eth1使用TCP/IP網(wǎng)絡(luò ),并且是占用固定的IP 10.1.33.165,子網(wǎng)掩碼是255.255.255.0,網(wǎng)關(guān)是10.1.133.1。 上面的這種配置方式,可以使用于大多數的情況,但在一些特殊的情況下,就需要一些更為靈活的手段來(lái)配置網(wǎng)絡(luò )。 通過(guò)PING配置網(wǎng)絡(luò ) Linux在處理PCMCIA卡的時(shí)候有比較好的方式,可以在PCMICA卡插入時(shí)通過(guò)一個(gè)配置腳本來(lái)確定網(wǎng)絡(luò )地址。但是,筆記本上的網(wǎng)卡是筆記本自帶的,并非PCMCIA卡,由于經(jīng)常需要奔波于辦公室、實(shí)驗室和家之間,就經(jīng)常需要修改網(wǎng)絡(luò )地址。如果我去的每一個(gè)地方都安裝了DHCP,那么我就可以把 eth0設定成為DHCP的方式,然而我的情況卻是:在家可以使用DHCP,在辦公室和實(shí)驗室都要使用固定地址。 為了解決這個(gè)問(wèn)題,我們可以使用一種mapping機制,這種方法的基本原理是通過(guò)運行一個(gè)程序來(lái)確定目前所處的環(huán)境,并為這個(gè)環(huán)境選擇一套配置。我現在使用的就是通過(guò)ping一個(gè)網(wǎng)絡(luò )的網(wǎng)關(guān)來(lái)確定當前網(wǎng)卡究竟連接在哪個(gè)網(wǎng)絡(luò )上,然后再選擇這個(gè)網(wǎng)絡(luò )的配置。 首先,在/usr/share/doc/ifupdown/examples中有一個(gè)文件ping-places.sh,把它復制到/etc/network目錄中,然后chmod +x /etc/network/ping-places.sh。下面就是編輯/etc/network/interfaces文件,下面是一個(gè)例子: 例子 2. mapping eth0 ① script /etc/network/ping-places.sh map 192.168.0.107/24 192.168.0.1 home map 10.1.133.165/24 10.1.133.1 office map 10.1.0.107/24 10.1.0.1 lab iface home inet dhcp ② iface office inet static ③ address 10.1.133.165 netmask 255.255.255.0 gateway 10.1.133.1 up cp /etc/resolv.conf.school /etc/resolv.conf ④ iface lab inet static address 10.1.0.107 netmask 255.255.255.0 gateway 10.1.0.1 up cp /etc/resolv.conf.school /etc/resolv.conf ① 表示對于網(wǎng)絡(luò )設備調用腳本/etc/network/ping-places.sh,如果能夠用地址192.168.0.107/24 ping通地址192.168.0.1,則將eth0映射為設備home,即啟動(dòng)home的配置。后面的office和lab與其類(lèi)似。 ② 表示虛擬設備home使用DHCP分配的地址。 ③ 表示虛擬設備office使用固定地址。 ④ 表示在啟動(dòng)這個(gè)網(wǎng)絡(luò )設備后還要執行cp命令,從而指定一個(gè)域名解析方法。除了up以外,還有pre-up、down和post-down可以用來(lái)指定在啟動(dòng)或停止網(wǎng)絡(luò )設備前后執行的命令。 在/usr/share/doc/ifupdown/examples中有一些配置網(wǎng)絡(luò )的例子和需要的腳本。
發(fā)表評論