Ubuntu 网络设置

查看当前网络设置:
ifconfig

eth0      Link encap:Ethernet  HWaddr 44:37:e8:56:a2:a6
          inet addr:192.168.3.108  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::4637:e6ff:fe56:a2a6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5790 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4979 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3169504 (3.1 MB)  TX bytes:707408 (707.4 KB)
          Interrupt:20 Memory:feac0000-feae0000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:6511 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6511 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3991386 (3.9 MB)  TX bytes:3991386 (3.9 MB)

1.open /etc/network/interfaces 。

sudo vi /etc/network/interfaces

设置静态IP

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
#设置为静态IP
iface eth0 inet static
#IP地址
address 192.168.1.6
#网关
gateway 192.168.1.1
#子网掩码
netmask 255.255.255.0
#网段
network 192.168.1.0
#组播地址
broadcast 192.168.1.255

Restart network

/etc/init.d/networking restart
Another way restart specified network device without affect others.
sudo ifdown eth0
sudo ifup eth0

#通过DHCP自动获得地址的配置方式

auto eth0
iface eth0 inet dhcp

or do it with command

sudo dhclient eth0

配置DNS服务器的地址,最多可以使用3个DNS服务器
sudo vi /etc/resolv.conf

nameserver 202.96.134.133
nameserver 202.96.128.68
nameserver 202.96.128.166

对”resolv.conf”的修改即时生效