背景: 今天(2010.12.28)剛給機器安裝了ubuntu 10.1 server 。因為網絡配置是需要在安裝過程中配置,安裝完成後就不再容易配置。而有時候管理者難免要修改ip位址,域名伺服器( dns ),網關(gateway)等!而事實是server一般沒有安裝xserver,故進入不了gui,也就不能在圖形使用者界面友善的配置網絡。是以,今天特别檢視了指令行下的網絡配置。鑒于國内網絡上ubuntu server的配置執行個體較少,是以在此特别推出ubuntu server的網絡配置。
ps:網絡上的配置方案大都為rhel5或其他os的方案。參考方案如下:
檢視ip可用ifconfig;檢視主機名:使用hostname.
1.暫時性修改:
更改ip可用
~# ifconfig eth0 10.32.14.121 netmask 255.255.255.0 up
//後面的up是開啟這塊網卡的意思。
// 指令通用後面不再給出。
更改主機名:hostname **(**代表主機名)
此種修改方式立刻生效,系統重新開機後則不能生效。
2.永久性更改
更改ip
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
device=eth0
onboot=yes
bootproto=static
ipaddr=10.32.14.121
netmask=255.255.255.0
gateway=10.32.14.254
更改主機名
vi /etc/sysconfig/network
hostname=**(**為主機名)
但這不太适合ubuntu server。
因為 /etc/sysconfig/ 目錄在ubuntu中根本不存在,這
無論是server還是desktop版本都不具備的。
正确的目錄和檔案是:/etc/network/
其中/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
# the primary network interface
auto eth0
iface eth0 inet static
address 10.10.20.***
netmask 255.255.255.0
network 10.10.20.0
broadcast 10.10.20.255
gateway 10.10.20.254
# dns-* options are implemented by the resolvconf package, if installed
dns-search 1server
隻要修改這個檔案就可以達到永久修改的目的!
請需要更改的朋友們嘗試一下!