Configuring NAT Using PF Firewall in Solaris 11 / 12 Zones

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Solaris 11/12 PF Firewall NAT Configuration

Below is an update on how to configure NAT in Solaris 11/12, the original post used IPfilter(IPF). Since Solaris now officially switched to the BSD firewall(PF) I created the updated example below.


The network used in the kernel zones are
The network used on the global zone is – this will be used as your external gateway(NAT).

  • Create a vNic and assign to each kernel zone.
  • Create a vNic for use on the global zone.
  • Set the default gateway to the global zone vnic.

An example is below:
Create vNics

global # dladm create-vnic kz1
global # dladm create-vnic kz2
global # dladm create-vnic gl1

vNic and zone configuration

zonecfg -z kz1 info
	configure-allowed-address: true
	physical: kz1
	id: 1
Zone IP address assignments
kz1 # ipadm create-addr -a net0
kz1 # route -p add default

NAME              CLASS/TYPE STATE        UNDER      ADDR
lo0               loopback   ok           --         --
   lo0/v4         static     ok           --
   lo0/v6         static     ok           --         ::1/128
net0              ip         ok           --         --
   net0/v4        static     ok           --
   net0/v6        addrconf   ok           --         fe80::8:20ff:feaa:b14f/10

netstat -rn

Routing Table: IPv4
  Destination           Gateway           Flags  Ref     Use     Interface 
-------------------- -------------------- ----- ----- ---------- --------- 
default                UG        2      16542               U         3         19 net0              UH        2       9716 lo0       

Routing Table: IPv6
  Destination/Mask            Gateway                   Flags Ref   Use    If   
--------------------------- --------------------------- ----- --- ------- ----- 
::1                         ::1                         UH      2      38 lo0   
fe80::/10                   fe80::8:20ff:feaa:b14f      U       2       0 net0 

Global zone vNic and IP address

global # ipadm create-addr -a gl1

Now we are ready for the PF configuration.
Below is how the /etc/firewall/pf.conf
Note: The pf.conf is a very simplified configuration just for the purpose of NAT.

ext_if = "localnet0"    # macro for external interface
int_if = "kz1"          # macro for internal interface, Note: this is not used in this example.

pass out on $ext_if from to any nat-to

Finally enable firewall with svcadm

svcadm enable svc:/network/firewall:default

Helpful tips
Check the PF active running rule set.
Tip: I have struggled with this for a while, as my rule-set had an syntax issue. I was using the old nat keyword which is now obsolete, causing my rule-set to break(and not being used), but by checking the service it will still show online, but it will be loading a default rule-set.
Note: Its always a good idea especially if things don't work properly to verify the active rule set.

To verify the active rule set, just run the below (make sure it is waht you expect it to be).

pfctl -s rules
pass out on localnet0 inet from to any flags S/SA nat-to

The below will show you the current active sessions (i.e. NAT being used).

pfctl -s state
all udp ( ->       MULTIPLE:SINGLE
all udp ( ->       MULTIPLE:SINGLE
all udp ( ->       MULTIPLE:SINGLE
all udp ( ->       MULTIPLE:SINGLE
all udp ( ->       MULTIPLE:SINGLE

Anther handy option is, to verify the new/modified rule set for syntax errors.

pfctl -vnf pf.conf

Official documentation

Leave a Reply

Notify of