Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7227
  • Last Modified:

Setting IP and default gateway without DHCP in Solaris


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!
  • 2
2 Solutions
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
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!
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now