Ubuntu的网络参数保存在文件 /etc/network/interfaces中,默认设置使用dhcp,动态IP获取。
设置静态ip的方法如下:
1) 编辑 /etc/network/interfaces
1.1)将dhcp 一行屏蔽
# The primary network interface
auto eth0
#iface eth0 inet dhcp
auto eth0
#iface eth0 inet dhcp
1.2)添加和静态ip有关的参数
# The primary network interface
iface eth0 inet static
address 192.168.1,151
netmask 255.255.255.0
gateway 192.168.1.1
iface eth0 inet static
address 192.168.1,151
netmask 255.255.255.0
gateway 192.168.1.1
2)编辑 /etc/resolv.conf,设置dns,如果重启还原,则还需要修改/etc/resolvconf/resolv.conf.d/base文件,两个内容一样
nameserver 192.168.1.1 #路由网关
nameserver 8.8.8.8 #google的dns服务器
nameserver 8.8.8.8 #google的dns服务器
3)执行下面两个命令,启用新设置
$sudo ifdown eth0
$sudo ifup eth0
$sudo ifup eth0
本文介绍如何在Ubuntu系统中配置静态IP地址,包括编辑interfaces文件设置网络接口为静态IP,指定IP地址、子网掩码及默认网关,同时配置DNS服务器,并通过重启网络服务使配置生效。
1890

被折叠的 条评论
为什么被折叠?



