2009年1月25日 星期日

透過指令修改ubuntu的網路設定

1. 設定IP
修改/etc/network/interfaces
若是要設定為DHCP以下為範例:

auto eth0
iface eth0 inet dhcp

若是固定ip則為

auto eth0
iface eth0 inet static
address 10.10.10.25
netmask 255.255.255.0
gateway 10.10.10.1

單網卡多個 IP(直接在網卡後,加上 ":n")

auto eth0:0
iface eth0:0 inet static
address [IP]
netmask [遮罩]
gateway [閘道]

auto eth0:1
iface eth0:1 inet static
address [IP]
netmask [遮罩]
gateway [閘道]

2. 設定DNS
修改/etc/resolv.conf
範例:

nameserver 168.95.1.1


3. 重新啟動network
[user@host ~]$ sudo /etc/init.d/networking restart

4. 設定 IP 位址
# ifconfig 介面 IP-位址 [broadcast 位址 ] [netmask ###]
$ sudo ifconfig eth0 163.26.183.1 broadcast 163.26.183.255 netmask 255.255.255.0

停止網路運作:停止網路介面ed0
$ sudo ifconfig eth0 down

啟動網路介面ed0
$ ifconfig eth0 up

5. 設定IP位址
ifconfig 語法為 :
ifconfig eth0 $IP netmask $NETMASK
如果你的 IP = 10.1.1.30
如果你的 NETMASK = 255.255.255.0
則你下的命令為
$ ifconfig eth0 10.1.1.30 netmask 255.255.255.0

route 設定 default gateway 語法為 :
route add default gw $GATEWAY
如果你的 GATEWAY = 10.1.1.1
則你下的命令為
$ route add default gw 10.1.1.1

請試試看以下命令 :
# 列出目前的網路卡設定狀態
$ ifconfig
# 秀出目前的 route table 表
$ route -n

[2009.04.12 補充]
6. 多張網卡ip設定
/etc/network/interface
# 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 192.168.20.146
netmask 255.255.255.0
network 192.168.20.0
broadcast 192.168.20.255
gateway 192.168.20.254

auto eth2
iface eth2 inet static
address 192.168.20.246
netmask 255.255.255.0
gateway 192.168.20.254


參考資料:
搞定 Ubuntu 底下的網路設定
測試網路介面 ifconfig
鳥哥
Linux 的網路連線設定

沒有留言: