Cheatsheet for configuring the networking in Solaris 11

There are quite a number of changes in the procedures to configure some of the networking parameters. Many things have changed, that were just editing of a file in the past, have now command-line based tools in order to change their parameters. Before you ask: The reason for this steps are quite simple. At first ist much easier to script the execution of a command, instead of the editing a file. I wrote a lot of those scripts in the past and from my experiences people have an infinite wisdom in creating ways and means to edit a file in a way that it breaks your automatic edting scripts. Furthermore putting all this configuration statements into SMF has an interesting consequence. In the past, it wasn’t always clear to most people when a change of the configuration got active. At the time of the save, at the restart of the daemon? By using SMF it’s clear. As soon as you type in svcadm refresh. Furthermore ifconfig came totally overloaded with parameters with the time. So dladm and ipadm were a very good move from my perspective. However i know that this is maybe a strange for an long-time user, and to be honest, i was spelling many curses in front of the display, albeit i see the advantages. So i’m putting up my cheatsheet online. My colleague Detlef is planing something similar. As soon his is ready, i will linking to his as well, as i’m sure it’s more complete.

With automatisms

In the datacenter it’s not that useful, however when you have an Solaris VM for example on your notebook you are using for administrative purposes, it’s really nice. At first we create the network configuration profiles for the datacenter and the office.

root@tachikoma:/home/jmoekamp# netcfg create ncp datacenter
root@tachikoma:/home/jmoekamp# netcfg create ncp office

Now we have to fill both with the configuration data. At first the one for the datacenter. I think the values are speaking for themself.

root@tachikoma:/home/jmoekamp# netcfg
netcfg> select ncp datacenter
netcfg:ncp:datacenter> create ncu phys net0
Created ncu 'net0'.  Walking properties ...
activation-mode (manual) [manual|prioritized]> manual
link-mac-addr>
link-autopush>
link-mtu>
netcfg:ncp:datacenter:ncu:net0> end
Committed changes
netcfg:ncp:datacenter> create ncu ip net0
Created ncu 'net0'.  Walking properties ...
ip-version (ipv4,ipv6) [ipv4|ipv6]> ipv4
ipv4-addrsrc (dhcp) [dhcp|static]> static
ipv4-addr> 192.168.1.27
ipv4-default-route> 192.168.1.1
netcfg:ncp:datacenter:ncu:net0> end
Committed changes
netcfg:ncp:datacenter> exit
root@tachikoma:/home/jmoekamp#

Now we do the same for the office:

root@tachikoma:/home/jmoekamp# netcfg
netcfg> select ncp office
netcfg:ncp:office> create ncu phys net0
Created ncu 'net0'.  Walking properties ...
activation-mode (manual) [manual|prioritized]> manual
link-mac-addr>
link-autopush>
link-mtu>
netcfg:ncp:office:ncu:net0> end
Committed changes
netcfg:ncp:office> create ncu ip net0
Created ncu 'net0'.  Walking properties ...
ip-version (ipv4,ipv6) [ipv4|ipv6]> ipv4
ipv4-addrsrc (dhcp) [dhcp|static]> dhcp
ipv4-default-route>
netcfg:ncp:office:ncu:net0> end
Committed changes
netcfg:ncp:office> exit

Now we can just switch the networking configuration by enabling one of the both profiles:

root@tachikoma:/home/jmoekamp# netadm enable -p ncp datacenter
Enabling ncp 'datacenter'
root@tachikoma:/home/jmoekamp# ifconfig net0
net0: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 6
        inet 192.168.1.27 netmask ffffff00 broadcast 192.168.1.255
        ether 8:0:27:b6:1:70

Let’s switch to the office profile:

root@tachikoma:/home/jmoekamp# netadm enable -p ncp office
Enabling ncp 'office'
root@tachikoma:/home/jmoekamp# ifconfig net0
net0: flags=201004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4,CoS> mtu 1500 index 7
        inet 192.168.1.185 netmask ffffff00 broadcast 192.168.1.255
        ether 8:0:27:b6:1:70

Of course the networking configuration is not just the interface configuration but a lot other stuff as well, link the configuration of the DNS. That options are in the location profiles. However i don’t want to activate the profile as well as the location both manually. Thus i configure an automatic activation of such configuration. In my example the datacenter profile configures an IP address of 192.168.1.27, the office profile uses DHCP which results in an IP-address out of the 192.168.1.100-199 range. Thus i’m using this for my automatic location switching. I can configure an activation mode and by choosing conditional-any this location profile will be activated automatically when any of the configured conditions are true. It’s pretty simple in my case: If the IP address is 192.168.1.27, i’m in the datacenter, if not i’m in the office. So, i’m configuring the location profile for the datacenter first. I think this is speaking for itself again, when you take the information into consideration, i gave you in the last paragraph:

