安裝Debian 7後, 改回最基本的網路設定方式(使用/etc/network/interface檔)

安裝Debian 7後, 改回最基本的網路設定方式

在剛裝完Debian 7 後, 發現網路卡eth0的設定已經被設定為DHCP, 查看了/etc/network/interface

# cat /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
iface lo inet loopback

發現, 奇怪, 這個設定檔只有lo interface 的設定, 那eth0 是在哪設定的呢?

查了一下, 原來Debian 已改用network-manager 來管理網路卡的設定. 但是我這台機器基本上是用來當head-less 機器, 以後不會裝螢幕, 也不會裝鍵盤滑鼠. 一切只用ssh 來控制. 對於使用GUI來管理網路卡, 實在很麻煩.

只好把它改回最原始Debain 的網路設定方法囉.
首先停用network-manager service

# /etc/init.d/network-manager stop
[ ok ] Stopping network connection manager: NetworkManager.

然後讓開機時不啟用network-manager service

# update-rc.d network-manager disable
update-rc.d: using dependency based boot sequencing
insserv: warning: current start runlevel(s) (empty) of script `network-manager' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `network-manager' overrides LSB defaults (0 1 6).

最後手動修改/etc/network/interface, 設定eth0 為DHCP, 增加如下內容於此檔案中

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp 

若eth0 要設為static IP, 則修改如下:

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254

並且修改/etc/resolv.conf 來設定DNS server

# cat /etc/resolv.conf
nameserver 168.95.1.1
nameserver 8.8.8.8

然後重開機就可以啦.


參考資料

  1. Network setup
This entry was posted in Linux and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *