首页  编辑  

Linux设定固定IP地址

Tags: /计算机文档/Linux & Unix/   Date Created:

设定固定 IP 地址

对 Ubuntu ,编辑 /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 eth 0

#iface eth 0 inet dhcp

iface eth 0 inet static

 address 172.16.0.46

 netmask 255.255.255.0

 gateway 172.16.0.254

 dns-nameservers 172.16.1.101 8.8.8.8 8.8.6.6

如果需要设定多个 IP 地址,可以增加一些行,类似下面:

auto eth0:1  

iface eth0:1 inet static  

address x.x.x.x  

netmask x.x.x.x  

network x.x.x.x  

broadcast x.x.x.x  

gateway x.x.x.x

修改完成后,重启网络服务刷新配置:

sudo /etc/init.d/networking restart

如果要从 DHCP 服务器获取 IP 地址,请运行:

sudo dhclient eth0

# 如果要删除 DHCP ,请运行:

sudo aptitude remove dhcp3-client dhcp3-common