ubuntu在机房上网

19 June 2009

最近资金紧张,没钱交网费,只好到机房上网了,不过又怀念自己的linux,因此在机房的机器上装了个Ubuntu。下面简要记录下如何配置上网。

Ubuntu默认安装的是DHCP
# The primary network interface
auto eth0
iface eth0 inet dhcp
 
先要取消DHCP
编辑/etc/network/interfaces
$sudo vim /etc/network/interfaces
# The primary network interface
auto eth0
#iface eth0 inet dhcp
 
设置IP地址和网关地址
# The primary network interface
iface eth0 inet static
address 192.168.4.148
netmask 255.255.255.0
gateway 192.168.4.254

设置DNS服务器地址,编辑文件/etc/resolv.conf
$sudo vim /etc/resolv.conf
nameserver 202.118.224.101
nameserver 202.106.0.20
 
重启eth0
$sudo ifdown eth0
$sudo ifup eth0

机房有时会限制MAC地址,修改MAC地址命令如下
$sudo ifconfig eth0 up
$sudo ifconfig eth0 hw ether 00:10:5C:E1:63:E1
$sudo ifconfig eth0 down

不过每次重启后都会失效
 自己写了一个脚本

#!/bin/sh
echo " **************************************************************"
echo " *                  Configure IP                              *"
echo " * Copyright by Jiang Bo <jiang_eis@hotmail.com> 2009.6.10    *"
echo " **************************************************************"

echo " shut down eth0..."
ifconfig eth0 down

echo " configure MAC..."
ifconfig eth0 hw ether 00:10:5C:E1:63:E1

echo " configure ip address..."
ifconfig eth0 192.168.4.148 netmask 255.255.255.0

echo " configure gateway address..."
route add default gw 192.168.4.254

echo " set up eth0..."
ifconfig eth0 up

 

每次重启后直接执行这个脚本就行了^^



blog comments powered by Disqus