Setting IP and default gateway without DHCP in Solaris

Posted on 2006-11-01
Last Modified: 2013-12-21

I have Solaris Sun OS 10 installed. I can set my default gateway and IP address dynamically by DHCP in my network (DHCP runs under windows).

But now I want to set a static IP, static gateway's IP and static sub domain and I want to have internet connection from the gateway I'll define.

I know something about defaultrouter and gateways file in /etc...

But I need step by step and a good example...

Please advice!

Thanks from now!
Question by:CSecurity
  • 2
LVL 48

Assisted Solution

Tintin earned 200 total points
ID: 17852989
To set your default gateway, do

echo "" >/etc/defaultrouter

where is your default route.

Make sure you have the correct IP address for your server in /etc/inet/hosts and /etc/inet/ipnodes

Then find out your interface name by doing

ifconfig -a

It will be something like bge0, ipge0, hme0 etc.

then put the hostname in /etc/hostname.<int>, eg:

echo "myhost" >/etc/hostname.bge0

then if you have a non-standard netmask, add it to /etc/netmasks.

If you use DNS, then add

nameserver <ip of your nameserver>

in /etc/resolv.conf

Accepted Solution

jhartzen earned 300 total points
ID: 17857275
Hi there Csecurity.

The answer by Tintin points you to the configuration files, but I would like to add a few things.  Firstly, just changing the config files will not set the IP address, gateway, netmask, etc, unless you also reboot or cycle through init s -> init 1 -> init 2.  Secondly, if you make a mistake while changing the network config, you can lose connectivity.  If you did not change the config files, you would be able to revert to the working config by rebooting.  Therefore I recommend first trying out the config using the config commands, and once it works, set it in the config files to make the changes permanent.

The files, as mentioned above, are:
/etc/inet/hosts (a link exists with the name /etc/hosts)
/etc/inet/netmasks (a link exsits with the name /etc/netmasks)
/etc/hostname.bge0 or /etc/hostname.ce0 or ... depending on your specific network card.

In my example below, I use the following:
IP address =
netmask =
default gateway =
Interface = bge0

If it is a new interface, first you must plumb the port, like this
> ifconfig bge0 plumb
(Note: this will fail if the port is currently plumbed)

Then set the network address
> ifconfig bge0 netmask broadcast +
(Note: More on the use of the "+" later)

If the interface is not yet up, eg if it was new, then bring it online:
> ifconfig bge0 up
(no harm in doing this on an already online interface.  You can temporarily offline an interface by using "down", which updates your dynamic routing tables, refreshes your ARP cache, etc.  Very handy hint, that last bit of info, by the way)

Now add a default gateway - This requires an "online" interface within the same subnet as the gateway address!
> route add default

Check your config: To show the interface IP address, netmask, etc, on all interfaces, use:
> ifconfig -a
(Note: carefully check that the first flag is the word "UP", missing flags means that the flags are not set)

Also check your routing:
>netstat -rn
(Note: Unless you have very specific requirements, there should be exactly one entry called "default")

Test your configuration.
ping the interface - proves that it is "up".
ping the default gateway - proves that you have a working link.
ping a machine on another subnet - proves that your default router is correctly set up.

Now that you have verified the setup, you can put all the settings into the config files.  Also remove the file /etc/dhcp.bge0 (depending on your interface type, the bge0 part could be something like eri1, qfe0, hme1, ce3, bge5, or many other types.)

Some hints:
Firstly: Later versions of solaris (since Solaris 9) allows you to automatically plumb all the interfaces present in the system, without having to guess what interfaces are present.  try
> ifconfig -a plumb
(ignore the errors for already plumbed interfaces) followed by
> ifconfig -a
this will list newly plumbed interfaces with as the address.

alternatively, discover network interfaces in the system with this command:
> grep network /etc/path_to_inst
(Note: With earlier versions of solaris, before solaris 8 in particular, your mileage will vary)

Second hint: Once you have the netmask set in the /etc/netmasks file, you can use a "+" so that the ifconfig command will fill in the netmask automatically based on the IP address you specify.  You can also almost certainly let the ifconfig command figure out the broadcast address by using a "+" in this field, to let the ifconfig command use the netmask and IP address together to work out the correct broadcast address.

Some hints on updating the config files:
for netmasks, add entries to the file using the network address followed by the netmask, both in dotted-decimal notation, eg:

The /etc/defaultrouter file must contain an IP address, not a hostname.

Having the wrong address for your host in /etc/hosts will cause X-windows to misbehave.  Make sure that the IP address/hostname pair refer to a live network interface!

DHCP might be providing you with DNS information.  You will lose this when you switch to using a static IP address.  Find your DNS server addresses, and do the following:
a) add a server line to /etc/resolv.conf for the DNS server(s)
b) make sure that the line in /etc/nsswitch.conf for "hosts" include the word "dns" at the end of the line.
c) reboot or send a HUP signal to the nscd process.

And always make backups of your config files before you modify them!

Expert Comment

ID: 17864712
One final thought from me:  It is good practice to release the DHCP lease prior to going to a fixed IP address, eg
> ifconfig bge0 release

This will inform the DHCP server that it can add that address back into its free pool.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question