Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7217
  • Last Modified:

Setting IP and default gateway without DHCP in Solaris

Hello!

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!
0
CSecurity
Asked:
CSecurity
  • 2
2 Solutions
 
TintinCommented:
To set your default gateway, do

echo "1.2.3.4" >/etc/defaultrouter

where 1.2.3.4 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
0
 
jhartzenCommented:
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.
/etc/defaultrouter

In my example below, I use the following:
IP address = 192.168.2.15
netmask = 255.255.255.0
default gateway = 192.168.2.1
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 192.168.2.15 netmask 255.255.255.0 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 192.168.2.1

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 0.0.0.0 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:
192.168.2.0   255.255.255.0

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!
0
 
jhartzenCommented:
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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