您的位置:首页 > 其它

Ubuntu中静态IP配置方法

2015-11-25 11:37 253 查看
将Ubuntu设置为静态IP。方法如下:
1、修改网络配置文件
网络配置信息存储在/etc/network/interfaces 文件中
sudo vi /etc/network/interfaces
我用vi打开,我的文件显示如下内容:
# 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
我的网络配置文件中只有一个环回地址,即127.0.0.1。在下面添加:
auto eth0 #指明网卡eth0在系统启动时自动加载
iface eth0 inet static #指明eth0采用ipv4地址,inet表示ipv4地址,inet6表示ipv6地址; static表示静态,dhcp表示动态
address 172.22.112.13 #静态ip
netmask 255.255.255.128 #子网掩码
gateway 172.22.112.1 #网关地址
:wq #保存退出


2、设置DNS服务器
在静态ip下还要配置DNS服务器(Windows也是这么做的),DNS信息存储在/etc/resolv.conf 中,如果没有此文件则直接新建:
sudo vi /etc/resolv.conf #用vi打开文件
进入编辑模式,输入a,然后依次输入下面内容:
nameserver 202.202.32.33 #首选DNS服务器
nameserver 61.128.128.68 #备用DNS服务器
:wq #保存退出
3、全部修改后,需要将网卡重启,让修改生效,方法如下,输入以下命令:
sudo ifdown eth0 #禁用网卡
sudo ifup eth0 #启动网卡

sudo /etc/init.d/networking restart 代替 sudo service network restart

直接用命令行配置Ip: ifconfig eth0 10.108.98.93 netmask 255.255.252.0
设置网关:route add default gw 10.108.99.1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: