---
title: "Solaris更改IP"
author: "eblddong"
date: "2012-07-26T09:28:13Z"
tags: ["Solaris", "vi", "虚拟机"]
categories: ["操作系统"]
slug: "solaris-ip"
draft: false
lastmod: "2012-07-26T09:28:12Z"
id: 1602009
url: "https://eblddong.iteye.com/blog/1602009"
---

转自：[http://hexiaozi.itpub.net/post/35915/474302](http://hexiaozi.itpub.net/post/35915/474302)

一 、更改solaris IP 地址

ifconfig用来配置 网卡 的IP地址,改动后即生效,  
但并不保存,下次启动后失效.  
我们以虚拟机 来讲.网卡pcn0  
#ifconfig -a  
lo0:.......  
inet 127.0.0.1 netmask ff000000  
pcn0:......  
inet 192.168.229.3 netmask ffffff00 broadcast 192.168.229.225  
ether 0:c:29:ff:2e:1f  
#ipconfig pcn0 192.168.6.6 netmask 255.255.255.0  
#ifconfig -a  
lo0:......  
inet 127.0.0.1 netmask ff000000  
pcn0:......  
inet 192.168.6.6 netmask ffffff00 broadcast 192.168.229.225  
ether 0:c:29:ff:2e:1f  
想要永久更改配置,则要更改配置文件 ,以网卡pcn0为例:  
要改三个文件1./etc/hosts 2./etc/netmasks 3./etc/inet/ipnodes  
#more /etc/hostname.pcn0  
sun10  
(看自己PC的名字)  
#more /etc/hosts  
127.0.0.1 localhost  
192.168.229.3 sun10 loghost  
(看自己的IP地址)  
(用vi或gedit改在图形界面 下很容易)  
#vi /etc/hosts (192.168.229.3改成192.168.6.6就行了)  
#vi /etc/netmasks (把192.168.229.0改成192.168.6.0)  
#vi /etc/inet/ipnodes (192.168.229.3改成192.168.6.6就行了)

#reboot (over)

永久更改：  
1）编辑文件/etc/hosts，更改相应的ip和主机名（这个主机名与“ping 主机名”相对应，与hostname命令 看到的主机名是两回事，可以一样也可以不一样，下面有说明），如果更改了/etc/hosts文件中的主机名，相 应的也要更改/etc/hostname.hme0文件中的主机名，也就是说文件/etc/hosts与/etc/hostname.hme0中的主机名 应该一致；  
2）编辑文件/etc/netmasks,编辑相应ip的子网掩码；  
3）在命令行下执行如下命令，使新ip马上生效  
#ifconfig hme0 inet ip\_address netmask 子网掩码 up 

二 、更改主机名  
永久更改：  
编辑文件/etc/nodename，输入新的文件名即可，重起或在命令行下执行“ hostname 新的主机名”，即可看到新的主机名已经生效了；

三 、更改网关  
编辑或新建文件/etc/defaultrouter,输入网关ip地址即可，同时在命令行下输入“route add default gateway IP地址”，新的网关即可马上生效了；

四 、 增加一个虚拟ip（即在一个网卡上增加第二个ip）

1）假如系统 网卡名称是/etc/hostname.hme0,再增加一个文件，/etc/hostname.hme0:1,文件内容为test；  
2）在/etc/hosts文件中增加一行纪录，“192.168.100.1 test”,假设新的ip为192.168.10.1 主机名为test；  
3）在/etc/netsmasks文件中增加一行纪录 “192.168.100.0 255.255.255.0”；  
4)重起即可生效了；

五、DNS设置

1.修改/etc/resolv.conf  
#vi /etc/resolv.conf  
加入一条  
nameserver 202.96.209.133 (上海DNS地址，你可以根据本地的ISP地址自己设置)  
2.修改/etc/nsswitch.conf,如没有，用cp nsswitch.dns nsswitch.conf  
将host: files 那行改成  
host: files dns  
也就是加一个dns  
3.修改/etc/defaultrouter  
defaultrouter 192.168.0.1 (你的网关地址，也就是TCP/IP下的default gateway)  
修改完后重新启动  
init 5