root@tachikoma:/home/jmoekamp# netcfg
netcfg> create loc datacenter
Created loc 'datacenter'.  Walking properties ...
activation-mode (manual) [manual|conditional-any|conditional-all]> conditional-any
conditions> ip-address is 192.168.1.27
nameservices (dns) [dns|files|nis|ldap]> dns
nameservices-config-file ("/etc/nsswitch.dns")>
dns-nameservice-configsrc (dhcp) [manual|dhcp]> manual
dns-nameservice-domain> datacenter.c0t0d0s0.org
dns-nameservice-servers> 192.168.1.1
dns-nameservice-search>
dns-nameservice-sortlist>
dns-nameservice-options>
nfsv4-domain>
ipfilter-config-file>
ipfilter-v6-config-file>
ipnat-config-file>
ippool-config-file>
ike-config-file>
ipsecpolicy-config-file>
netcfg:loc:datacenter>
netcfg:loc:datacenter> exit
Committed changes

Now i will configure the one for the office:

root@tachikoma:/home/jmoekamp# netcfg
netcfg> create loc office
Created loc 'office'.  Walking properties ...
activation-mode (manual) [manual|conditional-any|conditional-all]> conditional-any
conditions> ip-address is-not 192.168.1.28
nameservices (dns) [dns|files|nis|ldap]> dns
nameservices-config-file ("/etc/nsswitch.dns")>
dns-nameservice-configsrc (dhcp) [manual|dhcp]> manual
dns-nameservice-domain> office.c0t0d0s0.org
dns-nameservice-servers> 192.168.1.1
dns-nameservice-search>
dns-nameservice-sortlist>
dns-nameservice-options>
nfsv4-domain>
ipfilter-config-file>
ipfilter-v6-config-file>
ipnat-config-file>
ippool-config-file>
ike-config-file>
ipsecpolicy-config-file>
netcfg:loc:office>
netcfg:loc:office> exit
Committed changes
root@tachikoma:/home/jmoekamp# netcfg

Okay, let’s try this out. At first we activate the datacenter network configuration profile.

root@tachikoma:/home/jmoekamp# netadm enable -p ncp datacenter
Enabling ncp 'datacenter'

In theory, the resolv.conf should now change to nameserver 192.168.1.1. Let’s check this.

root@tachikoma:/home/jmoekamp# cat /etc/resolv.conf

#
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
#

#
# _AUTOGENERATED_FROM_SMF_V1_
#
# WARNING: THIS FILE GENERATED FROM SMF DATA.
#   DO NOT EDIT THIS FILE.  EDITS WILL BE LOST.
# See resolv.conf(4) for details.

domain  datacenter.c0t0d0s0.org
nameserver      192.168.1.1

Okay, that was successful. Now we will switch to the network configuration profile office.

root@tachikoma:/home/jmoekamp# netadm enable -p ncp office
Enabling ncp 'office'

We have a look into the resolv.conf again. The nameserver should have switched to 192.168.1.43:

root@tachikoma:/home/jmoekamp# cat /etc/resolv.conf

#
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
#

#
# _AUTOGENERATED_FROM_SMF_V1_
#
# WARNING: THIS FILE GENERATED FROM SMF DATA.
#   DO NOT EDIT THIS FILE.  EDITS WILL BE LOST.
# See resolv.conf(4) for details.

domain  office.c0t0d0s0.org
nameserver      192.168.1.43

Nice.

Without that automatic stuff ....

Configuring all this stuff manually isn’t hard as well. Perhaps you have chosen “Automatic” initially at install time in the CUI. So at first we have to get rid of the automatisms.

root@tachikoma:/home/jmoekamp# netadm enable -p ncp defaultfixed
Enabling ncp 'DefaultFixed'

Okay, now we configure an ip interface called net0 and assign an ip address

root@tachikoma:/home/jmoekamp# dladm show-phys
LINK              MEDIA                STATE      SPEED  DUPLEX    DEVICE
net0              Ethernet             unknown    0      unknown   pcn0
root@tachikoma:/home/jmoekamp# ipadm create-ip net0
root@tachikoma:/home/jmoekamp# ipadm create-addr -T static -a  192.168.1.28/24
net0/v4

Of course we need a defaultrouter. With this command we configure such a persistent default route.

root@tachikoma:/home/jmoekamp# route -p add default 192.168.1.1
add net default: gateway 192.168.1.1
add persistent net default: gateway 192.168.1.1

Configuring the dns server is a little bit more complex:

root@tachikoma:/home/jmoekamp# svccfg  -s "dns/client" setprop "config/nameserver = net_address: ( 192.168.1.1 )"
root@tachikoma:/home/jmoekamp# svccfg  -s "dns/client" setprop 'config/domain = astring: ("c0t0d0s0.org")'
root@tachikoma:/home/jmoekamp# svccfg -s "name-service/switch" setprop 'config/host = astring: "files dns"'
root@tachikoma:/home/jmoekamp# svcadm refresh name-service/switch
root@tachikoma:/home/jmoekamp# svcadm enable dns/client

Okay, let’s check the result:

root@tachikoma:/home/jmoekamp# grep "192.168.1.43" /etc/resolv.conf
nameserver      192.168.1.43
root@tachikoma:/home/jmoekamp# grep "host" /etc/nsswitch.conf
hosts:  files dns

Everything works as designed.